-
Notifications
You must be signed in to change notification settings - Fork 1
/
enums_test.go
88 lines (80 loc) · 1.9 KB
/
enums_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
package wcrawler_test
import (
"testing"
"github.com/gustavooferreira/wcrawler"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReturningAppStateString(t *testing.T) {
tests := map[string]struct {
input wcrawler.AppState
expectedOutput string
}{
"test 'IDLE' state": {
input: wcrawler.AppState_IDLE,
expectedOutput: "IDLE",
},
"test 'Running' state": {
input: wcrawler.AppState_Running,
expectedOutput: "Running",
},
"test 'Finished' state": {
input: wcrawler.AppState_Finished,
expectedOutput: "Finished",
},
"test 'Unknown' state": {
input: wcrawler.AppState_Unknown,
expectedOutput: "Unknown",
},
"test missing state": {
input: -100,
expectedOutput: "Unknown",
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
value := test.input.String()
assert.Equal(t, test.expectedOutput, value)
})
}
}
func TestParsingAppStateString(t *testing.T) {
tests := map[string]struct {
input string
expectedErr bool
expectedOutput wcrawler.AppState
}{
"test 'IDLE' state": {
input: "IDLE",
expectedOutput: wcrawler.AppState_IDLE,
},
"test 'Running' state": {
input: "Running",
expectedOutput: wcrawler.AppState_Running,
},
"test 'Finished' state": {
input: "Finished",
expectedOutput: wcrawler.AppState_Finished,
},
"test 'Unknown' state": {
expectedOutput: wcrawler.AppState_Unknown,
input: "Unknown",
},
"test missing state": {
input: "qwueyqwie",
expectedErr: true,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
var value wcrawler.AppState
err := value.Parse(test.input)
if test.expectedErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, test.expectedOutput, value)
})
}
}