diff --git a/src/test/java/com/github/sparsick/testcontainers/gitserver/GitServerContainerTest.java b/src/test/java/com/github/sparsick/testcontainers/gitserver/GitServerContainerTest.java index c80724a..d6389df 100644 --- a/src/test/java/com/github/sparsick/testcontainers/gitserver/GitServerContainerTest.java +++ b/src/test/java/com/github/sparsick/testcontainers/gitserver/GitServerContainerTest.java @@ -5,6 +5,7 @@ import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.transport.SshTransport; import org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory; import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig; @@ -14,10 +15,13 @@ import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; +import org.testcontainers.shaded.org.apache.commons.io.FileUtils; import org.testcontainers.utility.DockerImageName; import java.io.File; +import java.io.IOException; import java.net.URI; +import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -32,6 +36,7 @@ public class GitServerContainerTest { @TempDir(cleanup = CleanupMode.NEVER) private File tempDir; + @Test void validDockerImageName() { assertThatNoException().isThrownBy(() -> @@ -94,8 +99,16 @@ void gitRepoURI() { } @Test - void copyExistingGitRepo() { - var containerUnderTest = new GitServerContainer(LATEST_GIT_SERVER_VERSION).withCopyExistingGitRepoToContainer("src/test/resources/existingRepo"); + void copyExistingGitRepo(@TempDir File sampleRepo) throws GitAPIException, IOException { + FileUtils.copyFileToDirectory(new File("src/test/resources/sampleRepo/testFile"), sampleRepo); + + Git repo = Git.init().setDirectory(sampleRepo).setInitialBranch("main").call(); + repo.add().addFilepattern("testFile").call(); + repo.commit().setAuthor("Sandra Parsick", "sample@example.com").setMessage("init").call(); + + var containerUnderTest = new GitServerContainer(LATEST_GIT_SERVER_VERSION) + .withCopyExistingGitRepoToContainer(sampleRepo.getAbsolutePath()); + containerUnderTest.start(); URI gitRepoURI = containerUnderTest.getGitRepoURIAsSSH(); @@ -122,10 +135,16 @@ protected void configure(OpenSshConfig.Host hc, Session session) { } @Test - void copyExistingGitRepoWithCustomRepoName() { + void copyExistingGitRepoWithCustomRepoName(@TempDir File sampleRepo) throws IOException, GitAPIException { + FileUtils.copyFileToDirectory(new File("src/test/resources/sampleRepo/testFile"), sampleRepo); + + Git repo = Git.init().setDirectory(sampleRepo).call(); + repo.add().addFilepattern("testFile").call(); + repo.commit().setAuthor("Sandra Parsick", "sample@example.com").setMessage("init").call(); + var containerUnderTest = new GitServerContainer(LATEST_GIT_SERVER_VERSION) .withGitRepo("customRepoName") - .withCopyExistingGitRepoToContainer("src/test/resources/existingRepo"); + .withCopyExistingGitRepoToContainer(sampleRepo.getAbsolutePath()); containerUnderTest.start(); URI gitRepoURI = containerUnderTest.getGitRepoURIAsSSH(); diff --git a/src/test/resources/existingRepo b/src/test/resources/existingRepo deleted file mode 160000 index cce45a5..0000000 --- a/src/test/resources/existingRepo +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cce45a551767e3d6e19f5f7db83a9f33f4a9a317 diff --git a/src/test/resources/sampleRepo/testFile b/src/test/resources/sampleRepo/testFile new file mode 100644 index 0000000..e69de29