@@ -217,3 +217,103 @@ func TestCheckLagoonLabel(t *testing.T) {
217217 })
218218 }
219219}
220+
221+ func TestUnmarshalLagoonDockerComposeYAML (t * testing.T ) {
222+ type args struct {
223+ file string
224+ }
225+ tests := []struct {
226+ name string
227+ args args
228+ wantErrMsg string
229+ wantErr bool
230+ }{
231+ {
232+ name : "test1 docker-compose drupal example" ,
233+ args : args {
234+ file : "../../test-resources/docker-compose/test1/docker-compose.yml" ,
235+ },
236+ wantErr : true ,
237+ wantErrMsg : `line 59: mapping key "<<" already defined at line 58` ,
238+ },
239+ {
240+ name : "test2 docker-compose node example" ,
241+ args : args {
242+ file : "../../test-resources/docker-compose/test2/docker-compose.yml" ,
243+ },
244+ },
245+ {
246+ name : "test3 docker-compose complex" ,
247+ args : args {
248+ file : "../../test-resources/docker-compose/test3/docker-compose.yml" ,
249+ },
250+ },
251+ {
252+ name : "test4 docker-compose complex" ,
253+ args : args {
254+ file : "../../test-resources/docker-compose/test4/docker-compose.yml" ,
255+ },
256+ },
257+ {
258+ name : "test5 docker-compose complex" ,
259+ args : args {
260+ file : "../../test-resources/docker-compose/test5/docker-compose.yml" ,
261+ },
262+ wantErr : true ,
263+ wantErrMsg : `line 57: mapping key "<<" already defined at line 56` ,
264+ },
265+ {
266+ name : "test6 docker-compose complex" ,
267+ args : args {
268+ file : "../../test-resources/docker-compose/test6/docker-compose.yml" ,
269+ },
270+ },
271+ // these tests are specific to docker-compose validations, but will pass yaml validations
272+ {
273+ name : "test7 check an invalid docker-compose with ignoring non-string key errors (valid yaml)" ,
274+ args : args {
275+ file : "../../test-resources/docker-compose/test7/docker-compose.yml" ,
276+ },
277+ },
278+ {
279+ name : "test8 check an invalid docker-compose (same as test7 but not ignoring the errors)" ,
280+ args : args {
281+ file : "../../test-resources/docker-compose/test8/docker-compose.yml" ,
282+ },
283+ },
284+ {
285+ name : "test9 check an valid docker-compose with missing env_files" ,
286+ args : args {
287+ file : "../../test-resources/docker-compose/test9/docker-compose.yml" ,
288+ },
289+ },
290+ {
291+ name : "test10 check an valid docker-compose with missing env_files (same as test9 but not ignoring the errors)" ,
292+ args : args {
293+ file : "../../test-resources/docker-compose/test10/docker-compose.yml" ,
294+ },
295+ },
296+ {
297+ name : "test11 docker-compose service name with '.'" ,
298+ args : args {
299+ file : "../../test-resources/docker-compose/test11/docker-compose.yml" ,
300+ },
301+ },
302+ // ^^ these tests are specific to docker-compose validations, but will pass yaml validations
303+ }
304+ for _ , tt := range tests {
305+ t .Run (tt .name , func (t * testing.T ) {
306+ err := ValidateUnmarshalDockerComposeYAML (tt .args .file )
307+ if (err != nil ) != tt .wantErr {
308+ t .Errorf ("ValidateUnmarshalDockerComposeYAML() error = %v, wantErr %v" , err , tt .wantErr )
309+ return
310+ }
311+ if err != nil {
312+ if ! strings .Contains (err .Error (), tt .wantErrMsg ) {
313+ t .Errorf ("ValidateUnmarshalDockerComposeYAML() error = %v, wantErr %v" , err .Error (), tt .wantErrMsg )
314+ }
315+ return
316+ }
317+ })
318+ }
319+ }
0 commit comments