This is a helper to do unit testing of Heka lua sandboxes: encoders and decoders.
It is in alpha stage: some features may be missing or working incorrectly.
Contributions are welcome. See Contributing for details.
Install heka_mock, busted (or other Lua test suite) and other Lua modules you need:
luarocks install heka_mock busted lua-cjson lpeg
Create spec/
subdir in the dir with your lua modules:
---+--- spec/ --- my_encoder_spec.lua
---- my_encoder.lua
Example of specs can be found at https://github.com/timurb/heka_mock/tree/master/test/spec. For detailed APIs see API section below.
Run tests:
$ busted
●
1 success / 0 failures / 0 errors / 0 pending : 0.004586 seconds
luarocks install heka_mock busted lua-cjson lpeg
git clone git@github.com:timurb/heka_mock.git
cd heka_mock/test
busted
Expected output:
$ busted
●●●●●●●●●●●●●●●●●●●●●●●●
24 successes / 0 failures / 0 errors / 0 pending : 0.017647 seconds
Dependencies of lua-cjson
and lpeg
are required only for running tests for heka_mock, you may not need this in your setup.
(See also Heka docs for real behaviour of the functions in heka)
Add val to payload.
Inject payload to injection list and clear current payload.
Converts msg
to string and injects payload.
Processes message returned by read_message("raw")
to table.
NOTE: This only works in this scenario and does not works with protobuf structures and other native Heka formats.
(NOT IMPLEMENTED IN HEKA UPSTREAM)
Returns a table with all injected messages since last reset_payload()
.
(NOT IMPLEMENTED IN HEKA UPSTREAM)
Reset payload and injection list. Run it before every test.
Produces error. These function provided by Heka are not implemented as I don't quite understand what is their use case in lua code. Probably you should use Heka-provided test suite to test again these.
Not implemented. I didn't have any use case for this so didn't create this one. May be one day I fix this or merge your pull request for this.
Set values for read_message()
called by encoder.
As in upstream read_message("raw")
should return table with original unprocessed message for further handling with decode_message()
.
Note: no checking is done for non-standard Heka fields -- no errors are produced and they are not dropped while Heka will do either of these
Note: array values (read_message("Fields[foo]", 1, 2)
-- 2+ params) are not supported as they are not widely used. Probably they'll be supported in a later release of this library.
Set values for read_config()
called by encoder.
If no paramater passed only the default config params will be set (see default_config()
).
If you need to set some config values shared by all tests define them here.
Note: you still need to run mock_read_config()
to set them.
- Fork repository
- Do the fix
- Write the tests
- Create pull request
Copyright 2015-2016, Timur Batyrshin. License: MIT. See LICENSE for details.