-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_test.go
More file actions
104 lines (99 loc) · 2.83 KB
/
log_test.go
File metadata and controls
104 lines (99 loc) · 2.83 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package logs
import (
"testing"
)
func Test_Log(t *testing.T) {
tests := []struct {
name string
logRequest *LogErrorRequest
logResponse *LogResponse
}{
{
name: "Test logging with default log type for error",
logRequest: &LogErrorRequest{
AppName: "Outlook Calendar",
ErrorCode: 404,
ErrorMessage: "Not Found",
EventType: "Get Event",
LogType: Default, // Using default log type
Information: map[string]string{"key": "value"},
},
logResponse: &LogResponse{
LogType: Error,
msg: "Outlook Calendar - Unable to Get Event : 404 - Not Found",
},
},
{
name: "Test logging with default log type for info",
logRequest: &LogErrorRequest{
AppName: "Outlook Calendar",
ErrorCode: 200,
ErrorMessage: "Success",
EventType: "Get Event",
LogType: Default, // Using info log type
Information: map[string]string{"key": "value"},
},
logResponse: &LogResponse{
LogType: Info,
msg: "Outlook Calendar - Unable to Get Event : 200 - Success",
},
},
{
name: "Test logging with Info log type",
logRequest: &LogErrorRequest{
AppName: "Outlook Calendar",
ErrorCode: 200,
ErrorMessage: "Success",
EventType: "Get Event",
LogType: Info, // Using info log type
Information: map[string]string{"key": "value"},
},
logResponse: &LogResponse{
LogType: Info,
msg: "Outlook Calendar - Unable to Get Event : 200 - Success",
},
},
{
name: "Test logging with 403 as info log type",
logRequest: &LogErrorRequest{
AppName: "Outlook Calendar",
ErrorCode: 403,
ErrorMessage: "User Rate Limit Exceeded",
EventType: "Get Event",
LogType: Info,
Information: map[string]string{"key": "value"},
},
logResponse: &LogResponse{
LogType: Info,
msg: "Outlook Calendar - Unable to Get Event : 403 - User Rate Limit Exceeded",
},
},
{
name: "Test logging with 403 as Error log type",
logRequest: &LogErrorRequest{
AppName: "Outlook Calendar",
ErrorCode: 403,
ErrorMessage: "Rate limit Exceeded",
EventType: "Get Event",
LogType: Error, // Using info log type
Information: map[string]string{"key": "value"},
},
logResponse: &LogResponse{
LogType: Error,
msg: "Outlook Calendar - Unable to Get Event : 403 - Rate limit Exceeded",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actualLog := Log(test.logRequest)
t.Log(actualLog.msg)
if actualLog.LogType != test.logResponse.LogType {
t.Errorf("Expected log type: %v, Got: %v", test.logResponse.LogType, actualLog.LogType)
}
if actualLog.msg != test.logResponse.msg {
t.Errorf("Expected log message: %v, Got: %v", test.logResponse.msg, actualLog.msg)
}
})
}
}