Key metrics and engagement data
Repository has been active for 2 years, 2 months
⭐33
Want deeper insights? Explore GitObs.com
This project contains a Testcontainers implementation for a plain git server based on the Docker image rockstorm/git-server
(Github Project).
It sets up the git server with a ready to use repository with the default name testRepo
.
The repository name can be overwritten.
It exists two flavours for the git server (exposed by SSH or by HTTP)
The port is set by testcontainers' mechanism.
Maven:
xml1<dependencyManagement>2 <dependencies>3 <dependency>4 <groupId>io.github.sparsick.testcontainers.gitserver</groupId>5 <artifactId>testcontainers-git-bom</artifactId>6 <version>0.12.0</version>7 <scope>test</scope>8 </dependency>9 </dependencies>10</dependencyManagement>1112<dependencies>13 <dependency>14 <groupId>io.github.sparsick.testcontainers.gitserver</groupId>15 <artifactId>testcontainers-gitserver</artifactId>16 <scope>test</scope>17 </dependency>18</dependencies>
Gradle:
groovy1dependencyManagement {2 imports {3 mavenBom("io.github.sparsick.testcontainers.gitserver:testcontainers-git-bom:0.12.0")4 }5}678dependencies {9 testImplementation 'io.github.sparsick.testcontainers.gitserver:testcontainers-gitserver'10}
The following samples show how to use the git server container in a JUnit 5 test. Currently, there exists two flavour:
GitServerContainer
)GitHttpServerContainer
)The following sample shows how to use the git server container via SSH in a JUnit 5 test:
java1import com.github.sparsick.testcontainers.gitserver.GitServerVersions;2import com.github.sparsick.testcontainers.gitserver.plain.GitServerContainer;3import com.github.sparsick.testcontainers.gitserver.plain.SshHostKey;4import com.github.sparsick.testcontainers.gitserver.plain.SshIdentity;56@Testcontainers7public class GitServerContainerUsedInJUnit5Test {89 @Container10 private GitServerContainer containerUnderTest =11 new GitServerContainer(GitServerVersions.V2_43.getDockerImageName())12 .withGitRepo("testRepo") // overwrite the default git repository name13 .withGitPassword("12345") // overwrite the default git password14 .withSshKeyAuth() // enabled public key authentication15 .withCopyExistingGitRepoToContainer("src/test/resources/sampleRepo"); // path to an already existing Git repository1617 @Test18 void checkInteractWithTheContainer() {19 URI gitRepoURI = containerUnderTest.getGitRepoURIAsSSH();20 String gitPassword = containerUnderTest.getGitPassword();2122 SshIdentity sshIdentity = containerUnderTest.getSshClientIdentity();23 byte[] privateKey = sshIdentity.getPrivateKey();24 byte[] publicKey = sshIdentity.getPublicKey();25 byte[] passphrase = sshIdentity.getPassphrase();2627 SshHostKey hostKey = containerUnderTest.getHostKey();28 String host = hostKey.getHostname();29 byte[] key = hostKey.getKey();3031 // check interaction3233 }34}
The following sample shows how to use the git server container via HTTP without Basic Authentication in a JUnit 5 test:
java1import com.github.sparsick.testcontainers.gitserver.GitServerVersions;2import com.github.sparsick.testcontainers.gitserver.http.GitHttpServerContainer;34@Testcontainers5public class GitHttpServerContainerUsedInJUnit5Test {67 @Container8 private GitHttpServerContainer containerUnderTest =9 new GitHttpServerContainer(GitServerVersions.V2_43.getDockerImageName());1011 @Test12 void checkInteractWithTheContainer() {13 URI gitRepoURI = containerUnderTest.getGitRepoURIAsHttp();1415 // check interaction16 }17}
The next sample shows how to use the git server container via HTTP with Basic Authentication in a JUnit 5 test:
java1import com.github.sparsick.testcontainers.gitserver.GitServerVersions;2import com.github.sparsick.testcontainers.gitserver.http.BasicAuthenticationCredentials;3import com.github.sparsick.testcontainers.gitserver.http.GitHttpServerContainer;45@Testcontainers6public class GitHttpServerContainerUsedInJUnit5Test {78 @Container9 private GitHttpServerContainer containerUnderTest =10 new GitHttpServerContainer(GitServerVersions.V2_43.getDockerImageName(), new BasicAuthenticationCredentials("testuser", "testPassword"));1112 @Test13 void checkInteractWithTheContainer() {14 URI gitRepoURI = containerUnderTest.getGitRepoURIAsHttp();1516 BasicAuthenticationCredentials basicAuthCredentials = containerUnderTest.getBasicAuthCredentials();17 String username = basicAuthCredentials.getUsername();18 String password = basicAuthCredentials.getPassword();1920 // check interaction21 }22}
Since 0.9.0 it is possible to configure HTTP proxy, programmatically.
java1import com.github.sparsick.testcontainers.gitserver.GitServerVersions;2import com.github.sparsick.testcontainers.gitserver.http.GitHttpServerContainer;34@Testcontainers5public class GitHttpServerContainerUsedInJUnit5Test {67 @Container8 private GitHttpServerContainer containerUnderTest =9 new GitHttpServerContainer(GitServerVersions.V2_43.getDockerImageName())10 .withHttpProxySetting(new HttpProxySetting("http://proxy.example.com", "https://proxy.example.com", ""));1112 @Test13 void hasHttpProxySetting() {14 assertThat(containerUnderTest.hasHttpProxy()).isTrue();15 // check interaction16 }17}
In 0.5.x the package structure has changed.
The package com.github.sparsick.testcontainers.gitserver
is split in com.github.sparsick.testcontainers.gitserver.plain
and com.github.sparsick.testcontainers.gitserver.http
.
Making this migration easier, an OpenRewrite recipe io.github.sparsick.testcontainers.gitserver.rewrite.recipe.SplitPackage
is provided.
shell1mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \2 -Drewrite.recipeArtifactCoordinates=io.github.sparsick.testcontainers.gitserver:rewrite-testcontainers-gitserver:RELEASE \3 -Drewrite.activeRecipes=io.github.sparsick.testcontainers.gitserver.rewrite.recipe.SplitPackage
MIT License