aboutsummaryrefslogtreecommitdiff
path: root/pkg/testkit
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/testkit')
-rw-r--r--pkg/testkit/testkit.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/testkit/testkit.go b/pkg/testkit/testkit.go
new file mode 100644
index 0000000..526e1b3
--- /dev/null
+++ b/pkg/testkit/testkit.go
@@ -0,0 +1,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()
+}