@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 2023 the original author or authors .
* Copyright 2012 - 2024 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -18,6 +18,7 @@ package org.springframework.boot.docker.compose.core;
@@ -18,6 +18,7 @@ package org.springframework.boot.docker.compose.core;
import java.io.File ;
import java.io.IOException ;
import java.util.List ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.io.TempDir ;
@ -59,12 +60,20 @@ class DockerComposeFileTests {
@@ -59,12 +60,20 @@ class DockerComposeFileTests {
assertThat ( composeFile . toString ( ) ) . endsWith ( File . separator + "compose.yml" ) ;
}
@Test
void toStringReturnsFileNameList ( ) throws Exception {
File file1 = createTempFile ( "1.yml" ) ;
File file2 = createTempFile ( "2.yml" ) ;
DockerComposeFile composeFile = DockerComposeFile . of ( List . of ( file1 , file2 ) ) ;
assertThat ( composeFile ) . hasToString ( file1 + ", " + file2 ) ;
}
@Test
void findFindsSingleFile ( ) throws Exception {
File file = new File ( this . temp , "docker-compose.yml" ) ;
FileCopyUtils . copy ( new byte [ 0 ] , file ) ;
DockerComposeFile composeFile = DockerComposeFile . find ( file . getParentFile ( ) ) ;
assertThat ( composeFile . toString ( ) ) . endsWith ( File . separator + "docker-compose.yml" ) ;
assertThat ( composeFile . getFiles ( ) ) . containsExactly ( file ) ;
}
@Test
@ -74,7 +83,7 @@ class DockerComposeFileTests {
@@ -74,7 +83,7 @@ class DockerComposeFileTests {
File f2 = new File ( this . temp , "compose.yml" ) ;
FileCopyUtils . copy ( new byte [ 0 ] , f2 ) ;
DockerComposeFile composeFile = DockerComposeFile . find ( f1 . getParentFile ( ) ) ;
assertThat ( composeFile . toString ( ) ) . endsWith ( File . separator + "compose.yml" ) ;
assertThat ( composeFile . getFiles ( ) ) . containsExactly ( f2 ) ;
}
@Test
@ -94,24 +103,31 @@ class DockerComposeFileTests {
@@ -94,24 +103,31 @@ class DockerComposeFileTests {
@Test
void findWhenWorkingDirectoryIsNotDirectoryThrowsException ( ) throws Exception {
File file = new File ( this . temp , "iamafile" ) ;
FileCopyUtils . copy ( new byte [ 0 ] , file ) ;
File file = createTempFile ( "iamafile" ) ;
assertThatIllegalArgumentException ( ) . isThrownBy ( ( ) - > DockerComposeFile . find ( file ) )
. withMessageEndingWith ( "is not a directory" ) ;
}
@Test
void ofReturnsDockerComposeFile ( ) throws Exception {
File file = new File ( this . temp , "anyfile.yml" ) ;
FileCopyUtils . copy ( new byte [ 0 ] , file ) ;
File file = createTempFile ( "compose.yml" ) ;
DockerComposeFile composeFile = DockerComposeFile . of ( file ) ;
assertThat ( composeFile ) . isNotNull ( ) ;
assertThat ( composeFile ) . hasToString ( file . getCanonicalPath ( ) ) ;
assertThat ( composeFile . getFiles ( ) ) . containsExactly ( file ) ;
}
@Test
void ofWithMultipleFilesReturnsDockerComposeFile ( ) throws Exception {
File file1 = createTempFile ( "1.yml" ) ;
File file2 = createTempFile ( "2.yml" ) ;
DockerComposeFile composeFile = DockerComposeFile . of ( List . of ( file1 , file2 ) ) ;
assertThat ( composeFile ) . isNotNull ( ) ;
assertThat ( composeFile . getFiles ( ) ) . containsExactly ( file1 , file2 ) ;
}
@Test
void ofWhenFileIsNullThrowsException ( ) {
assertThatIllegalArgumentException ( ) . isThrownBy ( ( ) - > DockerComposeFile . of ( null ) )
assertThatIllegalArgumentException ( ) . isThrownBy ( ( ) - > DockerComposeFile . of ( ( File ) null ) )
. withMessage ( "File must not be null" ) ;
}
@ -129,9 +145,13 @@ class DockerComposeFileTests {
@@ -129,9 +145,13 @@ class DockerComposeFileTests {
}
private DockerComposeFile createComposeFile ( String name ) throws IOException {
return DockerComposeFile . of ( createTempFile ( name ) ) ;
}
private File createTempFile ( String name ) throws IOException {
File file = new File ( this . temp , name ) ;
FileCopyUtils . copy ( new byte [ 0 ] , file ) ;
return DockerComposeFile . of ( file ) ;
return file . getCanonicalFile ( ) ;
}
}