summaryrefslogtreecommitdiff
path: root/pkg/gitdiff/assert_test.go
diff options
context:
space:
mode:
authorAnton Medvedev <anton@medv.io>2025-11-30 12:46:34 +0100
committerAnton Medvedev <anton@medv.io>2025-11-30 12:46:34 +0100
commitf6b0f38af648d028422a7494378b5dabdc90573f (patch)
tree3c26cfc269c021300a2d1e4e02623dd440c20226 /pkg/gitdiff/assert_test.go
First commit
Diffstat (limited to 'pkg/gitdiff/assert_test.go')
-rw-r--r--pkg/gitdiff/assert_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/pkg/gitdiff/assert_test.go b/pkg/gitdiff/assert_test.go
new file mode 100644
index 0000000..878f13c
--- /dev/null
+++ b/pkg/gitdiff/assert_test.go
@@ -0,0 +1,30 @@
+package gitdiff
+
+import (
+ "errors"
+ "strings"
+ "testing"
+)
+
+func assertError(t *testing.T, expected interface{}, actual error, action string) {
+ if actual == nil {
+ t.Fatalf("expected error %s, but got nil", action)
+ }
+
+ switch exp := expected.(type) {
+ case bool:
+ if !exp {
+ t.Fatalf("unexpected error %s: %v", action, actual)
+ }
+ case string:
+ if !strings.Contains(actual.Error(), exp) {
+ t.Fatalf("incorrect error %s: %q does not contain %q", action, actual.Error(), exp)
+ }
+ case error:
+ if !errors.Is(actual, exp) {
+ t.Fatalf("incorrect error %s: expected %T (%v), actual: %T (%v)", action, exp, exp, actual, actual)
+ }
+ default:
+ t.Fatalf("unsupported expected error type: %T", exp)
+ }
+}