...
1
16
17 package test
18
19 import (
20 "strings"
21 "testing"
22 )
23
24
25
26
27 func ExpectError(t *testing.T, err error, substr string) {
28 if err != nil {
29 if len(substr) == 0 {
30 t.Fatalf("expect nil error but got %q", err.Error())
31 } else if !strings.Contains(err.Error(), substr) {
32 t.Fatalf("expect error to contain %q but got %q", substr, err.Error())
33 }
34 } else if len(substr) > 0 {
35 t.Fatalf("expect error to contain %q but got nil error", substr)
36 }
37 }
38
39
40
41
42 func SkipRest(t *testing.T, desc string, err error, contains string) bool {
43 if err != nil {
44 if len(contains) == 0 {
45 t.Errorf("case %q, expect nil error but got %q", desc, err.Error())
46 } else if !strings.Contains(err.Error(), contains) {
47 t.Errorf("case %q, expect error to contain %q but got %q", desc, contains, err.Error())
48 }
49 return true
50 } else if len(contains) > 0 {
51 t.Errorf("case %q, expect error to contain %q but got nil error", desc, contains)
52 return true
53 }
54 return false
55 }
56
View as plain text