-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdecode_test.go
More file actions
50 lines (42 loc) · 938 Bytes
/
decode_test.go
File metadata and controls
50 lines (42 loc) · 938 Bytes
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 scl
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func Test_AFileCanBeDecodedWithAnImplicitFileSystem(t *testing.T) {
type decodable struct {
Value0 string `hcl:"value0"`
Value1 int `hcl:"value1"`
Value2 []string `hcl:"value2"`
}
for cycle, test := range []struct {
path string
expected decodable
err error
}{
{
path: "fixtures/valid/decode.scl",
expected: decodable{
"1",
1,
[]string{"a", "b", "c"},
},
},
{
path: "fixtures/invalid/decode.scl",
err: fmt.Errorf("[fixtures/invalid/decode.scl:1] error parsing list, expected comma or list end, got: EOF"),
},
} {
t.Logf("Cycle %d", cycle)
got := decodable{}
err := DecodeFile(&got, test.path)
if test.err == nil {
require.Nil(t, err)
require.Equal(t, got, test.expected)
} else {
require.NotNil(t, err)
require.Equal(t, test.err.Error(), err.Error())
}
}
}