-
Notifications
You must be signed in to change notification settings - Fork 0
/
logType_test.go
155 lines (114 loc) · 2.88 KB
/
logType_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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package jobrunner
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestString_AppRoot(t *testing.T) {
// arrange
var appRootValue = 0
// SUT
var sut = LogType(appRootValue)
// act
var result = sut.String()
// assert
assert.Equal(t, LogTypeAppRoot, sut)
assert.Equal(t, appRootLogTypeName, result)
}
func TestString_NonSupportedLogTypes(t *testing.T) {
// arrange
var unsupportedValue = 1 << 31
// SUT
var sut = LogType(unsupportedValue)
// act
var result = sut.String()
// assert
assert.Zero(t, result)
}
func TestString_SingleSupportedLogType(t *testing.T) {
// SUT
var sut = LogTypeMethodLogic
// act
var result = sut.String()
// assert
assert.Equal(t, methodLogicLogTypeName, result)
}
func TestString_MultipleSupportedLogTypes(t *testing.T) {
// arrange
var supportedValue = LogTypeProcessEnter | LogTypeProcessRequest | LogTypeMethodLogic | LogTypeProcessResponse | LogTypeProcessExit
// SUT
var sut = LogType(supportedValue)
// act
var result = sut.String()
// assert
assert.Equal(t, LogTypeGeneralLogging, sut)
assert.True(t, strings.Contains(result, apiEnterLogTypeName))
assert.True(t, strings.Contains(result, apiRequestLogTypeName))
assert.True(t, strings.Contains(result, methodLogicLogTypeName))
assert.True(t, strings.Contains(result, apiResponseLogTypeName))
assert.True(t, strings.Contains(result, apiExitLogTypeName))
}
func TestHasFlag_FlagMatch_AppRoot(t *testing.T) {
// arrange
var flag = LogTypeAppRoot
// SUT
var sut = LogTypeAppRoot
// act
var result = sut.HasFlag(flag)
// assert
assert.True(t, result)
}
func TestHasFlag_FlagNoMatch_AppRoot(t *testing.T) {
// arrange
var flag = LogTypeAppRoot
// SUT
var sut = LogTypeProcessEnter | LogTypeProcessExit
// act
var result = sut.HasFlag(flag)
// assert
assert.True(t, result)
}
func TestHasFlag_FlagMatch_NotAppRoot(t *testing.T) {
// arrange
var flag = LogTypeMethodLogic
// SUT
var sut = LogTypeProcessEnter | LogTypeMethodLogic | LogTypeProcessExit
// act
var result = sut.HasFlag(flag)
// assert
assert.True(t, result)
}
func TestHasFlag_FlagNoMatch_NotAppRoot(t *testing.T) {
// arrange
var flag = LogTypeMethodLogic
// SUT
var sut = LogTypeProcessEnter | LogTypeProcessExit
// act
var result = sut.HasFlag(flag)
// assert
assert.False(t, result)
}
func TestNewLogType_NoMatchFound(t *testing.T) {
// arrange
var dummyValue = "some value"
// SUT + act
var result = NewLogType(dummyValue)
// assert
assert.Equal(t, LogTypeAppRoot, result)
}
func TestNewLogType_AppRoot(t *testing.T) {
// arrange
var dummyValue = appRootLogTypeName
// SUT + act
var result = NewLogType(dummyValue)
// assert
assert.Equal(t, LogTypeAppRoot, result)
}
func TestNewLogType_HappyPath(t *testing.T) {
for key, value := range logTypeNameMapping {
// SUT + act
var result = NewLogType(key)
// assert
assert.Equal(t, value, result)
}
}