/
enum_test.go
68 lines (60 loc) · 1.31 KB
/
enum_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
package cmcm
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOutputFormat_String(t *testing.T) {
tests := map[string]struct {
format OutputFormat
want string
}{
"plain": {Plain, "plain"},
"json": {JSON, "json"},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.format.String())
})
}
}
func TestOutputFormat_Valid(t *testing.T) {
tests := map[string]struct {
format OutputFormat
want error
}{
"plain": {Plain, nil},
"json": {JSON, nil},
"invalid": {OutputFormat("invalid"), ErrInvalidOutputFormat},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if tt.want != nil {
assert.ErrorIs(t, tt.format.Valid(), tt.want)
} else {
assert.NoError(t, tt.format.Valid())
}
})
}
}
func TestParseOutputFormat(t *testing.T) {
tests := map[string]struct {
s string
want OutputFormat
wantErr error
}{
"plain": {"plain", Plain, nil},
"json": {"json", JSON, nil},
"invalid": {"invalid", "", ErrInvalidOutputFormat},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got, err := ParseOutputFormat(tt.s)
assert.Equal(t, tt.want, got)
if tt.wantErr != nil {
assert.ErrorIs(t, err, tt.wantErr)
} else {
assert.NoError(t, err)
}
})
}
}