go-by-test/walk/walk_test.go
2024-09-20 19:56:28 +02:00

36 lines
582 B
Go

package walk
import (
"reflect"
"testing"
)
func TestWalk(t *testing.T) {
cases := []struct {
Name string
Input interface{}
ExpectedCalls []string
}{
{
"struct with one string field",
struct {
Name string
}{"Chris"},
[]string{"Chris"},
},
}
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)
})
if !reflect.DeepEqual(got, test.ExpectedCalls) {
t.Errorf("got %v want %v", got, test.ExpectedCalls)
}
})
}
}