Skip to content

Commit 28a7394

Browse files
committed
feat(test_utils): add new testing helpers
1 parent 6439b29 commit 28a7394

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test_utils/test_utils.go

+32
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ func Equals[V comparable](tb testing.TB, got V, exp V) {
1111
}
1212
}
1313

14+
func EqualsMap[K comparable, V comparable](tb testing.TB, got map[K]V, exp map[K]V) {
15+
if len(got) != len(exp) {
16+
tb.Fatalf("\nexp (len %d): %v\ngot (len %d): %v", len(exp), exp, len(got), got)
17+
}
18+
19+
for k, v := range exp {
20+
if gotV, gotOk := got[k]; !gotOk {
21+
tb.Fatalf("\nkey `%v` in got map not present", k)
22+
} else if v != gotV {
23+
tb.Fatalf("\nin got[%v]\nexp: %v\ngot: %v", k, v, gotV)
24+
}
25+
}
26+
}
27+
28+
func EqualsList[V comparable](tb testing.TB, got []V, exp []V) {
29+
if len(got) != len(exp) {
30+
tb.Fatalf("\nexp (len %d): %v\ngot (len %d): %v", len(exp), exp, len(got), got)
31+
}
32+
33+
for i, v := range exp {
34+
if got[i] != v {
35+
tb.Fatalf("\nin got[%v]\nexp: %v\ngot: %v", i, v, got[i])
36+
}
37+
}
38+
}
39+
1440
func ExpectError(tb testing.TB, err error, exp string) {
1541
if err == nil {
1642
tb.Fatalf("expected error, got nil")
@@ -22,3 +48,9 @@ func ExpectError(tb testing.TB, err error, exp string) {
2248
func ExpectNil(tb testing.TB, d any) {
2349
Equals(tb, fmt.Sprintf("%v", d), "<nil>")
2450
}
51+
52+
func ExpectNoError(tb testing.TB, err error) {
53+
if err != nil {
54+
tb.Fatalf("expected none, got error\nerror: %s", err)
55+
}
56+
}

0 commit comments

Comments
 (0)