Skip to content

Instantly share code, notes, and snippets.

@negz
Last active April 27, 2020 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save negz/e6223997a85273ccbc8bf08b5c9df12a to your computer and use it in GitHub Desktop.
Save negz/e6223997a85273ccbc8bf08b5c9df12a to your computer and use it in GitHub Desktop.
Common setup code in Go tests
func TestDoTheThing(t *testing.T) {
cases := map[string]struct{
thingArg string
want bool
}{
// Add test cases here.
}
SetupTheThing()
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got := DoTheThing(tc.thingArg)
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("Test failed: %s", diff)
}
}
}
TeardownTheThing()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment