Skip to content

Commit 9cc0509

Browse files
authored
Merge pull request #323 from smocker-dev/fix/flaky-proxy-tests
test: replace flaky httpbin.org with a local go-httpbin for proxy tests
2 parents 7c4457c + 54b281b commit 9cc0509

6 files changed

Lines changed: 42 additions & 29 deletions

File tree

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ VENOM=$(GOPATH)/bin/venom
4444
$(VENOM):
4545
go install github.com/ovh/venom/cmd/venom@$(VENOMVERSION)
4646

47+
# Local proxy target for the integration tests: a self-hosted httpbin (go-httpbin) so the
48+
# proxy mocks don't depend on the flaky public httpbin.org.
49+
GOHTTPBINVERSION:=v2.18.3
50+
GOHTTPBIN=$(GOPATH)/bin/go-httpbin
51+
$(GOHTTPBIN):
52+
go install github.com/mccutchen/go-httpbin/v2/cmd/go-httpbin@$(GOHTTPBINVERSION)
53+
4754
GOCOVMERGE=$(GOPATH)/bin/gocovmerge
4855
$(GOCOVMERGE):
4956
go install github.com/wadey/gocovmerge@latest
@@ -90,14 +97,19 @@ test:
9097
go test -v -race -coverprofile=$(COVERAGE_DIR)/test-cover.out ./server/...
9198

9299
PID_FILE=/tmp/$(APPNAME).test.pid
100+
HTTPBIN_PID_FILE=/tmp/$(APPNAME).httpbin.pid
101+
PROXY_TARGET_PORT ?= 8090
93102
.PHONY: test-integration
94-
test-integration: $(VENOM) check-default-ports persistence
103+
test-integration: $(VENOM) $(GOHTTPBIN) check-default-ports persistence
95104
mkdir -p $(COVERAGE_DIR)
96105
go test -race -coverpkg="./..." -c . -o $(BUILD_DIR)/$(APPNAME).test
106+
$(GOHTTPBIN) -port $(PROXY_TARGET_PORT) >/dev/null 2>&1 & echo $$! > $(HTTPBIN_PID_FILE)
97107
SMOCKER_PERSISTENCE_DIRECTORY=./$(SESSIONS_DIR) $(BUILD_DIR)/$(APPNAME).test -test.coverprofile=$(COVERAGE_DIR)/test-integration-cover.out >/dev/null 2>&1 & echo $$! > $(PID_FILE)
98108
sleep 5
99-
$(VENOM) run tests/features/$(SUITE)
100-
kill `cat $(PID_FILE)` 2> /dev/null || true
109+
@ret=0; $(VENOM) run tests/features/$(SUITE) || ret=$$?; \
110+
kill `cat $(PID_FILE)` 2>/dev/null || true; \
111+
kill `cat $(HTTPBIN_PID_FILE)` 2>/dev/null || true; \
112+
exit $$ret
101113

102114
.PHONY: start-integration
103115
start-integration: $(VENOM)

tests/data/proxy_mock_list.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@
1111
- request:
1212
path: /redirect-to
1313
proxy:
14-
host: https://httpbin.org
14+
host: http://localhost:8090
1515
- request:
1616
path: /redirect-to
1717
headers:
1818
X-Follow-Redirect: "true"
1919
proxy:
20-
host: https://httpbin.org
20+
host: http://localhost:8090
2121
follow_redirect: true
2222
- request:
2323
path: /get
2424
proxy:
25-
host: https://httpbin.org
25+
host: http://localhost:8090
2626
- request:
2727
path: /get
2828
headers:
2929
X-Keep-Host: "true"
3030
proxy:
31-
host: https://httpbin.org
31+
host: http://localhost:8090
3232
keep_host: true
3333
- request:
3434
path: /headers
3535
proxy:
36-
host: https://httpbin.org
36+
host: http://localhost:8090
3737
headers:
3838
custom: "foobar"
3939
multi:

tests/features/set_mocks.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ testcases:
165165
- result.bodyjson.__len__ ShouldEqual 9
166166
- result.bodyjson.bodyjson8.proxy.host ShouldEqual https://jsonplaceholder.typicode.com
167167
- result.bodyjson.bodyjson7.proxy.host ShouldEqual https://jsonplaceholder.typicode.com
168-
- result.bodyjson.bodyjson6.proxy.host ShouldEqual https://httpbin.org
169-
- result.bodyjson.bodyjson5.proxy.host ShouldEqual https://httpbin.org
170-
- result.bodyjson.bodyjson4.proxy.host ShouldEqual https://httpbin.org
171-
- result.bodyjson.bodyjson3.proxy.host ShouldEqual https://httpbin.org
172-
- result.bodyjson.bodyjson2.proxy.host ShouldEqual https://httpbin.org
168+
- result.bodyjson.bodyjson6.proxy.host ShouldEqual http://localhost:8090
169+
- result.bodyjson.bodyjson5.proxy.host ShouldEqual http://localhost:8090
170+
- result.bodyjson.bodyjson4.proxy.host ShouldEqual http://localhost:8090
171+
- result.bodyjson.bodyjson3.proxy.host ShouldEqual http://localhost:8090
172+
- result.bodyjson.bodyjson2.proxy.host ShouldEqual http://localhost:8090
173173
- result.bodyjson.bodyjson1.proxy.host ShouldEqual https://self-signed.badssl.com
174174
- result.bodyjson.bodyjson0.proxy.host ShouldEqual https://self-signed.badssl.com

tests/features/use_mocks.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,21 @@ testcases:
273273
# - result.headers.location ShouldEqual https://smocker.dev/
274274
# - type: http
275275
# method: GET
276-
# url: http://localhost:8080/redirect-to?url=https%3A%2F%2Fhttpbin.org%2Fget&status_code=302
276+
# url: http://localhost:8080/redirect-to?url=https%3A%2F%2Flocalhost:8090%2Fget&status_code=302
277277
# headers:
278278
# X-Follow-Redirect: "true"
279279
# User-Agent: "foobar"
280280
# no_follow_redirect: true
281281
# assertions:
282282
# - result.statuscode ShouldEqual 200
283-
# - result.bodyjson.url ShouldEqual https://httpbin.org/get
283+
# - result.bodyjson.url ShouldEqual https://localhost:8090/get
284284

285285
- type: http
286286
method: GET
287287
url: http://localhost:8080/get
288288
assertions:
289289
- result.statuscode ShouldEqual 200
290-
- result.bodyjson.headers.host ShouldEqual httpbin.org
290+
- result.bodyjson.headers.host.host0 ShouldEqual localhost:8090
291291

292292
- type: http
293293
method: GET
@@ -296,7 +296,7 @@ testcases:
296296
X-Keep-Host: "true"
297297
assertions:
298298
- result.statuscode ShouldEqual 200
299-
- result.bodyjson.headers.host ShouldEqual localhost
299+
- result.bodyjson.headers.host.host0 ShouldEqual localhost:8080
300300

301301
- type: http
302302
method: GET
@@ -306,8 +306,9 @@ testcases:
306306
CuStOm: ShouldBeOverwritten
307307
assertions:
308308
- result.statuscode ShouldEqual 200
309-
- result.bodyjson.headers.custom ShouldEqual foobar
310-
- result.bodyjson.headers.multi ShouldEqual foo,baz
309+
- result.bodyjson.headers.custom.custom0 ShouldEqual foobar
310+
- result.bodyjson.headers.multi.multi0 ShouldEqual foo
311+
- result.bodyjson.headers.multi.multi1 ShouldEqual baz
311312

312313
- type: http
313314
method: GET

tests/serialization/mock_proxy_mock_list.golden.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
}
5252
},
5353
"proxy": {
54-
"host": "https://httpbin.org",
54+
"host": "http://localhost:8090",
5555
"delay": {}
5656
}
5757
},
@@ -75,7 +75,7 @@
7575
}
7676
},
7777
"proxy": {
78-
"host": "https://httpbin.org",
78+
"host": "http://localhost:8090",
7979
"delay": {},
8080
"follow_redirect": true
8181
}
@@ -92,7 +92,7 @@
9292
}
9393
},
9494
"proxy": {
95-
"host": "https://httpbin.org",
95+
"host": "http://localhost:8090",
9696
"delay": {}
9797
}
9898
},
@@ -116,7 +116,7 @@
116116
}
117117
},
118118
"proxy": {
119-
"host": "https://httpbin.org",
119+
"host": "http://localhost:8090",
120120
"delay": {},
121121
"keep_host": true
122122
}
@@ -133,7 +133,7 @@
133133
}
134134
},
135135
"proxy": {
136-
"host": "https://httpbin.org",
136+
"host": "http://localhost:8090",
137137
"delay": {},
138138
"headers": {
139139
"custom": [

tests/serialization/mock_proxy_mock_list.golden.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
matcher: ShouldMatch
2929
value: .*
3030
proxy:
31-
host: https://httpbin.org
31+
host: http://localhost:8090
3232
- request:
3333
path:
3434
matcher: ShouldEqual
@@ -41,7 +41,7 @@
4141
- matcher: ShouldEqual
4242
value: "true"
4343
proxy:
44-
host: https://httpbin.org
44+
host: http://localhost:8090
4545
follow_redirect: true
4646
- request:
4747
path:
@@ -51,7 +51,7 @@
5151
matcher: ShouldMatch
5252
value: .*
5353
proxy:
54-
host: https://httpbin.org
54+
host: http://localhost:8090
5555
- request:
5656
path:
5757
matcher: ShouldEqual
@@ -64,7 +64,7 @@
6464
- matcher: ShouldEqual
6565
value: "true"
6666
proxy:
67-
host: https://httpbin.org
67+
host: http://localhost:8090
6868
keep_host: true
6969
- request:
7070
path:
@@ -74,7 +74,7 @@
7474
matcher: ShouldMatch
7575
value: .*
7676
proxy:
77-
host: https://httpbin.org
77+
host: http://localhost:8090
7878
headers:
7979
custom:
8080
- foobar

0 commit comments

Comments
 (0)