forked from hashicorp/consul-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapstructure_test.go
49 lines (40 loc) · 1.1 KB
/
mapstructure_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
package main
import (
"os"
"reflect"
"testing"
"github.com/mitchellh/mapstructure"
)
func TestStringToFileModeFunc(t *testing.T) {
f := StringToFileModeFunc()
strType := reflect.TypeOf("")
fmType := reflect.TypeOf(os.FileMode(0))
u32Type := reflect.TypeOf(uint32(0))
cases := []struct {
f, t reflect.Type
data interface{}
expected interface{}
err bool
}{
{strType, fmType, "0600", os.FileMode(0600), false},
{strType, fmType, "4600", os.FileMode(04600), false},
// Prepends 0 automatically
{strType, fmType, "600", os.FileMode(0600), false},
// Invalid file mode
{strType, fmType, "12345", "12345", true},
// Invalid syntax
{strType, fmType, "abcd", "abcd", true},
// Different type
{strType, strType, "0600", "0600", false},
{strType, u32Type, "0600", "0600", false},
}
for i, tc := range cases {
actual, err := mapstructure.DecodeHookExec(f, tc.f, tc.t, tc.data)
if (err != nil) != tc.err {
t.Errorf("case %d: %s", i, err)
}
if !reflect.DeepEqual(actual, tc.expected) {
t.Errorf("case %d: expected %#v to be %#v", i, actual, tc.expected)
}
}
}