@@ -23,7 +23,9 @@ func randomName(prefix string) string {
2323}
2424
2525func TestInitFromComposeFile (t * testing.T ) {
26- composeData := `services:
26+ composeData := `
27+ version: '3.0'
28+ services:
2729 nginx:
2830 image: nginx:${NGINX_VERSION}
2931 command: nginx $NGINX_ARGS
@@ -65,6 +67,49 @@ func TestInitFromInvalidComposeFile(t *testing.T) {
6567 assert .ErrorContains (t , err , "failed to read" )
6668}
6769
70+ func TestInitFromV2ComposeFile (t * testing.T ) {
71+ composeData := `
72+ version: '2.4'
73+ services:
74+ nginx:
75+ image: nginx:${NGINX_VERSION}
76+ command: nginx $NGINX_ARGS
77+ `
78+ inputDir := randomName ("app_input_" )
79+ os .Mkdir (inputDir , 0755 )
80+ ioutil .WriteFile (filepath .Join (inputDir , "docker-compose.yml" ), []byte (composeData ), 0644 )
81+ defer os .RemoveAll (inputDir )
82+
83+ testAppName := randomName ("app_" )
84+ dirName := internal .DirNameFromAppName (testAppName )
85+ err := os .Mkdir (dirName , 0755 )
86+ assert .NilError (t , err )
87+ defer os .RemoveAll (dirName )
88+
89+ err = initFromComposeFile (testAppName , filepath .Join (inputDir , "docker-compose.yml" ))
90+ assert .ErrorContains (t , err , "unsupported Compose file version" )
91+ }
92+
93+ func TestInitFromV1ComposeFile (t * testing.T ) {
94+ composeData := `
95+ nginx:
96+ image: nginx
97+ `
98+ inputDir := randomName ("app_input_" )
99+ os .Mkdir (inputDir , 0755 )
100+ ioutil .WriteFile (filepath .Join (inputDir , "docker-compose.yml" ), []byte (composeData ), 0644 )
101+ defer os .RemoveAll (inputDir )
102+
103+ testAppName := randomName ("app_" )
104+ dirName := internal .DirNameFromAppName (testAppName )
105+ err := os .Mkdir (dirName , 0755 )
106+ assert .NilError (t , err )
107+ defer os .RemoveAll (dirName )
108+
109+ err = initFromComposeFile (testAppName , filepath .Join (inputDir , "docker-compose.yml" ))
110+ assert .ErrorContains (t , err , "unsupported Compose file version" )
111+ }
112+
68113func TestWriteMetadataFile (t * testing.T ) {
69114 appName := "writemetadata_test"
70115 tmpdir := fs .NewDir (t , appName )
0 commit comments