1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
//go:build unit || integration
package testkit
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestValue[T any](t *testing.T, method string, want, got T) {
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("%s() mismatch (-want +got):\n%s", method, diff)
}
}
func TestFatalError(t *testing.T, method string, err error) {
if err != nil {
t.Fatalf("%s() fatal error : %+v", method, err)
}
}
func TestError(t *testing.T, method string, want, got error) {
if !equalError(want, got) {
t.Errorf("%s() err mismatch want: %+v got %+v", method, want, got)
}
}
func equalError(a, b error) bool {
return a == nil && b == nil || a != nil && b != nil && a.Error() == b.Error()
}
|