Skip to content

Commit 78758a2

Browse files
committed
improve test
Signed-off-by: Kavindu Dodanduwa <[email protected]>
1 parent 71a36b4 commit 78758a2

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

Diff for: providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/storage/connector/file/FileConnectorTest.java

+4-26
Original file line numberDiff line numberDiff line change
@@ -65,34 +65,12 @@ void emitErrorStateForInvalidPath() throws IOException {
6565

6666
@Test
6767
void watchForFileUpdatesAndEmitThem() throws IOException {
68-
final String initial = "{\n" +
69-
" \"flags\": {\n" +
70-
" \"myBoolFlag\": {\n" +
71-
" \"state\": \"ENABLED\",\n" +
72-
" \"variants\": {\n" +
73-
" \"on\": true,\n" +
74-
" \"off\": false\n" +
75-
" },\n" +
76-
" \"defaultVariant\": \"on\"\n" +
77-
" }\n" +
78-
" }\n" +
79-
"}";
80-
final String updatedFlags = "{\n" +
81-
" \"flags\": {\n" +
82-
" \"myBoolFlag\": {\n" +
83-
" \"state\": \"ENABLED\",\n" +
84-
" \"variants\": {\n" +
85-
" \"on\": true,\n" +
86-
" \"off\": false\n" +
87-
" },\n" +
88-
" \"defaultVariant\": \"off\"\n" +
89-
" }\n" +
90-
" }\n" +
91-
"}";
68+
final String initial = "{\"flags\":{\"myBoolFlag\":{\"state\":\"ENABLED\",\"variants\":{\"on\":true,\"off\":false},\"defaultVariant\":\"on\"}}}";
69+
final String updatedFlags = "{\"flags\":{\"myBoolFlag\":{\"state\":\"ENABLED\",\"variants\":{\"on\":true,\"off\":false},\"defaultVariant\":\"off\"}}}";
9270

9371
// given
9472
final Path updPath = Paths.get(getResourcePath(UPDATABLE_FILE));
95-
Files.write(updPath, initial.getBytes(), StandardOpenOption.WRITE);
73+
Files.write(updPath, initial.getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
9674

9775
final FileConnector connector = new FileConnector(updPath.toString());
9876

@@ -111,7 +89,7 @@ void watchForFileUpdatesAndEmitThem() throws IOException {
11189
assertEquals(initial, payload[0].getData());
11290

11391
// then update the flags
114-
Files.write(updPath, updatedFlags.getBytes(), StandardOpenOption.WRITE);
92+
Files.write(updPath, updatedFlags.getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
11593

11694
// finally wait for updated payload
11795
assertTimeoutPreemptively(Duration.ofSeconds(10), () -> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"flags": {
3+
"myBoolFlag": {
4+
"state": "ENABLED",
5+
"variants": {
6+
"on": true,
7+
"off": false
8+
},
9+
"defaultVariant": "on"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)