-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert.go
More file actions
43 lines (39 loc) · 957 Bytes
/
assert.go
File metadata and controls
43 lines (39 loc) · 957 Bytes
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
35
36
37
38
39
40
41
42
43
package asserts
import (
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/go-test/deep"
)
// Equals fails the test if exp is not equal to act.
func Equals[T any](tb testing.TB, exp, act T, message string) {
if diff := deep.Equal(exp, act); diff != nil {
_, file, line, _ := runtime.Caller(1)
tb.Logf(
"\t\033[31m✖ %s:%d:%s\n\n\t\033[36mexp\033[39m: %#v\n\n\t\033[36mgot\033[39m: %#v\n\n\t\033[36mdiff\033[39m:\n\t\t%s\033[39m\n\n",
filepath.Base(file),
line,
message,
exp,
act,
strings.Join(diff, "\n\t\t"),
)
tb.FailNow()
} else {
tb.Logf("\t\033[32;1m✔ \033[37;0m%s\033[39m\n", message)
}
}
// Success fails the test if err != nil.
func Success(tb testing.TB, err error) {
if nil != err {
_, file, line, _ := runtime.Caller(1)
tb.Logf(
"\t\033[31m✖ %s:%d\n\n\t\033[36mget unexpected error\u001B[39m:\n\t\t%s\u001B[39m\n\n",
filepath.Base(file),
line,
err,
)
tb.FailNow()
}
}