forked from wtfutil/wtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsers_test.go
50 lines (44 loc) · 993 Bytes
/
parsers_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
package cfg
import (
"testing"
"github.com/olebedev/config"
)
func Test_ParseAsMapOrList(t *testing.T) {
tests := []struct {
name string
configKey string
yaml string
expectedCount int
}{
{
name: "as empty set",
configKey: "data",
yaml: "",
expectedCount: 0,
},
{
name: "as map",
configKey: "data",
yaml: "data:\n a: cat\n b: dog",
expectedCount: 2,
},
{
name: "as list",
configKey: "data",
yaml: "data:\n - cat\n - dog\n - rat\n",
expectedCount: 3,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ymlConfig, err := config.ParseYaml(tt.yaml)
if err != nil {
t.Errorf("\nexpected: no error\n got: %v", err)
}
actual := ParseAsMapOrList(ymlConfig, tt.configKey)
if tt.expectedCount != len(actual) {
t.Errorf("\nexpected: %d\n got: %d", tt.expectedCount, len(actual))
}
})
}
}