From 895d10a62729722ac1f0fdfb361422a1f554e2df Mon Sep 17 00:00:00 2001 From: Justin Marney Date: Sat, 17 Sep 2016 17:41:44 +0000 Subject: [PATCH] Use DeepEqual instead of multiple if statements to reduce noise. --- helper/schema/field_reader_diff_test.go | 59 +++++++------------------ 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/helper/schema/field_reader_diff_test.go b/helper/schema/field_reader_diff_test.go index 65a0d4496..7339dea7a 100644 --- a/helper/schema/field_reader_diff_test.go +++ b/helper/schema/field_reader_diff_test.go @@ -12,6 +12,11 @@ func TestDiffFieldReader_impl(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{ "list_of_sets_1": &Schema{ Type: TypeList, @@ -26,10 +31,7 @@ func TestDiffFieldReader_NestedSetUpdate(t *testing.T) { }, }, }, - Set: func(a interface{}) int { - m := a.(map[string]interface{}) - return m["val"].(int) - }, + Set: hashFn, }, }, }, @@ -47,10 +49,7 @@ func TestDiffFieldReader_NestedSetUpdate(t *testing.T) { }, }, }, - Set: func(a interface{}) int { - m := a.(map[string]interface{}) - return m["val"].(int) - }, + Set: hashFn, }, }, }, @@ -97,44 +96,16 @@ func TestDiffFieldReader_NestedSetUpdate(t *testing.T) { t.Fatalf("err: %v", err) } - list, ok := out.Value.([]interface{}) - if !ok { - t.Fatalf("nestedSetUpdate: bad: Value type\n\nexpected: []interface{}\n\ngot: %v", reflect.TypeOf(out.Value)) - } - if len(list) != 1 { - t.Fatalf("nestedSetUpdate: bad: list length\n\nexpected: 1\n\ngot: %v\n\n", len(list)) - } + s := &Set{F: hashFn} + s.Add(map[string]interface{}{"val": 1}) + expected := s.List() - var m map[string]interface{} - m, ok = list[0].(map[string]interface{}) - if !ok { - t.Fatalf("nestedSetUpdate: bad: list item type\n\nexpected: map[string]interface{}\n\ngot: %v\n\n", reflect.TypeOf(list[0])) - } + l := out.Value.([]interface{}) + i := l[0].(map[string]interface{}) + actual := i["nested_set"].(*Set).List() - rawSet := m["nested_set"] - if rawSet == nil { - 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) + if !reflect.DeepEqual(expected, actual) { + t.Fatalf("bad: NestedSetUpdate\n\nexpected: %#v\n\ngot: %#v\n\n", expected, actual) } }