-
Notifications
You must be signed in to change notification settings - Fork 1
/
assert_test.go
45 lines (37 loc) · 923 Bytes
/
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
package cors
import (
"fmt"
"reflect"
"runtime/debug"
"testing"
)
// assertEquals fails the test if got result isn't equals expected result
func assertEquals(t *testing.T, want, got interface{}, msg string) {
if reflect.DeepEqual(want, got) {
return
}
fail(t, msg, want, got)
}
// assertTrue fails the test if the condition is false
func assertTrue(t *testing.T, condition bool, msg string) {
if condition {
return
}
fail(t, msg, true, condition)
}
// assertFalse fails the test if the condition is true
func assertFalse(t *testing.T, condition bool, msg string) {
if !condition {
return
}
fail(t, msg, false, condition)
}
// fail fails the test and prints place of error and error message
func fail(t *testing.T, msg string, want, got interface{}) {
fmt.Printf(
"%s\n want: %#v\n got: %#v\n",
msg, want, got,
)
fmt.Println(string(debug.Stack()))
t.FailNow()
}