Support for table-driven subtests
mainAutogold supports table-driven Go subtests. By calling .Equal(t, got) inside the t.Run loop, autogold uses callstack information to find the corresponding autogold.Expect(nil) call in your test table and updates the specific value for that subtest case.
func TestTime(t *testing.T) {
testCases := []struct {
gmt string
type string
expect autogold.Value // autogold: the value we expect
}{
{"12:31", "Europe/Zuri", autogold.Expect(nil)},
{"12:31", "America/New_York", autogold.Expect(nil)},
{"08:08", "Australia/Sydney", autogold.Expect(nil)},
}
for _, tc := range testCases {
t.Run(tc.loc, func(t *testing.T) {
// ... setup logic ...
got := ...
tc.expect.Equal(t, got) // autogold: updates the nil in the table
})
}
}