[check-log] tweak test case
@@ -900,22 +900,40 @@ func TestRunMultipleExcludePattern(t *testing.T) {
bytes, _ := getBytesToSkip(stateFile)
assert.Equal(t, int64(0), bytes, "stateFile size should be 0 (actual: %d)", bytes)
- runPlugin := func(logmsg string, status checkers.Status, matchedCount int) {
- fh.WriteString(logmsg)
+ tests := []struct {
+ logmsg string
+ want checkers.Status
+ matchedCount int64
+ }{
+ {
+ logmsg: "[TESTAPP] DEBUG: THIS LINE UNMATCHED\n",
+ want: checkers.OK,
+ matchedCount: 0,
+ },
+ {
+ logmsg: "[TESTAPP] ERROR: THIS LINE MATCHED\n",
+ want: checkers.CRITICAL,
+ matchedCount: 1,
+ },
+ {
+ logmsg: "[TESTAPP] ERROR: THIS LINE EXCLUDED(FOO BAR)\n[TESTAPP] ERROR: THIS LINE MATCHED(FOO)\n",
+ want: checkers.CRITICAL,
+ matchedCount: 1,
+ },
+ {
+ logmsg: "[TESTAPP] ERROR: THIS LINE EXCLUDED(FOO BAR)\nERROR: THIS LINE UNMATCHED\n",
+ want: checkers.OK,
+ matchedCount: 0,
+ },
+ }
+
+ for _, test := range tests {
+ fh.WriteString(test.logmsg)
ckr := run(context.Background(), params)
- assert.Equal(t, status, ckr.Status, fmt.Sprintf("ckr.Status should be %s", status.String()))
+ assert.Equal(t, test.want, ckr.Status, fmt.Sprintf("ckr.Status should be %s", test.want.String()))
- msg := fmt.Sprintf("%d warnings, %d criticals for pattern /ERROR/ and /TESTAPP/.", matchedCount, matchedCount)
+ msg := fmt.Sprintf("%d warnings, %d criticals for pattern /ERROR/ and /TESTAPP/.", test.matchedCount, test.matchedCount)
assert.Equal(t, msg, ckr.Message, fmt.Sprintf("chk.Message should be '%s' (actual: '%s')", msg, ckr.Message))
}
-
- lo1 := "[TESTAPP] DEBUG: THIS LINE UNMATCHED\n"
- lo2 := "[TESTAPP] ERROR: THIS LINE MATCHED\n"
- lo3 := "[TESTAPP] ERROR: THIS LINE EXCLUDED(FOO BAR)\n[TESTAPP] ERROR: THIS LINE MATCHED(FOO)\n"
- lo4 := "[TESTAPP] ERROR: THIS LINE EXCLUDED(FOO BAR)\nERROR: THIS LINE UNMATCHED\n"
- runPlugin(lo1, checkers.OK, 0)
- runPlugin(lo2, checkers.CRITICAL, 1)
- runPlugin(lo3, checkers.CRITICAL, 1)
- runPlugin(lo4, checkers.OK, 0)
}
