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