-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathparser_test.go
54 lines (44 loc) · 1.31 KB
/
parser_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
package config
import (
"testing"
"time"
. "github.com/onsi/gomega"
)
func TestParseConfigFromYamlBytes(t *testing.T) {
RegisterTestingT(t)
type Duration string
type BigConfig struct {
Simple string
Str string `json:"name"`
Integer16 int16
Timeout time.Duration
NotTimeout Duration
}
var testData = map[string]struct {
input string
want BigConfig
fail bool
}{
"simple": {"simple: test", BigConfig{Simple: "test"}, false},
"bad simple": {"simple test", BigConfig{}, true},
"json tag": {"name: BigName", BigConfig{Str: "BigName"}, false},
"int16": {"integer16: 25", BigConfig{Integer16: 25}, false},
"duration number": {"timeout: 5000000000", BigConfig{Timeout: 5 * time.Second}, false},
"duration string": {"timeout: 5s", BigConfig{Timeout: 5 * time.Second}, false},
"bad duration": {"timeout: s5s", BigConfig{}, true},
"not duration": {"nottimeout: 30SecToAgent", BigConfig{NotTimeout: "30SecToAgent"}, false},
}
for name, tt := range testData {
t.Run(name, func(t *testing.T) {
RegisterTestingT(t)
out := BigConfig{}
err := parseConfigFromYamlBytes([]byte(tt.input), &out)
if tt.fail {
Expect(err).To(HaveOccurred())
return
}
Expect(err).ToNot(HaveOccurred())
Expect(out).To(Equal(tt.want))
})
}
}