Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: __mock.module_info hasn't enough data #42

Open
5 tasks
0legovich opened this issue Jan 10, 2023 · 0 comments
Open
5 tasks

[Bug]: __mock.module_info hasn't enough data #42

0legovich opened this issue Jan 10, 2023 · 0 comments
Assignees
Labels
bug Something isn't working tests Test framework or running tests

Comments

@0legovich
Copy link
Contributor

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

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
@0legovich 0legovich added the bug Something isn't working label Jan 10, 2023
@0legovich 0legovich added the tests Test framework or running tests label Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tests Test framework or running tests
Projects
None yet
Development

No branches or pull requests

2 participants