Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Git Server version support #16

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}