diff --git a/walk/walk_test.go b/walk/walk_test.go index 70441cd..0fb02b3 100644 --- a/walk/walk_test.go +++ b/walk/walk_test.go @@ -1,27 +1,35 @@ package walk import ( + "reflect" "testing" ) func TestWalk(t *testing.T) { - t.Run("walk function test", func(t *testing.T) { - expected := "Chris" - var got []string + cases := []struct { + Name string + Input interface{} + ExpectedCalls []string + }{ + { + "struct with one string field", + struct { + Name string + }{"Chris"}, + []string{"Chris"}, + }, + } - x := struct { - Name string - }{expected} + for _, test := range cases { + t.Run(test.Name, func(t *testing.T) { + var got []string + Walk(test.Input, func(input string) { + got = append(got, input) + }) - Walk(x, func(input string) { - got = append(got, input) + if !reflect.DeepEqual(got, test.ExpectedCalls) { + t.Errorf("got %v want %v", got, test.ExpectedCalls) + } }) - - if len(got) != 1 { - t.Errorf("wrong number of function calls, got %d want %d", len(got), 1) - } - if got[0] != expected { - t.Errorf("got %q want %q", got[0], expected) - } - }) + } }