-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Describe the bug
I tried to write a simple test for my module and get unexpected error
/soldr-modules/utils/mock/core.lua:864: /soldr-modules/utils/engine/event.lua:488: attempt to call field 'fields_schema_validator' (a nil value)
After a little research, I realized that __mock.module_config hasn't enough data. I found the row with initializing and containing __mock.module_info https://github.com/vxcontrol/soldr-modules/blob/master/utils/mock/core.lua#L693 and was unhappy surprised there are no fields: fields
, actions
, events
. As I understand __mock.module_info should contains data from file <module_name>/<version>/config/info.json
.
I crookedly fixed it in my module, but it will be better if __mock.module_info contains real data from <module_name>/<version>/config/info.json
.
Steps to Reproduce
-
prepare environment by Wiki: https://github.com/vxcontrol/soldr-modules/wiki/Unit-testing
-
cd soldr-modules
-
git fetch origin osquery_linux (if not merged)
-
Import test code:
cat << EOF > ./tests/osquery_linux_client_spec.lua
require 'busted.runner'()
describe('osquery_linux agent', function()
setup(function()
_G.__mock = {
vars = {},
timeout = 2, -- in seconds
cwd = "tmpcwd",
module = "osquery_linux",
version = "1.0.0",
side = "agent",
log_level = os.getenv("LOG_LEVEL") or "debug", -- error, warn, info, debug, trace
}
require("mock")
__mock:module_start()
end)
teardown(function()
-- stop module actually wait for module coroutine to finish execution
__mock:module_stop()
end)
before_each(function()
__mock:clear_expectations()
end)
end)
EOF
- Run test:
./tests_framework/lua/bin/busted.osx64.cmd tests/osquery_linux_client_spec.lua
Expected behavior:
1 success / 0 failures / 0 errors / 0 pending : 0.288752 seconds
Actual behavior:
0 successes / 0 failures / 1 error / 0 pending : 0.213859 seconds
Error → tests/osquery_linux_client_spec.lua @ 4
osquery_linux agent setup
/Users/roman/other/cok/soldr-modules/utils/mock/core.lua:864: /Users/roman/other/cok/soldr-modules/utils/engine/event.lua:493: attempt to call field 'fields_schema_validator' (a nil value)
Screenshots, screen recording, code snippet
No response
Environment information
➜ uname -a
Darwin MacBook-Pro.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64
Which agent binary used?
- darwin-amd64
- linux-386
- linux-amd64
- windows-386
- windows-amd64