Skip to content

Commit f626ebc

Browse files
authored
Merge pull request #13 from senseyeio/smotes/v2.1-compatibility
smotes/v2.1 compatibility
2 parents 0e7cd30 + 3716b8c commit f626ebc

File tree

13 files changed

+962
-120
lines changed

13 files changed

+962
-120
lines changed

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ services:
66
language: go
77

88
go:
9-
- "1.10"
10-
- "1.11"
11-
- "1.12"
9+
- "1.13"
10+
- "1.14"
11+
- "1.15"
12+
- "1.16"
1213

1314
script: make unit && make integration
1415

1516
jobs:
1617
include:
1718
- stage: check
18-
install: go get golang.org/x/lint/golint github.com/kisielk/errcheck
19-
script: make lint && make errcheck
20-
go: "1.12" # only run source code analysis tools on latest version of Go
19+
install: go install golang.org/x/lint/golint@latest
20+
script: make lint
21+
go: "1.16" # only run source code analysis tools on latest version of Go

Makefile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
GOPACKAGES := $(shell go list ./...)
1+
PACKAGES := $(shell go list ./... | grep -v mock)
22

33
.PHONY: default
4-
default: fmt lint unit
5-
6-
.PHONY: errcheck
7-
errcheck:
8-
@errcheck -asserts -blank -ignore 'io:[cC]lose' $(GOPACKAGES)
4+
default: fmt lint
95

106
.PHONY: fmt
7+
## fmt: runs go fmt on source files
118
fmt:
129
@go fmt $(PACKAGES)
1310

11+
.PHONY: help
12+
## help: prints this help message
13+
help:
14+
@echo "Usage: \n"
15+
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
16+
1417
.PHONY: integration
18+
## integration: runs the integration tests
1519
integration:
16-
@sh ./scripts/integration_test.sh $(GOPACKAGES)
20+
@go clean -testcache
21+
@sh ./scripts/integration_test.sh $(PACKAGES)
1722

1823
.PHONY: lint
24+
## lint: runs go lint on source files
1925
lint:
20-
@golint -set_exit_status $(GOPACKAGES)
26+
@golint -set_exit_status -min_confidence=0.3 $(PACKAGES)
2127

2228
.PHONY: unit
29+
## unit: runs the unit tests
2330
unit:
24-
@go test -cover -timeout=1s $(GOPACKAGES)
31+
@go clean -testcache
32+
@go test -cover -covermode=atomic -race -timeout=1s $(PACKAGES)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $ make integration
2121

2222
The integration tests expect Docker to be available on the host, using it to run a local mountebank container at
2323
`localhost:2525`, with the additional ports 8080-8081 exposed for test imposters. Currently tested against a mountebank
24-
v2.0.0 instance using the [andyrbell/mountebank](https://hub.docker.com/r/andyrbell/mountebank) image on DockerHub.
24+
v2.1.2 instance using the [andyrbell/mountebank](https://hub.docker.com/r/andyrbell/mountebank) image on DockerHub.
2525

2626
## Contributing
2727

client.go

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,141 @@ func (cli *Client) Imposter(ctx context.Context, port int, replay bool) (*Impost
129129
return &imp, nil
130130
}
131131

132+
// AddStub adds a new Stub without restarting its Imposter given the imposter's
133+
// port and the new stub's index, or simply to the end of the array if index < 0.
134+
//
135+
// See more information about this resource at:
136+
// http://www.mbtest.org/docs/api/overview#add-stub
137+
func (cli *Client) AddStub(ctx context.Context, port, index int, stub Stub) (*Imposter, error) {
138+
p := fmt.Sprintf("/imposters/%d/stubs", port)
139+
140+
dto := map[string]interface{}{"stub": stub}
141+
if index >= 0 {
142+
dto["index"] = index
143+
}
144+
b, err := json.Marshal(dto)
145+
if err != nil {
146+
return nil, err
147+
}
148+
149+
req, err := cli.restCli.NewRequest(ctx, http.MethodPost, p, bytes.NewReader(b), nil)
150+
if err != nil {
151+
return nil, err
152+
}
153+
154+
resp, err := cli.restCli.Do(req)
155+
if err != nil {
156+
return nil, err
157+
}
158+
159+
var imp Imposter
160+
if resp.StatusCode == http.StatusOK {
161+
if err := cli.restCli.DecodeResponseBody(resp.Body, &imp); err != nil {
162+
return nil, err
163+
}
164+
} else {
165+
return nil, cli.decodeError(resp.Body)
166+
}
167+
return &imp, nil
168+
}
169+
170+
// OverwriteStub overwrites an existing Stub without restarting its Imposter,
171+
// where the stub index denotes the stub to be changed.
172+
//
173+
// See more information about this resouce at:
174+
// http://www.mbtest.org/docs/api/overview#change-stub
175+
func (cli *Client) OverwriteStub(ctx context.Context, port, index int, stub Stub) (*Imposter, error) {
176+
p := fmt.Sprintf("/imposters/%d/stubs/%d", port, index)
177+
178+
b, err := json.Marshal(stub)
179+
if err != nil {
180+
return nil, err
181+
}
182+
183+
req, err := cli.restCli.NewRequest(ctx, http.MethodPut, p, bytes.NewReader(b), nil)
184+
if err != nil {
185+
return nil, err
186+
}
187+
188+
resp, err := cli.restCli.Do(req)
189+
if err != nil {
190+
return nil, err
191+
}
192+
193+
var imp Imposter
194+
if resp.StatusCode == http.StatusOK {
195+
if err := cli.restCli.DecodeResponseBody(resp.Body, &imp); err != nil {
196+
return nil, err
197+
}
198+
} else {
199+
return nil, cli.decodeError(resp.Body)
200+
}
201+
return &imp, nil
202+
}
203+
204+
// OverwriteAllStubs overwrites all existing Stubs without restarting their Imposter.
205+
//
206+
// See more information about this resource at:
207+
// http://www.mbtest.org/docs/api/overview#change-stubs
208+
func (cli *Client) OverwriteAllStubs(ctx context.Context, port int, stubs []Stub) (*Imposter, error) {
209+
p := fmt.Sprintf("/imposters/%d/stubs", port)
210+
211+
b, err := json.Marshal(map[string]interface{}{
212+
"stubs": stubs,
213+
})
214+
if err != nil {
215+
return nil, err
216+
}
217+
218+
req, err := cli.restCli.NewRequest(ctx, http.MethodPut, p, bytes.NewReader(b), nil)
219+
if err != nil {
220+
return nil, err
221+
}
222+
223+
resp, err := cli.restCli.Do(req)
224+
if err != nil {
225+
return nil, err
226+
}
227+
228+
var imp Imposter
229+
if resp.StatusCode == http.StatusOK {
230+
if err := cli.restCli.DecodeResponseBody(resp.Body, &imp); err != nil {
231+
return nil, err
232+
}
233+
} else {
234+
return nil, cli.decodeError(resp.Body)
235+
}
236+
return &imp, nil
237+
}
238+
239+
// RemoveStub removes a Stub without restarting its Imposter.
240+
//
241+
// See more information about this resource at:
242+
// http://www.mbtest.org/docs/api/overview#delete-stub
243+
func (cli *Client) RemoveStub(ctx context.Context, port, index int) (*Imposter, error) {
244+
p := fmt.Sprintf("/imposters/%d/stubs/%d", port, index)
245+
246+
req, err := cli.restCli.NewRequest(ctx, http.MethodDelete, p, http.NoBody, nil)
247+
if err != nil {
248+
return nil, err
249+
}
250+
251+
resp, err := cli.restCli.Do(req)
252+
if err != nil {
253+
return nil, err
254+
}
255+
256+
var imp Imposter
257+
if resp.StatusCode == http.StatusOK {
258+
if err := cli.restCli.DecodeResponseBody(resp.Body, &imp); err != nil {
259+
return nil, err
260+
}
261+
} else {
262+
return nil, cli.decodeError(resp.Body)
263+
}
264+
return &imp, nil
265+
}
266+
132267
// Delete removes an Imposter configured on the given port and returns
133268
// the deleted Imposter data, or an empty Imposter struct if one does not
134269
// exist on the port.
@@ -169,7 +304,7 @@ func (cli *Client) Delete(ctx context.Context, port int, replay bool) (*Imposter
169304
// See more information about this resource at:
170305
// http://www.mbtest.org/docs/api/overview#delete-imposter-requests.
171306
func (cli *Client) DeleteRequests(ctx context.Context, port int) (*Imposter, error) {
172-
p := fmt.Sprintf("/imposters/%d/requests", port)
307+
p := fmt.Sprintf("/imposters/%d/savedProxyResponses", port)
173308

174309
req, err := cli.restCli.NewRequest(ctx, http.MethodDelete, p, nil, nil)
175310
if err != nil {

0 commit comments

Comments
 (0)