Use DeepEqual instead of multiple if statements to reduce noise.
This commit is contained in:
parent
53e10dfa89
commit
895d10a627
|
@ -12,6 +12,11 @@ func TestDiffFieldReader_impl(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiffFieldReader_NestedSetUpdate(t *testing.T) {
|
func TestDiffFieldReader_NestedSetUpdate(t *testing.T) {
|
||||||
|
hashFn := func(a interface{}) int {
|
||||||
|
m := a.(map[string]interface{})
|
||||||
|
return m["val"].(int)
|
||||||
|
}
|
||||||
|
|
||||||
schema := map[string]*Schema{
|
schema := map[string]*Schema{
|
||||||
"list_of_sets_1": &Schema{
|
"list_of_sets_1": &Schema{
|
||||||
Type: TypeList,
|
Type: TypeList,
|
||||||
|
@ -26,10 +31,7 @@ func TestDiffFieldReader_NestedSetUpdate(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Set: func(a interface{}) int {
|
Set: hashFn,
|
||||||
m := a.(map[string]interface{})
|
|
||||||
return m["val"].(int)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -47,10 +49,7 @@ func TestDiffFieldReader_NestedSetUpdate(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Set: func(a interface{}) int {
|
Set: hashFn,
|
||||||
m := a.(map[string]interface{})
|
|
||||||
return m["val"].(int)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -97,44 +96,16 @@ func TestDiffFieldReader_NestedSetUpdate(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
list, ok := out.Value.([]interface{})
|
s := &Set{F: hashFn}
|
||||||
if !ok {
|
s.Add(map[string]interface{}{"val": 1})
|
||||||
t.Fatalf("nestedSetUpdate: bad: Value type\n\nexpected: []interface{}\n\ngot: %v", reflect.TypeOf(out.Value))
|
expected := s.List()
|
||||||
}
|
|
||||||
if len(list) != 1 {
|
|
||||||
t.Fatalf("nestedSetUpdate: bad: list length\n\nexpected: 1\n\ngot: %v\n\n", len(list))
|
|
||||||
}
|
|
||||||
|
|
||||||
var m map[string]interface{}
|
l := out.Value.([]interface{})
|
||||||
m, ok = list[0].(map[string]interface{})
|
i := l[0].(map[string]interface{})
|
||||||
if !ok {
|
actual := i["nested_set"].(*Set).List()
|
||||||
t.Fatalf("nestedSetUpdate: bad: list item type\n\nexpected: map[string]interface{}\n\ngot: %v\n\n", reflect.TypeOf(list[0]))
|
|
||||||
}
|
|
||||||
|
|
||||||
rawSet := m["nested_set"]
|
if !reflect.DeepEqual(expected, actual) {
|
||||||
if rawSet == nil {
|
t.Fatalf("bad: NestedSetUpdate\n\nexpected: %#v\n\ngot: %#v\n\n", expected, actual)
|
||||||
t.Fatalf("nestedSetUpdate: bad: nested_set\n\nexpected: not nil\n\ngot: nil\n\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
var set *Set
|
|
||||||
set, ok = rawSet.(*Set)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("nestedSetUpdate: bad: nested set type\n\nexpected: *Set\n\ngot: %v\n\n", reflect.TypeOf(m["nested_set"]))
|
|
||||||
}
|
|
||||||
if set.Len() != 1 {
|
|
||||||
t.Fatalf("nestedSetUpdate: bad: nested set length\n\nexpected: 1\n\ngot: %v\n\n", set.Len())
|
|
||||||
}
|
|
||||||
|
|
||||||
setList := set.List()
|
|
||||||
var item map[string]interface{}
|
|
||||||
item, ok = setList[0].(map[string]interface{})
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("nestedSetUpdate: bad: nested set item type\n\nexpected: map[string]interface{}\n\ngot: %v\n\n", reflect.TypeOf(setList[0]))
|
|
||||||
}
|
|
||||||
|
|
||||||
val := item["val"].(int)
|
|
||||||
if val != 1 {
|
|
||||||
t.Fatalf("nestedSetUpdate: bad: val\n\nexpected: 1\n\ngot: %v\n\n", val)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue