Skip to content

Commit b4d2e87

Browse files
authored
fix: consider NOT_FOUND after reset callbacks as unhandled request (#124)
1 parent b9b0bc2 commit b4d2e87

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

tzatziki-http/src/main/java/com/decathlon/tzatziki/steps/HttpSteps.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,15 @@ public void mockserver_has_not_been_called_on(Guard guard, String path) {
468468
public void after() {
469469
if (doNotAllowUnhandledRequests) {
470470
List<LogEventRequestAndResponse> requestAndResponses = retrieveRequestResponses(request());
471+
String notFoundMessageRegex = "Not Found(?: Again!)?";
471472
Set<HttpRequest> unhandledRequests = requestAndResponses
472473
.stream()
473-
.filter(requestAndResponse -> "Not Found".equals(requestAndResponse.getHttpResponse().getReasonPhrase()))
474+
.filter(requestAndResponse -> Optional.ofNullable(requestAndResponse.getHttpResponse().getReasonPhrase()).orElse("").matches(notFoundMessageRegex))
474475
.map(requestAndResponse -> (HttpRequest) requestAndResponse.getHttpRequest())
475476
.collect(Collectors.toSet());
476477
// we make a second pass, the calls might have been handled later on
477478
requestAndResponses.stream()
478-
.filter(requestAndResponse -> !"Not Found".equals(requestAndResponse.getHttpResponse().getReasonPhrase()))
479+
.filter(requestAndResponse -> !Optional.ofNullable(requestAndResponse.getHttpResponse().getReasonPhrase()).orElse("").matches(notFoundMessageRegex))
479480
.forEach(requestAndResponse -> unhandledRequests.remove((HttpRequest) requestAndResponse.getHttpRequest()));
480481
withFailMessage(() -> assertThat(unhandledRequests).isEmpty(), () -> "unhandled requests: %s".formatted(unhandledRequests));
481482
}

tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,4 +1215,16 @@ Feature: to interact with an http service and setup mocks
12151215
Examples:
12161216
| mocksRange |
12171217
| 2-150 |
1218-
| 151-250 |
1218+
| 151-250 |
1219+
1220+
@ignore @run-manually
1221+
Scenario Template: Mocks from other tests should be considered as unhandled requests
1222+
* a root logger set to INFO
1223+
Given that if <idx> == 1 => getting on "http://backend/unhandled" will return a status OK_200
1224+
And that if <idx> == 2 => getting on "http://backend/justForHostnameMock" will return a status OK_200
1225+
Then we get on "http://backend/unhandled"
1226+
1227+
Examples:
1228+
| idx |
1229+
| 1 |
1230+
| 2 |

0 commit comments

Comments
 (0)