...

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

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

     1-- replay_test.lua
     2-- Runs unit tests against the severity filtering code from severity.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 replay = require("replay")
    16
    17local test_string_fill = "_test-pod-name_test-container-name_"
    18local fake_timestamp = "dummy_timestamp"
    19
    20local replay_test_cases = {
    21    {
    22        description = "log_replay class added",
    23        record = {
    24            ["kubernetes"] = {
    25                ["container_name"] = "lumperctl",
    26                ["namespace_name"] = "warehouse-system"
    27            },
    28            ["replay_severity"] = "info",
    29        },
    30        tag = "k8s_container.warehouse-system" .. test_string_fill,
    31        assert_func = 
    32            function(t,number, timestamp, record) 
    33                t.equal(number, 2)
    34                t.equal(timestamp, fake_timestamp)
    35                t.equal(record["log_class"], "replay") 
    36            end
    37    },
    38    {
    39        description = "message changed to original log",
    40        record = {
    41            ["kubernetes"] = {
    42                ["container_name"] = "lumperctl",
    43                ["namespace_name"] = "warehouse-system"
    44            },
    45            ["original-log"] = "test-log",
    46            ["replay_severity"] = "info",
    47        },
    48        tag = "k8s_container.warehouse-system" .. test_string_fill,
    49        assert_func = 
    50            function(t,number, timestamp, record) 
    51                t.equal(number, 2)
    52                t.equal(timestamp, fake_timestamp)
    53                t.equal(record["original-log"], nil) 
    54                t.equal(record["message"], "test-log") 
    55            end
    56    },
    57    {
    58        description = "replay severity unchanged",
    59        record = {
    60            ["kubernetes"] = {
    61                ["container_name"] = "lumperctl",
    62                ["namespace_name"] = "warehouse-system"
    63            },
    64            ["original-log"] = "test-log",
    65            ["replay_severity"] = "info",
    66        },
    67        tag = "k8s_container.warehouse-system" .. test_string_fill,
    68        assert_func = 
    69            function(t,number, timestamp, record) 
    70                t.equal(number, 2)
    71                t.equal(timestamp, fake_timestamp)
    72                t.equal(record["replay_severity"], "info") 
    73            end
    74    },
    75    {
    76        description = "replay severity not passed setting to default",
    77        record = {
    78            ["kubernetes"] = {
    79                ["container_name"] = "lumperctl",
    80                ["namespace_name"] = "warehouse-system"
    81            },
    82            ["original-log"] = "test-log",
    83        },
    84        tag = "k8s_container.warehouse-system" .. test_string_fill,
    85        assert_func = 
    86            function(t,number, timestamp, record) 
    87                t.equal(number, 2)
    88                t.equal(timestamp, fake_timestamp)
    89                t.equal(record["replay_severity"], "info") 
    90            end
    91    },
    92    {
    93        description = "original time kept",
    94        record = {
    95            ["kubernetes"] = {
    96                ["container_name"] = "lumperctl",
    97                ["namespace_name"] = "warehouse-system"
    98            },
    99            ["original-log"] = "test-log",
   100            ["original-time"] = "new-time",
   101            ["replay_severity"] = "info",
   102        },
   103        tag = "k8s_container.warehouse-system" .. test_string_fill,
   104        assert_func = 
   105            function(t,number, timestamp, record) 
   106                t.equal(number, 1)
   107                t.equal(timestamp, "new-time")
   108                t.equal(record["replay_severity"], "info") 
   109            end
   110    },
   111}
   112
   113print("-------------------------")
   114print("replay_test_cases started")
   115print("-------------------------")
   116for _, case in ipairs(replay_test_cases) do
   117    test(case.description, function(t)
   118        local number, timestamp, record= replay.process_logs(case.tag, fake_timestamp ,case.record)
   119        case.assert_func(t, number, timestamp, record)
   120    end)
   121end

View as plain text