File: assert_test.go

package info (click to toggle)
golang-github-gitleaks-go-gitdiff 0.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 800 kB
  • sloc: makefile: 2; sh: 1
file content (30 lines) | stat: -rw-r--r-- 710 bytes parent folder | download
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
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)
	}
}