-- replay_test.lua -- Runs unit tests against the severity filtering code from severity.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 replay = require("replay") local test_string_fill = "_test-pod-name_test-container-name_" local fake_timestamp = "dummy_timestamp" local replay_test_cases = { { description = "log_replay class added", record = { ["kubernetes"] = { ["container_name"] = "lumperctl", ["namespace_name"] = "warehouse-system" }, ["replay_severity"] = "info", }, tag = "k8s_container.warehouse-system" .. test_string_fill, assert_func = function(t,number, timestamp, record) t.equal(number, 2) t.equal(timestamp, fake_timestamp) t.equal(record["log_class"], "replay") end }, { description = "message changed to original log", record = { ["kubernetes"] = { ["container_name"] = "lumperctl", ["namespace_name"] = "warehouse-system" }, ["original-log"] = "test-log", ["replay_severity"] = "info", }, tag = "k8s_container.warehouse-system" .. test_string_fill, assert_func = function(t,number, timestamp, record) t.equal(number, 2) t.equal(timestamp, fake_timestamp) t.equal(record["original-log"], nil) t.equal(record["message"], "test-log") end }, { description = "replay severity unchanged", record = { ["kubernetes"] = { ["container_name"] = "lumperctl", ["namespace_name"] = "warehouse-system" }, ["original-log"] = "test-log", ["replay_severity"] = "info", }, tag = "k8s_container.warehouse-system" .. test_string_fill, assert_func = function(t,number, timestamp, record) t.equal(number, 2) t.equal(timestamp, fake_timestamp) t.equal(record["replay_severity"], "info") end }, { description = "replay severity not passed setting to default", record = { ["kubernetes"] = { ["container_name"] = "lumperctl", ["namespace_name"] = "warehouse-system" }, ["original-log"] = "test-log", }, tag = "k8s_container.warehouse-system" .. test_string_fill, assert_func = function(t,number, timestamp, record) t.equal(number, 2) t.equal(timestamp, fake_timestamp) t.equal(record["replay_severity"], "info") end }, { description = "original time kept", record = { ["kubernetes"] = { ["container_name"] = "lumperctl", ["namespace_name"] = "warehouse-system" }, ["original-log"] = "test-log", ["original-time"] = "new-time", ["replay_severity"] = "info", }, tag = "k8s_container.warehouse-system" .. test_string_fill, assert_func = function(t,number, timestamp, record) t.equal(number, 1) t.equal(timestamp, "new-time") t.equal(record["replay_severity"], "info") end }, } print("-------------------------") print("replay_test_cases started") print("-------------------------") for _, case in ipairs(replay_test_cases) do test(case.description, function(t) local number, timestamp, record= replay.process_logs(case.tag, fake_timestamp ,case.record) case.assert_func(t, number, timestamp, record) end) end