-- systemd_test.lua -- Runs unit tests against the systemd filtering code from systemd.lua -- requires 2 arguments -- 1. a path to the test library: e.g.: /Users/ur1337/edge-infra/third_party/lua/simple_test/src -- 2. a path to the test target dir: e.g.: /Users/ur1337/edge-infra/pkg/edge/logging/fluentbit local test_library = arg[1] .. "/?.lua" local target_dir = arg[2] .. "/?.lua" local test_data = arg[2] .. "/testdata" -- the test library and target directory need to be added to package.path so we can 'require' them package.path = package.path .. ";" .. test_library .. ";" .. target_dir .. ";" .. test_data local test = require("simple_test.init") local systemd = require("systemd") local recordTest = { ["message"] = { ["message"] = "first message", }, ["PRIORITY"] = "6", } local recordTest2 = { ["message"] = { ["message"] = "second message", }, } local systemd_test_cases = { { description = "systemd should return info", tag = nil, timestamp = "2023-09-22T18:03:22.695739473Z", record = recordTest, assert_sev = function(t,result) t.equal(result, "INFO") end, assert_tag = function(t,result) t.equal(result, 2) end }, { description = "systemd should return default", tag = nil, timestamp = "2023-09-22T18:03:22.695739473Z", record = recordTest2, assert_sev = function(t,result) t.equal(result, "DEFAULT") end, assert_tag = function(t,result) t.equal(result, 2) end } } print("--------------------------") print("systemd_test_cases started") print("--------------------------") for _, test_case in ipairs(systemd_test_cases) do test(test_case.description, function(t) local returnCode, timeResult, recordResult = systemd.format_log_level(test_case.tag, test_case.timestamp,test_case.record) local severity = recordResult["severity"] test_case.assert_sev(t, severity) test_case.assert_tag(t, returnCode) end) end