forked from linkedin/goavro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathensure_test.go
41 lines (35 loc) · 864 Bytes
/
ensure_test.go
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
package goavro
// NOTE: This file was copied from https://github.com/karrick/gorill
import (
"strings"
"testing"
)
func ensureError(tb testing.TB, err error, contains ...string) {
tb.Helper()
if len(contains) == 0 || (len(contains) == 1 && contains[0] == "") {
if err != nil {
tb.Fatalf("GOT: %v; WANT: %v", err, contains)
}
return
}
if err == nil {
tb.Errorf("GOT: %v; WANT: %v", err, contains)
} else {
for _, stub := range contains {
if stub != "" && !strings.Contains(err.Error(), stub) {
tb.Errorf("GOT: %v; WANT: %q", err, stub)
}
}
}
}
// ensureNoPanic prettifies the output so one knows which test case caused a
// panic.
func ensureNoPanic(tb testing.TB, label string, callback func()) {
tb.Helper()
defer func() {
if r := recover(); r != nil {
tb.Fatalf("TEST: %s: GOT: %v", label, r)
}
}()
callback()
}