From a9ac76fa37896abb67d1327c489b4919b8732a3b Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Sat, 26 Aug 2023 12:31:09 +0200 Subject: [PATCH 1/3] test: refactor tests to test all supported git server images --- .../gitserver/GitServerContainerTest.java | 17 +++++++++++------ .../gitserver/SupportedGitServerImages.java | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 src/test/java/com/github/sparsick/testcontainers/gitserver/SupportedGitServerImages.java 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 7b74434..df6d247 100644 --- a/src/test/java/com/github/sparsick/testcontainers/gitserver/GitServerContainerTest.java +++ b/src/test/java/com/github/sparsick/testcontainers/gitserver/GitServerContainerTest.java @@ -7,6 +7,9 @@ import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; +import org.testcontainers.shaded.com.github.dockerjava.core.DockerContextMetaFile; import org.testcontainers.utility.DockerImageName; import java.io.File; @@ -63,9 +66,10 @@ void exposedPortIs22() { assertThat(exposedPorts).containsOnly(22); } - @Test - void containerStarted() { - var containerUnderTest = new GitServerContainer(DockerImageName.parse("rockstorm/git-server:2.38")); + @ParameterizedTest + @ArgumentsSource(SupportedGitServerImages.class) + void containerStarted(DockerImageName dockerImageName) { + var containerUnderTest = new GitServerContainer(dockerImageName); containerUnderTest.start(); @@ -83,9 +87,10 @@ void gitRepoURI() { assertThat(gitRepoURI.toString()).isEqualTo("ssh://git@"+ containerUnderTest.getHost() + ":" + gitPort + "/srv/git/testRepoName.git"); } - @Test - void setupGitRepo() { - var containerUnderTest = new GitServerContainer(DockerImageName.parse("rockstorm/git-server:2.38")).withGitRepo("testRepoName"); + @ParameterizedTest + @ArgumentsSource(SupportedGitServerImages.class) + void setupGitRepo(DockerImageName dockerImageName) { + var containerUnderTest = new GitServerContainer(dockerImageName).withGitRepo("testRepoName"); containerUnderTest.start(); diff --git a/src/test/java/com/github/sparsick/testcontainers/gitserver/SupportedGitServerImages.java b/src/test/java/com/github/sparsick/testcontainers/gitserver/SupportedGitServerImages.java new file mode 100644 index 0000000..f4e8a00 --- /dev/null +++ b/src/test/java/com/github/sparsick/testcontainers/gitserver/SupportedGitServerImages.java @@ -0,0 +1,15 @@ +package com.github.sparsick.testcontainers.gitserver; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.testcontainers.utility.DockerImageName; + +import java.util.stream.Stream; + +public class SupportedGitServerImages implements ArgumentsProvider { + @Override + public Stream provideArguments(ExtensionContext extensionContext) { + return Stream.of("2.40", "2.38", "2.36", "2.34", "2.34.2").map(version -> DockerImageName.parse("rockstorm/git-server:" + version)).map(Arguments::of); + } +} From 2411d23f5a971761e708599e2e46d7f0243d6040 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Sat, 26 Aug 2023 16:20:15 +0200 Subject: [PATCH 2/3] feat: add support for all release version of git server docker image --- .../testcontainers/gitserver/GitServerContainer.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/sparsick/testcontainers/gitserver/GitServerContainer.java b/src/main/java/com/github/sparsick/testcontainers/gitserver/GitServerContainer.java index 86e9ce4..2104f3b 100644 --- a/src/main/java/com/github/sparsick/testcontainers/gitserver/GitServerContainer.java +++ b/src/main/java/com/github/sparsick/testcontainers/gitserver/GitServerContainer.java @@ -24,7 +24,11 @@ public class GitServerContainer extends GenericContainer { public GitServerContainer(DockerImageName dockerImageName) { super(dockerImageName); dockerImageName.assertCompatibleWith(DEFAULT_DOCKER_IMAGE_NAME); - waitingFor(Wait.forLogMessage(".*Container configuration completed.*", 1)).addExposedPorts(22); + if ("2.38".compareTo(dockerImageName.getVersionPart()) <= 0 ) { + waitingFor(Wait.forLogMessage(".*Container configuration completed.*", 1)).addExposedPorts(22); + } else { + withExposedPorts(22); + } } /** From 9d5ed24d755f46040cef60f3aff4384c569076c2 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Sat, 26 Aug 2023 16:23:51 +0200 Subject: [PATCH 3/3] doc: fix javadoc warnings --- .../testcontainers/gitserver/GitServerContainer.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/github/sparsick/testcontainers/gitserver/GitServerContainer.java b/src/main/java/com/github/sparsick/testcontainers/gitserver/GitServerContainer.java index 2104f3b..038e3bc 100644 --- a/src/main/java/com/github/sparsick/testcontainers/gitserver/GitServerContainer.java +++ b/src/main/java/com/github/sparsick/testcontainers/gitserver/GitServerContainer.java @@ -80,6 +80,13 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) { } } + /** + * Return the Git Password that was set with the method {@code withGitPassword}. + * + * If no password was set, the default "12345" is returned. + * + * @return the git password + */ public String getGitPassword() { var password = getEnvMap().get(GIT_PASSWORD_KEY); return password != null ? password : "12345";