Skip to content

Commit

Permalink
Add mergeJsonAndYamlFiles test to check merge JSON and YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
chacham committed Nov 9, 2021
1 parent 52e0b5e commit 33ae5ac
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions it/src/test/java/com/linecorp/centraldogma/it/MergeFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void scaffold(CentralDogma client) {
Change.ofJsonUpsert("/foo.json", "{ \"a\": \"bar\" }"),
Change.ofJsonUpsert("/foo1.json", "{ \"b\": \"baz\" }"),
Change.ofJsonUpsert("/foo2.json", "{ \"a\": \"new_bar\" }"),
Change.ofYamlUpsert("/bar0.yml", "c:\n" +
Change.ofYamlUpsert("/bar.yml", "c:\n" +
" z: \"foo\""),
Change.ofYamlUpsert("/bar1.yml", "c:\n" +
" x: \"qux\""),
Expand Down Expand Up @@ -106,12 +106,12 @@ void mergeJsonFiles(ClientType clientType) {
void mergeYamlFiles(ClientType clientType) {
final CentralDogma client = clientType.client(dogma);
final MergedEntry<?> merged = client.mergeFiles("myPro", "myRepo", Revision.HEAD,
MergeSource.ofRequired("/bar0.yml"),
MergeSource.ofRequired("/bar.yml"),
MergeSource.ofRequired("/bar1.yml"),
MergeSource.ofRequired("/bar2.yml"),
MergeSource.ofOptional("/bar3.yml")).join();

assertThat(merged.paths()).containsExactly("/bar0.yml", "/bar1.yml","/bar2.yml");
assertThat(merged.paths()).containsExactly("/bar.yml", "/bar1.yml","/bar2.yml");
assertThat(merged.revision()).isEqualTo(new Revision(2));
assertThatJson(merged.content()).isEqualTo('{' +
" \"c\": {" +
Expand All @@ -123,7 +123,7 @@ void mergeYamlFiles(ClientType clientType) {

// Check again to see if the original files are changed.
// Content is YAML but uses as JsonNode, so use assertThatJson
assertThatJson(client.getFile("myPro", "myRepo", Revision.HEAD, Query.ofYaml("/bar0.yml"))
assertThatJson(client.getFile("myPro", "myRepo", Revision.HEAD, Query.ofYaml("/bar.yml"))
.join()
.content())
.isEqualTo("{ \"c\": { \"z\": \"foo\" } }");
Expand All @@ -137,14 +137,50 @@ void mergeYamlFiles(ClientType clientType) {
.isEqualTo("{ \"d\": \"bar\" }");

assertThatThrownBy(() -> client.mergeFiles("myPro", "myRepo", Revision.HEAD,
MergeSource.ofRequired("/bar0.yml"),
MergeSource.ofRequired("/bar.yml"),
MergeSource.ofRequired("/bar1.yml"),
MergeSource.ofRequired("/bar2.yml"),
MergeSource.ofRequired("/bar3.yml")).join())
.isInstanceOf(CompletionException.class)
.hasCauseInstanceOf(EntryNotFoundException.class);
}

@ParameterizedTest
@EnumSource(ClientType.class)
void mergeJsonAndYamlFiles(ClientType clientType) {
final CentralDogma client = clientType.client(dogma);
final MergedEntry<?> merged = client.mergeFiles("myPro", "myRepo", Revision.HEAD,
MergeSource.ofRequired("/foo.json"),
MergeSource.ofRequired("/bar.yml"),
MergeSource.ofOptional("/baz.json")).join();

assertThat(merged.paths()).containsExactly("/foo.json", "/bar.yml");
assertThat(merged.revision()).isEqualTo(new Revision(2));
assertThatJson(merged.content()).isEqualTo('{' +
" \"a\": \"bar\"," +
" \"c\": {" +
" \"z\": \"foo\"" +
" }" +
'}');

// Check again to see if the original files are changed.
assertThatJson(client.getFile("myPro", "myRepo", Revision.HEAD, Query.ofJson("/foo.json"))
.join()
.content())
.isEqualTo("{ \"a\": \"bar\" }");
assertThatJson(client.getFile("myPro", "myRepo", Revision.HEAD, Query.ofYaml("/bar.yml"))
.join()
.content())
.isEqualTo("{ \"c\": { \"z\": \"foo\" } }");

assertThatThrownBy(() -> client.mergeFiles("myPro", "myRepo", Revision.HEAD,
MergeSource.ofRequired("/foo.json"),
MergeSource.ofRequired("/bar.yml"),
MergeSource.ofRequired("/baz.json")).join())
.isInstanceOf(CompletionException.class)
.hasCauseInstanceOf(EntryNotFoundException.class);
}

@ParameterizedTest
@EnumSource(ClientType.class)
void exceptionWhenOnlyOptionalFilesAndDoNotExist(ClientType clientType) {
Expand Down

0 comments on commit 33ae5ac

Please sign in to comment.