Simplify the failing test
Remove a level of nesting and separate the passing and failing cases.
This commit is contained in:
parent
6502ffef22
commit
77eac88c9f
@ -852,21 +852,25 @@ func TestDecode_topLevelKeys(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecode_structureMixedFields(t *testing.T) {
|
func TestDecode_structureFlattened(t *testing.T) {
|
||||||
jsonConfig := `{
|
jsonA := `
|
||||||
"vars": {
|
{
|
||||||
"var_1": {
|
"var_1": {
|
||||||
"default": {
|
"default": {
|
||||||
"key1": "a",
|
"key1": "a",
|
||||||
"key2": "b"
|
"key2": "b"
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"var_2": {
|
}
|
||||||
"description": "an extra field is required",
|
`
|
||||||
"default": {
|
|
||||||
"key1": "a",
|
jsonB := `
|
||||||
"key2": "b"
|
{
|
||||||
}
|
"var_2": {
|
||||||
|
"description": "an extra field is required",
|
||||||
|
"default": {
|
||||||
|
"key1": "a",
|
||||||
|
"key2": "b"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -878,26 +882,27 @@ func TestDecode_structureMixedFields(t *testing.T) {
|
|||||||
Default map[string]string
|
Default map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Root struct {
|
var vA, vB []*V
|
||||||
Vars []*V
|
|
||||||
}
|
|
||||||
|
|
||||||
var r Root
|
err := Decode(&vA, jsonA)
|
||||||
|
|
||||||
err := Decode(&r, jsonConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.Vars) != 2 {
|
err = Decode(&vB, jsonB)
|
||||||
t.Fatalf("expected 2 Vars, got %d", len(r.Vars))
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Vars[1].Default == nil {
|
if len(vA) == 0 {
|
||||||
t.Fatalf("failed to decode Default field in %#v", r.Vars[1])
|
t.Fatal("failed to decode vA")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(r.Vars[0].Default, r.Vars[1].Default) {
|
if len(vB) == 0 {
|
||||||
t.Fatalf("defaults should match\n[0]: %#v\n[1]: %#v\n", r.Vars[0], r.Vars[1])
|
t.Fatal("failed to decode vB")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(vA[0].Default, vB[0].Default) {
|
||||||
|
t.Fatalf("defaults should match\n[0]: %#v\n[1]: %#v\n", vA[0], vB[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user