This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_mock.go
128 lines (118 loc) · 3.24 KB
/
client_mock.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package rpcx
import (
"context"
"sync"
)
// Ensure, that ClientMock does implement Client.
// If this is not the case, regenerate this file with moq.
var _ Client = &ClientMock{}
// ClientMock is a mock implementation of Client.
//
// func TestSomethingThatUsesClient(t *testing.T) {
//
// // make and configure a mocked Client
// mockedClient := &ClientMock{
// CallFunc: func(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error {
// panic("mock out the Call method")
// },
// CloseFunc: func() error {
// panic("mock out the Close method")
// },
// }
//
// // use mockedClient in code that requires Client
// // and then make assertions.
//
// }
type ClientMock struct {
// CallFunc mocks the Call method.
CallFunc func(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error
// CloseFunc mocks the Close method.
CloseFunc func() error
// calls tracks calls to the methods.
calls struct {
// Call holds details about calls to the Call method.
Call []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// ServiceMethod is the serviceMethod argument value.
ServiceMethod string
// Args is the args argument value.
Args interface{}
// Reply is the reply argument value.
Reply interface{}
}
// Close holds details about calls to the Close method.
Close []struct {
}
}
lockCall sync.RWMutex
lockClose sync.RWMutex
}
// Call calls CallFunc.
func (mock *ClientMock) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error {
if mock.CallFunc == nil {
panic("ClientMock.CallFunc: method is nil but Client.Call was just called")
}
callInfo := struct {
Ctx context.Context
ServiceMethod string
Args interface{}
Reply interface{}
}{
Ctx: ctx,
ServiceMethod: serviceMethod,
Args: args,
Reply: reply,
}
mock.lockCall.Lock()
mock.calls.Call = append(mock.calls.Call, callInfo)
mock.lockCall.Unlock()
return mock.CallFunc(ctx, serviceMethod, args, reply)
}
// CallCalls gets all the calls that were made to Call.
// Check the length with:
// len(mockedClient.CallCalls())
func (mock *ClientMock) CallCalls() []struct {
Ctx context.Context
ServiceMethod string
Args interface{}
Reply interface{}
} {
var calls []struct {
Ctx context.Context
ServiceMethod string
Args interface{}
Reply interface{}
}
mock.lockCall.RLock()
calls = mock.calls.Call
mock.lockCall.RUnlock()
return calls
}
// Close calls CloseFunc.
func (mock *ClientMock) Close() error {
if mock.CloseFunc == nil {
panic("ClientMock.CloseFunc: method is nil but Client.Close was just called")
}
callInfo := struct {
}{}
mock.lockClose.Lock()
mock.calls.Close = append(mock.calls.Close, callInfo)
mock.lockClose.Unlock()
return mock.CloseFunc()
}
// CloseCalls gets all the calls that were made to Close.
// Check the length with:
// len(mockedClient.CloseCalls())
func (mock *ClientMock) CloseCalls() []struct {
} {
var calls []struct {
}
mock.lockClose.RLock()
calls = mock.calls.Close
mock.lockClose.RUnlock()
return calls
}