this repo has no description
1package main
2
3import (
4 "reflect"
5 "testing"
6)
7
8func TestWalk(t *testing.T) {
9
10 cases := []struct {
11 Name string
12 Input interface{}
13 ExpectedCalls []string
14 }{
15 {
16 "struct with one string field",
17 struct { Name string }{"Chris"},
18 []string{"Chris"},
19 },
20 {
21 "struct with two string field",
22 struct {
23 Name string
24 City string
25 }{"Chris", "London"},
26 []string{"Chris", "London"},
27 },
28 {
29 "struct with non string field",
30 struct {
31 Name string
32 Age int
33 }{"Chris", 33},
34 []string{"Chris"},
35 },
36 }
37
38 for _, test := range cases {
39 t.Run(test.Name, func(t *testing.T) {
40 var got []string
41
42 walk(test.Input, func(input string) {
43 got = append(got, input)
44 })
45
46 if !reflect.DeepEqual(got, test.ExpectedCalls) {
47 t.Errorf("got %v, want %v", got, test.ExpectedCalls)
48 }
49 })
50 }
51}