-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
55 lines (49 loc) · 1009 Bytes
/
config_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseConfig(t *testing.T) {
cases := []struct {
name string
testFile string
errMsg string
}{
{
name: "valid config",
testFile: "valid.yaml",
errMsg: "",
},
{
name: "not yaml",
testFile: "invalid.txt",
errMsg: "line 1: cannot unmarshal !!str `abc` into main.Config",
},
{
name: "empty file",
testFile: "empty.txt",
errMsg: "Commands: cannot be blank",
},
{
name: "empty yaml",
testFile: "empty.yaml",
errMsg: "Commands: cannot be blank",
},
{
name: "missing fields",
testFile: "missing_fields.yaml",
errMsg: "Commands: cannot be blank",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
cf := openTestFile(t, "TestParseConfig", tc.testFile)
_, err := parseConfig(cf)
if tc.errMsg == "" {
assert.Nil(t, err)
} else {
assert.ErrorContains(t, err, tc.errMsg)
}
})
}
}