aboutsummaryrefslogtreecommitdiff
path: root/pkg/testkit/testkit.go
blob: 3cc4afd4fa9f0ae6330b5aed8f1db23cdb7070c8 (plain)
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
32
33
34
//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) {
	t.Helper()
	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) {
	t.Helper()
	if err != nil {
		t.Fatalf("%s() fatal error : %+v", method, err)
	}
}

func TestError(t *testing.T, method string, want, got error) {
	t.Helper()
	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()
}