MCPcopy
hub / github.com/kubernetes/node-problem-detector / TestMatch

Function TestMatch

pkg/systemlogmonitor/log_buffer_test.go:64–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

62}
63
64func TestMatch(t *testing.T) {
65 max := 4
66 for c, test := range []struct {
67 logs []string
68 exprs []string
69 expected [][]string
70 }{
71 {
72 // Buffer not full
73 logs: []string{"a1", "b2"},
74 exprs: []string{
75 "a1", // Not including the last line, should not match
76 "b1", // Not match
77 "b2", // match
78 `\w{2}`, // Regexp should work
79 "a1\nb2", // Including the last line, should match
80 `a1b2`, // No new line, should not match
81 },
82 expected: [][]string{{}, {}, {"b2"}, {"b2"}, {"a1", "b2"}, {}},
83 },
84 {
85 // Buffer full
86 logs: []string{"a1", "b2", "c3", "d4", "e5"},
87 exprs: []string{
88 "(?s)a1.+", // Rotate out, should not match
89 `[a-z]\d\n[a-z]\d`, // New line should work, and only the one contains the last line should match
90 `[a-z]\d`, // Multiple match, only the one contains the last line should match
91 },
92 expected: [][]string{{}, {"d4", "e5"}, {"e5"}},
93 },
94 } {
95 b := NewLogBuffer(max)
96 for _, log := range test.logs {
97 b.Push(&types.Log{Message: log})
98 }
99 for i, expr := range test.exprs {
100 logs := b.Match(expr)
101 got := []string{}
102 for _, log := range logs {
103 got = append(got, log.Message)
104 }
105 if !reflect.DeepEqual(test.expected[i], got) {
106 t.Errorf("case %d.%d: expected %v, got %v", c+1, i+1, test.expected[i], got)
107 }
108 }
109 }
110}

Callers

nothing calls this directly

Calls 3

PushMethod · 0.95
MatchMethod · 0.95
NewLogBufferFunction · 0.85

Tested by

no test coverage detected