-
Notifications
You must be signed in to change notification settings - Fork 5
/
config_test.go
60 lines (56 loc) · 886 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
56
57
58
59
60
package differer
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestReadConfig(t *testing.T) {
tt := []struct {
name string
input string
exp *Config
valid bool
}{
{
name: "valid",
input: `---
runners:
a: b
timeout: 5s
`,
exp: &Config{
Timeout: 5 * time.Second,
Runners: map[string]string{"a": "b"},
},
valid: true,
},
{
name: "valid default timeout",
input: `---
runners:
a: b
`,
exp: &Config{
Timeout: 10 * time.Second,
Runners: map[string]string{"a": "b"},
},
valid: true,
},
{
name: "unexpected YAML syntax",
input: `@`,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
r := strings.NewReader(tc.input)
got, err := ReadConfig(r)
if !tc.valid {
require.NotNil(t, err)
return
}
require.Equal(t, tc.exp, got)
})
}
}