3
0

Improve setting import tests

This commit is contained in:
Tomaž Jerman
2019-10-16 13:38:59 +02:00
parent 346f9bd4df
commit 22cfc3db9a
2 changed files with 32 additions and 46 deletions

View File

@@ -10,11 +10,6 @@ import (
)
func TestSettingImport_CastSet(t *testing.T) {
type tv struct {
name string
value string
}
var aux interface{}
req := require.New(t)
f, err := os.Open("testdata/settings.yaml")
@@ -26,39 +21,23 @@ func TestSettingImport_CastSet(t *testing.T) {
imp := NewImporter()
err = imp.CastSet(aux)
req.Nil(err)
req.Len(imp.settings, 6)
tests := []tv{
tv{
name: "array",
value: "[\"v1\",\"v2\"]",
},
tv{
name: "object",
value: "{\"k1\":\"v1\",\"k2\":\"v2\"}",
},
tv{
name: "plain_b",
value: "true",
},
tv{
name: "plain_double",
value: "12.34",
},
tv{
name: "plain_double_2",
value: "12",
},
tv{
name: "plain_s",
value: "\"string\"",
},
tests := map[string]string{
"v_string": "\"string\"",
"v_float": "12.34",
"v_int-as-float": "123",
"v_bool_true": "true",
"v_bool_false": "false",
"v_slice": "[1,1.23,\"string\",true,false]",
"v_map": "{\"k1\":\"string\",\"k2\":1,\"k3\":1.23,\"k4\":true,\"k5\":false}",
}
for _, t := range tests {
v := imp.settings.First(t.name)
vv, _ := types.JSONText(t.value).MarshalJSON()
ee, _ := v.Value.MarshalJSON()
req.Equal(vv, ee)
for k, test := range tests {
t.Run(k, func(t *testing.T) {
v := imp.settings.First(k)
vv, _ := types.JSONText(test).MarshalJSON()
ee, _ := v.Value.MarshalJSON()
req.Equal(ee, vv)
})
}
}

View File

@@ -1,10 +1,17 @@
array:
- v1
- v2
object:
k1: v1
k2: v2
plain_b: true
plain_double: 12.34
plain_double_2: 12
plain_s: string
v_string: string
v_float: 12.34
v_int-as-float: 123
v_bool_true: true
v_bool_false: false
v_slice:
- 1
- 1.23
- string
- true
- false
v_map:
k1: string
k2: 1
k3: 1.23
k4: true
k5: false