/
testing_t.go
65 lines (51 loc) · 1.05 KB
/
testing_t.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
package test
// T our minimal testing interface for our custom assertions
type T interface {
Log(args ...interface{})
Logf(format string, args ...interface{})
Errorf(format string, args ...interface{})
FailNow()
Fail()
Fatalf(format string, args ...interface{})
}
func NewMockT() *MockT {
return &MockT{}
}
var _ T = &MockT{}
type MockT struct {
logfCount int
errorfCount int
fatalfCount int
failnowCount int
failCount int
}
func (t *MockT) Log(_ ...interface{}) {
t.logfCount++
}
func (t *MockT) Logf(_ string, _ ...interface{}) {
t.logfCount++
}
func (t *MockT) Errorf(_ string, _ ...interface{}) {
t.errorfCount++
}
func (t *MockT) Fatalf(_ string, _ ...interface{}) {
t.fatalfCount++
}
func (t *MockT) FailNow() {
t.failnowCount++
}
func (t *MockT) Fail() {
t.failCount++
}
func (t *MockT) CalledLogf() bool {
return t.logfCount > 0
}
func (t *MockT) CalledErrorf() bool {
return t.errorfCount > 0
}
func (t *MockT) CalledFatalf() bool {
return t.fatalfCount > 0
}
func (t *MockT) CalledFailNow() bool {
return t.failnowCount > 0
}