-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpet_test.go
63 lines (56 loc) · 1.11 KB
/
pet_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
package main
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReadConfig(t *testing.T) {
tcs := []struct {
name string
input string
environment map[string]string
want []Pet
}{
{
name: "basic",
input: "testdata/basic.hcl",
want: []Pet{
&Cat{Name: "Ink", Sound: "meow"},
&Dog{Name: "Swinney", Breed: "Dachshund"},
},
},
{
name: "variables",
input: "testdata/variables.hcl",
environment: map[string]string{
"CAT_SOUND": "nyan",
},
want: []Pet{
&Cat{Name: "Neko", Sound: "nyan"},
&Cat{Name: "Whiskers", Sound: "meow"},
},
},
{
name: "functions",
input: "testdata/function.hcl",
want: []Pet{
&Dog{Name: "Spot", Breed: "Pug"},
},
},
}
for _, tc := range tcs {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
for k, v := range tc.environment {
os.Setenv(k, v)
}
got, err := ReadConfig(tc.input)
if assert.Nil(t, err, "error while parsing input") {
assert.Equal(t, tc.want, got)
} else {
assert.Fail(t, err.Error())
}
})
}
}