-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmocks_test.go
52 lines (41 loc) · 1.38 KB
/
mocks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gokaf
import (
"testing"
)
func TestGetMockLogs(t *testing.T) {
// Clear the buffer before running the test
mockLoggerBuff.Reset()
// Log some messages using the mock logger
mockLogger.Warn("Message 1")
mockLogger.Warn("Message 2")
mockLogger.Warn("Message 3")
// Get the logs using the getMockLogs function
logs := getMockLogs()
// Define expected log messages
expectedLogs := []string{"Message 1", "Message 2", "Message 3"}
// Check if the number of logs matches
if len(logs) != len(expectedLogs) {
t.Errorf("Expected %d logs, but got %d", len(expectedLogs), len(logs))
}
// Check if each log message is as expected
for i, expectedLog := range expectedLogs {
if logs[i] != expectedLog {
t.Errorf("Expected log: %s, but got: %s", expectedLog, logs[i])
}
}
}
func TestMockLogsRegex(t *testing.T) {
// Define log message with multiple fields
logMessage := `time=2023-11-15T23:34:25.522+04:00 level=WARN msg="Engine Shutting Down"`
// Find submatches using the mockLogsRegex
matches := mockLogsRegex.FindStringSubmatch(logMessage)
// Check if the 'msg' field was found
if len(matches) < 2 {
t.Errorf("Unable to extract 'msg' field from log message")
}
// Check if the extracted 'msg' value is as expected
expectedMsg := "Engine Shutting Down"
if matches[1] != expectedMsg {
t.Errorf("Expected 'msg' value: %s, but got: %s", expectedMsg, matches[1])
}
}