-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
100 lines (86 loc) · 2.65 KB
/
options.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
package mock_server_client
import "time"
type RequestOption func(*request)
// WithPathParameter sets required request path parameter that has to be checked on mock
// server app to return corresponding response.
func WithPathParameter(key, value string) RequestOption {
return func(r *request) {
if r.pathParams == nil {
r.pathParams = map[string]string{}
}
r.pathParams[key] = value
}
}
// WithQueryParameter sets required query parameter that has to be checked on mock
// server app to return corresponding response.
func WithQueryParameter(key, value string) RequestOption {
return func(r *request) {
if r.queryParams == nil {
r.queryParams = map[string]string{}
}
r.queryParams[key] = value
}
}
// WithRequestHeader sets required header parameter that has to be checked on mock
// server app to return corresponding response.
func WithRequestHeader(key, value string) RequestOption {
return func(r *request) {
if r.headers == nil {
r.headers = map[string]string{}
}
r.headers[key] = value
}
}
// WithRequestBody sets required body that has to be checked on mock
// server app to return corresponding response.
func WithRequestBody(body interface{}) RequestOption {
return func(r *request) {
r.body = body
}
}
type ResponseOption func(*response)
// WithResponseHeader sets response header to be returned within corresponding HTTP response from mock server app.
func WithResponseHeader(key, value string) ResponseOption {
return func(r *response) {
if r.headers == nil {
r.headers = map[string]string{}
}
r.headers[key] = value
}
}
// WithResponseBody sets response body to be returned within corresponding HTTP response from mock server app.
func WithResponseBody(body interface{}) ResponseOption {
return func(r *response) {
r.body = body
}
}
// WithStatusCode sets HTTP status code to be returned within corresponding HTTP response from mock server app.
func WithStatusCode(s int) ResponseOption {
return func(r *response) {
r.statusCode = s
}
}
// WithDelay sets HTTP response delay for mock server app.
func WithDelay(s time.Duration) ResponseOption {
return func(r *response) {
r.delay = &s
}
}
// WithReason sets HTTP failure reason for mock server app.
func WithReason(s string) ResponseOption {
return func(r *response) {
r.reasonPhrase = s
}
}
// WithDropConnection sets true to brake HTTP connection from mock server app side for particular response.
func WithDropConnection() ResponseOption {
return func(r *response) {
r.drop = true
}
}
// WithErrorBytes sets error bytes within dropped connection on mock server side.
func WithErrorBytes(b []byte) ResponseOption {
return func(r *response) {
r.errorBytes = b
}
}