...

Text file src/edge-infra.dev/pkg/edge/logging/fluentbit/systemd_test.lua

Documentation: edge-infra.dev/pkg/edge/logging/fluentbit

     1-- systemd_test.lua
     2-- Runs unit tests against the systemd filtering code from systemd.lua
     3-- requires 2 arguments 
     4--   1. a path to the test library:    e.g.: /Users/ur1337/edge-infra/third_party/lua/simple_test/src
     5--   2. a path to the test target dir: e.g.: /Users/ur1337/edge-infra/pkg/edge/logging/fluentbit
     6
     7local test_library = arg[1] .. "/?.lua"
     8local target_dir = arg[2] .. "/?.lua"
     9local test_data = arg[2] .. "/testdata"
    10
    11-- the test library and target directory need to be added to package.path so we can 'require' them
    12package.path = package.path .. ";" .. test_library .. ";" .. target_dir .. ";" .. test_data
    13
    14local test = require("simple_test.init")
    15local systemd = require("systemd")
    16
    17
    18local recordTest = {
    19    ["message"] = {
    20        ["message"] = "first message",
    21    },
    22    ["PRIORITY"] = "6",
    23}
    24
    25local recordTest2 = {
    26    ["message"] = {
    27        ["message"] = "second message",
    28    },
    29}
    30
    31local systemd_test_cases = {
    32    {
    33        description = "systemd should return info",
    34        tag = nil,
    35        timestamp = "2023-09-22T18:03:22.695739473Z",
    36        record = recordTest,
    37        assert_sev = function(t,result) t.equal(result, "INFO") end,
    38        assert_tag = function(t,result) t.equal(result, 2) end
    39    },
    40    {
    41        description = "systemd should return default",
    42        tag = nil,
    43        timestamp = "2023-09-22T18:03:22.695739473Z",
    44        record = recordTest2,
    45        assert_sev = function(t,result) t.equal(result, "DEFAULT") end,
    46        assert_tag = function(t,result) t.equal(result, 2) end
    47    }
    48}
    49print("--------------------------")
    50print("systemd_test_cases started")
    51print("--------------------------")
    52for _, test_case in ipairs(systemd_test_cases) do
    53    test(test_case.description, function(t)
    54        local returnCode, timeResult, recordResult = systemd.format_log_level(test_case.tag, test_case.timestamp,test_case.record)
    55        local severity = recordResult["severity"]
    56        test_case.assert_sev(t, severity)
    57        test_case.assert_tag(t, returnCode)
    58    end)
    59end

View as plain text