-
Notifications
You must be signed in to change notification settings - Fork 107
/
store_test.go
87 lines (73 loc) · 1.65 KB
/
store_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
package gock
import (
"testing"
"github.com/nbio/st"
)
func TestStoreRegister(t *testing.T) {
defer after()
st.Expect(t, len(mocks), 0)
mock := New("foo").Mock
Register(mock)
st.Expect(t, len(mocks), 1)
st.Expect(t, mock.Request().Mock, mock)
st.Expect(t, mock.Response().Mock, mock)
}
func TestStoreGetAll(t *testing.T) {
defer after()
st.Expect(t, len(mocks), 0)
mock := New("foo").Mock
store := GetAll()
st.Expect(t, len(mocks), 1)
st.Expect(t, len(store), 1)
st.Expect(t, store[0], mock)
}
func TestStoreExists(t *testing.T) {
defer after()
st.Expect(t, len(mocks), 0)
mock := New("foo").Mock
st.Expect(t, len(mocks), 1)
st.Expect(t, Exists(mock), true)
}
func TestStorePending(t *testing.T) {
defer after()
New("foo")
st.Expect(t, mocks, Pending())
}
func TestStoreIsPending(t *testing.T) {
defer after()
New("foo")
st.Expect(t, IsPending(), true)
Flush()
st.Expect(t, IsPending(), false)
}
func TestStoreIsDone(t *testing.T) {
defer after()
New("foo")
st.Expect(t, IsDone(), false)
Flush()
st.Expect(t, IsDone(), true)
}
func TestStoreRemove(t *testing.T) {
defer after()
st.Expect(t, len(mocks), 0)
mock := New("foo").Mock
st.Expect(t, len(mocks), 1)
st.Expect(t, Exists(mock), true)
Remove(mock)
st.Expect(t, Exists(mock), false)
Remove(mock)
st.Expect(t, Exists(mock), false)
}
func TestStoreFlush(t *testing.T) {
defer after()
st.Expect(t, len(mocks), 0)
mock1 := New("foo").Mock
mock2 := New("foo").Mock
st.Expect(t, len(mocks), 2)
st.Expect(t, Exists(mock1), true)
st.Expect(t, Exists(mock2), true)
Flush()
st.Expect(t, len(mocks), 0)
st.Expect(t, Exists(mock1), false)
st.Expect(t, Exists(mock2), false)
}