Improve test structures using subtests

This commit is contained in:
Ian Fijolek
2024-11-14 11:35:26 -08:00
parent 3f6c8f5a22
commit 32745c816c
5 changed files with 182 additions and 163 deletions
+17 -8
View File
@@ -1,6 +1,9 @@
package main
import "testing"
import (
"fmt"
"testing"
)
func TestUtilEqualSliceString(t *testing.T) {
cases := []struct {
@@ -21,12 +24,18 @@ func TestUtilEqualSliceString(t *testing.T) {
}
for _, c := range cases {
actual := EqualSliceString(c.a, c.b)
if actual != c.expected {
t.Errorf(
"EqualSliceString(%v, %v), expected=%v actual=%v",
c.a, c.b, c.expected, actual,
)
}
c := c
t.Run(fmt.Sprintf("%v %v", c.a, c.b), func(t *testing.T) {
t.Parallel()
actual := EqualSliceString(c.a, c.b)
if actual != c.expected {
t.Errorf(
"EqualSliceString(%v, %v), expected=%v actual=%v",
c.a, c.b, c.expected, actual,
)
}
})
}
}