Skip to content

Commit 0bf22fc

Browse files
authored
fix: can now assert count number with path containing regex which doesn't match the initial mocks (#147)
1 parent 44e12c8 commit 0bf22fc

File tree

2 files changed

+23
-3
lines changed
  • mockfaster/src/main/java/com/decathlon/tzatziki/utils
  • tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps

2 files changed

+23
-3
lines changed

mockfaster/src/main/java/com/decathlon/tzatziki/utils/MockFaster.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ public static synchronized void add_mock(HttpRequest httpRequest, ExpectationRes
115115
});
116116
}
117117

118+
String pattern;
118119
if (httpRequest.getPath() instanceof NottableSchemaString uriSchema) {
119-
PATH_PATTERNS.add(Pattern.compile(((ObjectNode) getValue(uriSchema, "schemaJsonNode")).get("pattern").textValue()));
120+
pattern = ((ObjectNode) getValue(uriSchema, "schemaJsonNode")).get("pattern").textValue();
120121
} else {
121-
PATH_PATTERNS.add(Pattern.compile(httpRequest.getPath().getValue()));
122+
pattern = httpRequest.getPath().getValue();
122123
}
124+
PATH_PATTERNS.add(Pattern.compile(pattern.replaceAll("\\([^()]*\\)","(.*)")));
123125
}
124126

125127
private static void modifyJsonStrictnessMatcher(List<HttpRequestMatcher> httpRequestMatchers, Comparison comparison) {

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,4 +1358,22 @@ Feature: to interact with an http service and setup mocks
13581358
| {"headers":{"my-header":"a bad value"},"body":{"payload":{"my-body":{"field":"a good value"}}}} |
13591359
| {"headers":{"my-header":"a bad value"}} |
13601360
| {"headers":{"my-header":"a good value"},"body":{"payload":{"my-body":{"field":"a bad value"}}}} |
1361-
| {"body":{"payload":{"my-body":{"field":"a bad value"}}}} |
1361+
| {"body":{"payload":{"my-body":{"field":"a bad value"}}}} |
1362+
1363+
Scenario: Requests count assertion should also work for digit
1364+
And that getting on "http://backend/pipe/([a-z]*)/([0-9]*)/(\d+)" will return a status OK_200 and:
1365+
"""
1366+
$1|$2|$3
1367+
"""
1368+
When we get on "http://backend/pipe/a/1/2"
1369+
Then we received a status OK_200 and:
1370+
"""
1371+
a|1|2
1372+
"""
1373+
When we get on "http://backend/pipe/c/3/4"
1374+
Then we received a status OK_200 and:
1375+
"""
1376+
c|3|4
1377+
"""
1378+
And "http://backend/pipe/[a-b]*/1/\d+" has received 1 GET
1379+
And "http://backend/pipe/.*/\d*/\d+" has received 2 GETs

0 commit comments

Comments
 (0)