Skip to content

Commit

Permalink
Merge pull request #16 from sparsick/improve-git-version-support
Browse files Browse the repository at this point in the history
Improve Git Server version support
  • Loading branch information
sparsick authored Aug 26, 2023
2 parents 3f0c94a + 9d5ed24 commit 28509cf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public class GitServerContainer extends GenericContainer<GitServerContainer> {
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);
}
}

/**
Expand Down Expand Up @@ -76,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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<? extends Arguments> 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);
}
}

0 comments on commit 28509cf

Please sign in to comment.