Skip to content

Commit

Permalink
tests: refactor test, so that it is hopefully running on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sparsick committed Oct 11, 2023
1 parent f14e70d commit f89b366
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -32,6 +36,7 @@ public class GitServerContainerTest {
@TempDir(cleanup = CleanupMode.NEVER)
private File tempDir;


@Test
void validDockerImageName() {
assertThatNoException().isThrownBy(() ->
Expand Down Expand Up @@ -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", "[email protected]").setMessage("init").call();

var containerUnderTest = new GitServerContainer(LATEST_GIT_SERVER_VERSION)
.withCopyExistingGitRepoToContainer(sampleRepo.getAbsolutePath());

containerUnderTest.start();

URI gitRepoURI = containerUnderTest.getGitRepoURIAsSSH();
Expand All @@ -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", "[email protected]").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();
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/existingRepo
Submodule existingRepo deleted from cce45a
Empty file.

0 comments on commit f89b366

Please sign in to comment.