Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
  • Loading branch information
Kavindu-Dodan committed Jan 5, 2024
1 parent 71a36b4 commit 78758a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,12 @@ void emitErrorStateForInvalidPath() throws IOException {

@Test
void watchForFileUpdatesAndEmitThem() throws IOException {
final String initial = "{\n" +
" \"flags\": {\n" +
" \"myBoolFlag\": {\n" +
" \"state\": \"ENABLED\",\n" +
" \"variants\": {\n" +
" \"on\": true,\n" +
" \"off\": false\n" +
" },\n" +
" \"defaultVariant\": \"on\"\n" +
" }\n" +
" }\n" +
"}";
final String updatedFlags = "{\n" +
" \"flags\": {\n" +
" \"myBoolFlag\": {\n" +
" \"state\": \"ENABLED\",\n" +
" \"variants\": {\n" +
" \"on\": true,\n" +
" \"off\": false\n" +
" },\n" +
" \"defaultVariant\": \"off\"\n" +
" }\n" +
" }\n" +
"}";
final String initial = "{\"flags\":{\"myBoolFlag\":{\"state\":\"ENABLED\",\"variants\":{\"on\":true,\"off\":false},\"defaultVariant\":\"on\"}}}";
final String updatedFlags = "{\"flags\":{\"myBoolFlag\":{\"state\":\"ENABLED\",\"variants\":{\"on\":true,\"off\":false},\"defaultVariant\":\"off\"}}}";

// given
final Path updPath = Paths.get(getResourcePath(UPDATABLE_FILE));
Files.write(updPath, initial.getBytes(), StandardOpenOption.WRITE);
Files.write(updPath, initial.getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

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

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

// then update the flags
Files.write(updPath, updatedFlags.getBytes(), StandardOpenOption.WRITE);
Files.write(updPath, updatedFlags.getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

// finally wait for updated payload
assertTimeoutPreemptively(Duration.ofSeconds(10), () -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"flags": {
"myBoolFlag": {
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "on"
}
}
}

0 comments on commit 78758a2

Please sign in to comment.