-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplica_test.go
62 lines (45 loc) · 1.26 KB
/
replica_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
package replica
import "testing"
func before() {
Mocks.Clear()
}
func MockedFunction(a string) (int, []interface{}) {
c, r := MockFn(a)
return c, r
}
func TestFunctionCallDataAdd(t *testing.T) {
before()
_, _ = MockedFunction("test")
// Check that the parameters were added
if len(Mocks.GetCallParams("MockedFunction")[0]) != 1 {
t.Error("Expected 1 parameter, got", len(Mocks.GetCallParams("MockedFunction")[0]))
}
}
func TestMockFnCallCountUpdate(t *testing.T) {
before()
_, _ = MockedFunction("test")
_, _ = MockedFunction("test")
count, _ := MockedFunction("test")
// Check that the call count is correct
if Mocks.GetCallCount("MockedFunction") != 3 {
t.Error("Expected 3 calls, got", Mocks.GetCallCount("MockedFunction"))
}
// Check that the return value is correct
if count != 3 {
t.Error("Expected 3 calls, got", count)
}
}
func TestMockFnMockReturn(t *testing.T) {
before()
_, r := MockedFunction("test")
// Test that first run returns nothing
if len(r) != 0 {
t.Error("Expected 0 return values, got", len(r))
}
// Check that the return value updates to match the mocked one
Mocks.SetReturnValues("MockedFunction", "mocked")
_, r = MockedFunction("test")
if r[0].(string) != "mocked" {
t.Error("Expected 'mocked', got", r[0])
}
}