-
Notifications
You must be signed in to change notification settings - Fork 16
/
assert_test.go
92 lines (69 loc) · 2.06 KB
/
assert_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package assert
import (
"errors"
"testing"
)
// NOTES:
// - Run "go test" to run tests
// - Run "gocov test | gocov report" to report on test converage by file
// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called
//
// or
//
// -- may be a good idea to change to output path to somewherelike /tmp
// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
//
func MyCustomErrorHandler(t testing.TB, errs map[string]string, key, expected string) {
val, ok := errs[key]
EqualSkip(t, 2, ok, true)
NotEqualSkip(t, 2, val, nil)
EqualSkip(t, 2, val, expected)
}
func TestRegexMatchAndNotMatch(t *testing.T) {
goodRegex := "^(.*/vendor/)?github.com/go-playground/assert$"
MatchRegex(t, "github.com/go-playground/assert", goodRegex)
MatchRegex(t, "/vendor/github.com/go-playground/assert", goodRegex)
NotMatchRegex(t, "/vendor/github.com/go-playground/test", goodRegex)
}
func TestBasicAllGood(t *testing.T) {
err := errors.New("my error")
NotEqual(t, err, nil)
Equal(t, err.Error(), "my error")
err = nil
Equal(t, err, nil)
fn := func() {
panic("omg omg omg!")
}
PanicMatches(t, func() { fn() }, "omg omg omg!")
PanicMatches(t, func() { panic("omg omg omg!") }, "omg omg omg!")
/* if you uncomment creates hard fail, that is expected
// you cant really do this, but it is here for the sake of completeness
fun := func() {}
PanicMatches(t, func() { fun() }, "omg omg omg!")
*/
errs := map[string]string{}
errs["Name"] = "User Name Invalid"
errs["Email"] = "User Email Invalid"
MyCustomErrorHandler(t, errs, "Name", "User Name Invalid")
MyCustomErrorHandler(t, errs, "Email", "User Email Invalid")
}
func TestEquals(t *testing.T) {
type Test struct {
Name string
}
tst := &Test{
Name: "joeybloggs",
}
Equal(t, tst, tst)
NotEqual(t, tst, nil)
NotEqual(t, nil, tst)
type TestMap map[string]string
var tm TestMap
Equal(t, tm, nil)
Equal(t, nil, tm)
var iface interface{}
var iface2 interface{}
iface = 1
Equal(t, iface, 1)
NotEqual(t, iface, iface2)
}