forked from bifurcation/mint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon_test.go
58 lines (47 loc) · 1.17 KB
/
common_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
package mint
import (
"bytes"
"encoding/hex"
"fmt"
"reflect"
"testing"
)
func assert(t *testing.T, test bool, msg string) {
if !test {
t.Fatalf(msg)
}
}
func assertError(t *testing.T, err error, msg string) {
assert(t, err != nil, msg)
}
func assertNotError(t *testing.T, err error, msg string) {
if err != nil {
msg += ": " + err.Error()
}
assert(t, err == nil, msg)
}
func assertNotNil(t *testing.T, x interface{}, msg string) {
assert(t, x != nil, msg)
}
func assertEquals(t *testing.T, a interface{}, b interface{}) {
if a != b {
assert(t, false, fmt.Sprintf("%v != %v", a, b))
}
}
func assertByteEquals(t *testing.T, a []byte, b []byte) {
if !bytes.Equal(a, b) {
assert(t, false, fmt.Sprintf("%v != %v", hex.EncodeToString(a), hex.EncodeToString(b)))
}
}
func assertDeepEquals(t *testing.T, a interface{}, b interface{}) {
if !reflect.DeepEqual(a, b) {
assert(t, false, fmt.Sprintf("%v != %v", a, b))
}
}
type errorReadWriter struct{}
func (e errorReadWriter) Read(p []byte) (n int, err error) {
return 0, fmt.Errorf("Unknown read error")
}
func (e errorReadWriter) Write(p []byte) (n int, err error) {
return 0, fmt.Errorf("Unknown write error")
}