Skip to content

Commit b9b0bc2

Browse files
authored
fix: dynamic file name for file loading and bug on timestamp detected as dot notation (#123)
1 parent 61e3954 commit b9b0bc2

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

tzatziki-core/src/main/java/com/decathlon/tzatziki/steps/ObjectSteps.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public class ObjectSteps {
172172
value = Time.parse(property.substring(1));
173173
} else if (property.startsWith("&")) {
174174
// this is a file to load
175-
value = load(property.substring(1));
175+
value = load(getOrSelf(property.substring(1)));
176176
} else {
177177
// let's get the value in the context, or fallback on the name of the property
178178
value = getOrSelf(property);
@@ -428,7 +428,7 @@ public void output_in(Guard guard, String sourcePath, Type type, Object sourceVa
428428
throw new RuntimeException(e);
429429
}
430430
try {
431-
Path path = Paths.get(resourcePath.toString(), sourcePath).normalize();
431+
Path path = Paths.get(resourcePath.toString(), resolve(sourcePath)).normalize();
432432
if (!Paths.get(path.toString()).normalize().startsWith(resourcePath)) {
433433
throw new AssertionError("no escape from the resource folder is allowed!");
434434
}

tzatziki-core/src/test/resources/com/decathlon/tzatziki/steps/objects.feature

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,16 @@ Feature: to interact with objects in the context
250250
| test2 | value2 |
251251

252252
Scenario Template: we can write to and read from files
253-
Given that we output in "<path>":
253+
Given that dateAppendedFilePath is:
254+
"""
255+
<path>-{{{[@now as a formatted date YYYY-MM-dd'T'HH_mm_ss]}}}
256+
"""
257+
Given that we output in "{{{dateAppendedFilePath}}}":
254258
"""yml
255259
id: 1
256260
name: bob
257261
"""
258-
When bob is "{{{[&<path>]}}}"
262+
When bob is "{{{[&dateAppendedFilePath]}}}"
259263
Then bob is equal to:
260264
"""yml
261265
id: 1
@@ -931,14 +935,15 @@ Feature: to interact with objects in the context
931935
message: another message
932936
"""
933937

934-
Scenario: dot notation should not take dot from timestamp into account
938+
Scenario: dot notation should only take dot notation for keys (even if the value contains dots and colons)
935939
Given that object is:
936940
"""
937-
timestamp: '2021-08-01T12:30:00.000+02:00'
941+
current_time.timestamp: '2021-08-01T12:30:00.000+02:00'
938942
"""
939943
Then object is equal to:
940944
"""
941-
timestamp: '2021-08-01T10:30:00Z'
945+
current_time:
946+
timestamp: '2021-08-01T10:30:00Z'
942947
"""
943948

944949
Scenario: contains should work even if an expected with a map is matched against a non-map (empty string for eg.)

tzatziki-mapper/src/main/java/com/decathlon/tzatziki/utils/Mapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static String dotNotationToYamlObject(String content) {
6868
for (int idx = 0; idx < lines.size(); idx++) {
6969
String line;
7070
String matchOnlyIfNonRegexFlag = "(?![ \"']*\\?e)";
71-
String captureDotNotation = "^(?>([ \\-]*))" + matchOnlyIfNonRegexFlag + "([^.:]+)\\.([\\S ]+:" + matchOnlyIfNonRegexFlag + "[^\\n]*)\\n?";
71+
String captureDotNotation = "(?>([ \\-]*))" + matchOnlyIfNonRegexFlag + "([^.:]+)\\.((?>[^:]+)(?<!\\d{4}-\\d{2}-\\d{2}T\\d{2}):" + matchOnlyIfNonRegexFlag + ".*)";
7272
while ((line = lines.get(idx)).matches(captureDotNotation)) {
7373
String rootObjectIndent = line.replaceAll(captureDotNotation, "$1").replace("-", " ");
7474
String subObjectIndent = " " + rootObjectIndent;

0 commit comments

Comments
 (0)