-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocks.go
176 lines (163 loc) · 4.2 KB
/
mocks.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package aeolic
import (
"io"
"net/http"
"sync"
)
// Ensure, that httpClientMock does implement httpClient.
// If this is not the case, regenerate this file with moq.
var _ httpClient = &httpClientMock{}
// httpClientMock is a mock implementation of httpClient.
//
// func TestSomethingThatUseshttpClient(t *testing.T) {
//
// // make and configure a mocked httpClient
// mockedhttpClient := &httpClientMock{
// DoFunc: func(req *http.Request) (*http.Response, error) {
// panic("mock out the Do method")
// },
// GetFunc: func(url string) (*http.Response, error) {
// panic("mock out the Get method")
// },
// PostFunc: func(url string, contentType string, body io.Reader) (*http.Response, error) {
// panic("mock out the Post method")
// },
// }
//
// // use mockedhttpClient in code that requires httpClient
// // and then make assertions.
//
// }
type httpClientMock struct {
// DoFunc mocks the Do method.
DoFunc func(req *http.Request) (*http.Response, error)
// GetFunc mocks the Get method.
GetFunc func(url string) (*http.Response, error)
// PostFunc mocks the Post method.
PostFunc func(url string, contentType string, body io.Reader) (*http.Response, error)
// calls tracks calls to the methods.
calls struct {
// Do holds details about calls to the Do method.
Do []struct {
// Req is the req argument value.
Req *http.Request
}
// Get holds details about calls to the Get method.
Get []struct {
// URL is the url argument value.
URL string
}
// Post holds details about calls to the Post method.
Post []struct {
// URL is the url argument value.
URL string
// ContentType is the contentType argument value.
ContentType string
// Body is the body argument value.
Body io.Reader
}
}
lockDo sync.RWMutex
lockGet sync.RWMutex
lockPost sync.RWMutex
}
// Do calls DoFunc.
func (mock *httpClientMock) Do(req *http.Request) (*http.Response, error) {
if mock.DoFunc == nil {
panic("httpClientMock.DoFunc: method is nil but httpClient.Do was just called")
}
callInfo := struct {
Req *http.Request
}{
Req: req,
}
mock.lockDo.Lock()
mock.calls.Do = append(mock.calls.Do, callInfo)
mock.lockDo.Unlock()
return mock.DoFunc(req)
}
// DoCalls gets all the calls that were made to Do.
// Check the length with:
//
// len(mockedhttpClient.DoCalls())
func (mock *httpClientMock) DoCalls() []struct {
Req *http.Request
} {
var calls []struct {
Req *http.Request
}
mock.lockDo.RLock()
calls = mock.calls.Do
mock.lockDo.RUnlock()
return calls
}
// Get calls GetFunc.
func (mock *httpClientMock) Get(url string) (*http.Response, error) {
if mock.GetFunc == nil {
panic("httpClientMock.GetFunc: method is nil but httpClient.Get was just called")
}
callInfo := struct {
URL string
}{
URL: url,
}
mock.lockGet.Lock()
mock.calls.Get = append(mock.calls.Get, callInfo)
mock.lockGet.Unlock()
return mock.GetFunc(url)
}
// GetCalls gets all the calls that were made to Get.
// Check the length with:
//
// len(mockedhttpClient.GetCalls())
func (mock *httpClientMock) GetCalls() []struct {
URL string
} {
var calls []struct {
URL string
}
mock.lockGet.RLock()
calls = mock.calls.Get
mock.lockGet.RUnlock()
return calls
}
// Post calls PostFunc.
func (mock *httpClientMock) Post(url string, contentType string, body io.Reader) (*http.Response, error) {
if mock.PostFunc == nil {
panic("httpClientMock.PostFunc: method is nil but httpClient.Post was just called")
}
callInfo := struct {
URL string
ContentType string
Body io.Reader
}{
URL: url,
ContentType: contentType,
Body: body,
}
mock.lockPost.Lock()
mock.calls.Post = append(mock.calls.Post, callInfo)
mock.lockPost.Unlock()
return mock.PostFunc(url, contentType, body)
}
// PostCalls gets all the calls that were made to Post.
// Check the length with:
//
// len(mockedhttpClient.PostCalls())
func (mock *httpClientMock) PostCalls() []struct {
URL string
ContentType string
Body io.Reader
} {
var calls []struct {
URL string
ContentType string
Body io.Reader
}
mock.lockPost.RLock()
calls = mock.calls.Post
mock.lockPost.RUnlock()
return calls
}