-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrassert_test.go
85 lines (71 loc) · 1.59 KB
/
errassert_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
package errassert_test
import (
"testing"
"github.com/zoido/errassert"
)
func NewMockT() *MockT {
return &MockT{}
}
type MockT struct {
failCalled bool
failNowCalled bool
logCalled bool
logfMsg string
}
var _ errassert.TestingT = (*MockT)(nil)
func (m *MockT) Helper() {}
func (m *MockT) FailNow() { m.failNowCalled = true }
func (m *MockT) Fail() { m.failCalled = true }
func (m *MockT) Log(args ...interface{}) {
m.logCalled = true
if len(args) == 1 {
m.logfMsg = args[0].(string)
}
}
func (m MockT) AssertFailed(t *testing.T) {
t.Helper()
if !m.failCalled {
t.Error("expected Fail to be called but it was not")
}
}
func (m MockT) AssertFailedNow(t *testing.T) {
t.Helper()
if !m.failNowCalled {
t.Error("expected FailNow to be called but it was not")
}
}
func (m MockT) AssertNotFailed(t *testing.T) {
t.Helper()
if m.failCalled {
t.Error("expected FailNow to not be called but it was")
}
}
func (m MockT) AssertNotFailedNow(t *testing.T) {
t.Helper()
if m.failNowCalled {
t.Error("expected FailNow to not be called but it was")
}
}
func (m MockT) AssertLogfCalled(t *testing.T) {
t.Helper()
if !m.logCalled {
t.Error("expected Logf to be called but it was not")
}
}
func (m MockT) AssertLogfNotCalled(t *testing.T) {
t.Helper()
if m.logCalled {
t.Error("expected Logf to not be called but it was")
}
}
func (m MockT) AssertLogfCalledWith(t *testing.T, expected string) {
t.Helper()
m.AssertLogfCalled(t)
if m.logfMsg != expected {
t.Errorf(
"expected Logf to be called with %q but it was called with %q",
expected,
m.logfMsg,
)
}
}