Skip to content

Commit

Permalink
Merge pull request #464 from jonesbusy/feature/testcontainer
Browse files Browse the repository at this point in the history
Add testcontainers
  • Loading branch information
jonesbusy authored Dec 16, 2024
2 parents c5bd82f + 3adbd34 commit e55159c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// allowing easy windows / linux testing and producing incrementals
// the only feature that buildPlugin has that relates to plugins is allowing you to test against multiple jenkins versions
buildPlugin(
useContainerAgent: true,
useContainerAgent: false,
configurations: [
[platform: 'linux', jdk: 21],
[platform: 'windows', jdk: 21],
Expand Down
11 changes: 10 additions & 1 deletion plugin-modernizer-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>io.github.sparsick.testcontainers.gitserver</groupId>
<artifactId>testcontainers-gitserver</artifactId>
<scope>test</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -65,6 +70,11 @@
<type>zip</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -75,7 +85,6 @@
</resource>
</resources>
<plugins>
<!-- We don't want to deploy the CLI to Jenkins Artifactory (It's huge fat jar of ~100Mib). We only need the parent pom and core for recipes -->
<!-- The CLI is distributed via JRelease and published on the GitHub releases page -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.github.sparsick.testcontainers.gitserver.GitServerVersions;
import com.github.sparsick.testcontainers.gitserver.http.GitHttpServerContainer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
Expand All @@ -26,13 +28,19 @@
import org.junit.jupiter.api.io.TempDir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

/**
* Integration test for the command line interface
*/
@WireMockTest
@Testcontainers(disabledWithoutDocker = true)
public class CommandLineITCase {

@Container
private GitHttpServerContainer gitRemote = new GitHttpServerContainer(GitServerVersions.V2_45.getDockerImageName());

/**
* Logger
*/
Expand Down Expand Up @@ -127,7 +135,7 @@ public void testListRecipes() throws Exception {
}

@Test
public void testNotBuildMetadataForDeprecatedPlugin(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
public void testBuildMetadata(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
LOG.info("Running testBuildMetadataForDeprecatedPlugin");

PluginStatsApiResponse pluginStatsApiResponse = new PluginStatsApiResponse(Map.of("a-fake-plugin", 1));
Expand All @@ -137,7 +145,7 @@ public void testNotBuildMetadataForDeprecatedPlugin(WireMockRuntimeInfo wmRuntim
new UpdateCenterData.UpdateCenterPlugin(
"a-fake-plugin",
"1",
"[email protected]:jenkinsci/a-fake-plugin.git",
gitRemote.getGitRepoURIAsHttp().toString(),
"main",
"io.jenkins.plugins:a-fake",
null)),
Expand All @@ -153,6 +161,9 @@ public void testNotBuildMetadataForDeprecatedPlugin(WireMockRuntimeInfo wmRuntim
WireMock wireMock = wmRuntimeInfo.getWireMock();
wireMock.register(WireMock.get(WireMock.urlEqualTo("/api/user"))
.willReturn(WireMock.jsonResponse(USER_API_RESPONSE, 200)));
wireMock.register(WireMock.get(WireMock.urlEqualTo("/api/repos/jenkinsci/testRepo"))
.willReturn(WireMock.jsonResponse(
new RepoApiResponse(gitRemote.getGitRepoURIAsHttp().toString()), 200)));
wireMock.register(WireMock.get(WireMock.urlEqualTo("/update-center.json"))
.willReturn(WireMock.jsonResponse(updateCenterApiResponse, 200)));
wireMock.register(WireMock.get(WireMock.urlEqualTo("/plugin-versions.json"))
Expand Down Expand Up @@ -255,6 +266,8 @@ private InvocationRequest buildRequest(String args) {
*/
private record UserApiResponse(String login, String type) {}

private record RepoApiResponse(String clone_url) {}

private static final UserApiResponse USER_API_RESPONSE = new UserApiResponse("fake-owner", "User");

private record PluginStatsApiResponse(Map<String, Integer> plugins) {}
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions plugin-modernizer-cli/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
<appender-ref ref="CONSOLE" />
</root>
<logger name="io.jenkins.tools.pluginmodernizer" level="TRACE" />
<logger name="org.testcontainers" level="INFO" />
<logger name="com.github.dockerjava" level="INFO" />
</configuration>
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<bouncycastle.version>1.79</bouncycastle.version>
<maven.surefire.version>3.5.2</maven.surefire.version>
<maven.failsafe.version>3.5.2</maven.failsafe.version>
<testcontainers.version>1.20.4</testcontainers.version>
<testcontainers.git.version>0.10.0</testcontainers.git.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -255,6 +257,18 @@
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>io.github.sparsick.testcontainers.gitserver</groupId>
<artifactId>testcontainers-gitserver</artifactId>
<version>${testcontainers.git.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -340,6 +354,17 @@
</build>

<profiles>
<profile>
<id>skip-spotless-on-windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<spotless.check.skip>true</spotless.check.skip>
</properties>
</profile>
<profile>
<id>enable-jacoco</id>
<build>
Expand Down

0 comments on commit e55159c

Please sign in to comment.