@@ -50,7 +50,12 @@ protected void scaffold(CentralDogma client) {
50
50
client .push ("myPro" , "myRepo" , Revision .HEAD , "Initial files" ,
51
51
Change .ofJsonUpsert ("/foo.json" , "{ \" a\" : \" bar\" }" ),
52
52
Change .ofJsonUpsert ("/foo1.json" , "{ \" b\" : \" baz\" }" ),
53
- Change .ofJsonUpsert ("/foo2.json" , "{ \" a\" : \" new_bar\" }" )).join ();
53
+ Change .ofJsonUpsert ("/foo2.json" , "{ \" a\" : \" new_bar\" }" ),
54
+ Change .ofYamlUpsert ("/bar.yml" , "c:\n " +
55
+ " z: \" foo\" " ),
56
+ Change .ofYamlUpsert ("/bar1.yml" , "c:\n " +
57
+ " x: \" qux\" " ),
58
+ Change .ofYamlUpsert ("/bar2.yml" , "d: \" bar\" " )).join ();
54
59
}
55
60
56
61
@ Override
@@ -96,6 +101,56 @@ void mergeJsonFiles(ClientType clientType) {
96
101
.hasCauseInstanceOf (EntryNotFoundException .class );
97
102
}
98
103
104
+ @ ParameterizedTest
105
+ @ EnumSource (ClientType .class )
106
+ void mergeYamlFiles (ClientType clientType ) {
107
+ final CentralDogma client = clientType .client (dogma );
108
+ final MergedEntry <?> merged = client .mergeFiles ("myPro" , "myRepo" , Revision .HEAD ,
109
+ MergeSource .ofRequired ("/bar.yml" ),
110
+ MergeSource .ofRequired ("/bar1.yml" ),
111
+ MergeSource .ofRequired ("/bar2.yml" ),
112
+ MergeSource .ofOptional ("/bar3.yml" )).join ();
113
+
114
+ assertThat (merged .paths ()).containsExactly ("/bar.yml" , "/bar1.yml" , "/bar2.yml" );
115
+ assertThat (merged .revision ()).isEqualTo (new Revision (2 ));
116
+ assertThatJson (merged .content ()).isEqualTo ('{' +
117
+ " \" c\" : {" +
118
+ " \" z\" : \" foo\" ," +
119
+ " \" x\" : \" qux\" " +
120
+ " }," +
121
+ " \" d\" : \" bar\" " +
122
+ '}' );
123
+
124
+ /* TODO: Make it work. For now, ContentServiceV1 cannot differentiate
125
+ * MergeQuery.ofJson(which is MergeQuery<JsonNode>) and MergeQuery.ofYaml(which is also
126
+ * MergeQuery<JsonNode>), so merged entry type is always EntryType.JSON
127
+ assertThat(merged.type()).isEqualTo(EntryType.YAML);
128
+ */
129
+
130
+ // Check again to see if the original files are changed.
131
+ // Content is YAML but uses as JsonNode, so use assertThatJson
132
+ assertThatJson (client .getFile ("myPro" , "myRepo" , Revision .HEAD , Query .ofYaml ("/bar.yml" ))
133
+ .join ()
134
+ .content ())
135
+ .isEqualTo ("{ \" c\" : { \" z\" : \" foo\" } }" );
136
+ assertThatJson (client .getFile ("myPro" , "myRepo" , Revision .HEAD , Query .ofYaml ("/bar1.yml" ))
137
+ .join ()
138
+ .content ())
139
+ .isEqualTo ("{ \" c\" : { \" x\" : \" qux\" } }" );
140
+ assertThatJson (client .getFile ("myPro" , "myRepo" , Revision .HEAD , Query .ofYaml ("/bar2.yml" ))
141
+ .join ()
142
+ .content ())
143
+ .isEqualTo ("{ \" d\" : \" bar\" }" );
144
+
145
+ assertThatThrownBy (() -> client .mergeFiles ("myPro" , "myRepo" , Revision .HEAD ,
146
+ MergeSource .ofRequired ("/bar.yml" ),
147
+ MergeSource .ofRequired ("/bar1.yml" ),
148
+ MergeSource .ofRequired ("/bar2.yml" ),
149
+ MergeSource .ofRequired ("/bar3.yml" )).join ())
150
+ .isInstanceOf (CompletionException .class )
151
+ .hasCauseInstanceOf (EntryNotFoundException .class );
152
+ }
153
+
99
154
@ ParameterizedTest
100
155
@ EnumSource (ClientType .class )
101
156
void exceptionWhenOnlyOptionalFilesAndDoNotExist (ClientType clientType ) {
0 commit comments