Skip to content

Commit 3adbd34

Browse files
committed
Add testcontainers
1 parent c5bd82f commit 3adbd34

File tree

6 files changed

+53
-4
lines changed

6 files changed

+53
-4
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// allowing easy windows / linux testing and producing incrementals
33
// the only feature that buildPlugin has that relates to plugins is allowing you to test against multiple jenkins versions
44
buildPlugin(
5-
useContainerAgent: true,
5+
useContainerAgent: false,
66
configurations: [
77
[platform: 'linux', jdk: 21],
88
[platform: 'windows', jdk: 21],

plugin-modernizer-cli/pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
<groupId>org.slf4j</groupId>
5757
<artifactId>slf4j-api</artifactId>
5858
</dependency>
59+
<dependency>
60+
<groupId>io.github.sparsick.testcontainers.gitserver</groupId>
61+
<artifactId>testcontainers-gitserver</artifactId>
62+
<scope>test</scope>
63+
</dependency>
5964
<!-- Test dependencies -->
6065
<dependency>
6166
<groupId>org.apache.maven</groupId>
@@ -65,6 +70,11 @@
6570
<type>zip</type>
6671
<scope>test</scope>
6772
</dependency>
73+
<dependency>
74+
<groupId>org.testcontainers</groupId>
75+
<artifactId>junit-jupiter</artifactId>
76+
<scope>test</scope>
77+
</dependency>
6878
</dependencies>
6979

7080
<build>
@@ -75,7 +85,6 @@
7585
</resource>
7686
</resources>
7787
<plugins>
78-
<!-- 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 -->
7988
<!-- The CLI is distributed via JRelease and published on the GitHub releases page -->
8089
<plugin>
8190
<groupId>org.apache.maven.plugins</groupId>

plugin-modernizer-cli/src/test/java/io/jenkins/tools/pluginmodernizer/cli/CommandLineITCase.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import static org.junit.jupiter.api.Assertions.assertNotNull;
66
import static org.junit.jupiter.api.Assertions.assertTrue;
77

8+
import com.github.sparsick.testcontainers.gitserver.GitServerVersions;
9+
import com.github.sparsick.testcontainers.gitserver.http.GitHttpServerContainer;
810
import com.github.tomakehurst.wiremock.client.WireMock;
911
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
1012
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
@@ -26,13 +28,19 @@
2628
import org.junit.jupiter.api.io.TempDir;
2729
import org.slf4j.Logger;
2830
import org.slf4j.LoggerFactory;
31+
import org.testcontainers.junit.jupiter.Container;
32+
import org.testcontainers.junit.jupiter.Testcontainers;
2933

3034
/**
3135
* Integration test for the command line interface
3236
*/
3337
@WireMockTest
38+
@Testcontainers(disabledWithoutDocker = true)
3439
public class CommandLineITCase {
3540

41+
@Container
42+
private GitHttpServerContainer gitRemote = new GitHttpServerContainer(GitServerVersions.V2_45.getDockerImageName());
43+
3644
/**
3745
* Logger
3846
*/
@@ -127,7 +135,7 @@ public void testListRecipes() throws Exception {
127135
}
128136

129137
@Test
130-
public void testNotBuildMetadataForDeprecatedPlugin(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
138+
public void testBuildMetadata(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
131139
LOG.info("Running testBuildMetadataForDeprecatedPlugin");
132140

133141
PluginStatsApiResponse pluginStatsApiResponse = new PluginStatsApiResponse(Map.of("a-fake-plugin", 1));
@@ -137,7 +145,7 @@ public void testNotBuildMetadataForDeprecatedPlugin(WireMockRuntimeInfo wmRuntim
137145
new UpdateCenterData.UpdateCenterPlugin(
138146
"a-fake-plugin",
139147
"1",
140-
"git@github.com:jenkinsci/a-fake-plugin.git",
148+
gitRemote.getGitRepoURIAsHttp().toString(),
141149
"main",
142150
"io.jenkins.plugins:a-fake",
143151
null)),
@@ -153,6 +161,9 @@ public void testNotBuildMetadataForDeprecatedPlugin(WireMockRuntimeInfo wmRuntim
153161
WireMock wireMock = wmRuntimeInfo.getWireMock();
154162
wireMock.register(WireMock.get(WireMock.urlEqualTo("/api/user"))
155163
.willReturn(WireMock.jsonResponse(USER_API_RESPONSE, 200)));
164+
wireMock.register(WireMock.get(WireMock.urlEqualTo("/api/repos/jenkinsci/testRepo"))
165+
.willReturn(WireMock.jsonResponse(
166+
new RepoApiResponse(gitRemote.getGitRepoURIAsHttp().toString()), 200)));
156167
wireMock.register(WireMock.get(WireMock.urlEqualTo("/update-center.json"))
157168
.willReturn(WireMock.jsonResponse(updateCenterApiResponse, 200)));
158169
wireMock.register(WireMock.get(WireMock.urlEqualTo("/plugin-versions.json"))
@@ -255,6 +266,8 @@ private InvocationRequest buildRequest(String args) {
255266
*/
256267
private record UserApiResponse(String login, String type) {}
257268

269+
private record RepoApiResponse(String clone_url) {}
270+
258271
private static final UserApiResponse USER_API_RESPONSE = new UserApiResponse("fake-owner", "User");
259272

260273
private record PluginStatsApiResponse(Map<String, Integer> plugins) {}

plugin-modernizer-cli/src/test/resources/a-fake-plugin/pom.xml

Whitespace-only changes.

plugin-modernizer-cli/src/test/resources/logback-test.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
<appender-ref ref="CONSOLE" />
1616
</root>
1717
<logger name="io.jenkins.tools.pluginmodernizer" level="TRACE" />
18+
<logger name="org.testcontainers" level="INFO" />
19+
<logger name="com.github.dockerjava" level="INFO" />
1820
</configuration>

pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
<bouncycastle.version>1.79</bouncycastle.version>
7676
<maven.surefire.version>3.5.2</maven.surefire.version>
7777
<maven.failsafe.version>3.5.2</maven.failsafe.version>
78+
<testcontainers.version>1.20.4</testcontainers.version>
79+
<testcontainers.git.version>0.10.0</testcontainers.git.version>
7880
</properties>
7981

8082
<dependencyManagement>
@@ -255,6 +257,18 @@
255257
<artifactId>snakeyaml</artifactId>
256258
<version>${snakeyaml.version}</version>
257259
</dependency>
260+
<dependency>
261+
<groupId>io.github.sparsick.testcontainers.gitserver</groupId>
262+
<artifactId>testcontainers-gitserver</artifactId>
263+
<version>${testcontainers.git.version}</version>
264+
<scope>test</scope>
265+
</dependency>
266+
<dependency>
267+
<groupId>org.testcontainers</groupId>
268+
<artifactId>junit-jupiter</artifactId>
269+
<version>${testcontainers.version}</version>
270+
<scope>test</scope>
271+
</dependency>
258272
</dependencies>
259273
</dependencyManagement>
260274

@@ -340,6 +354,17 @@
340354
</build>
341355

342356
<profiles>
357+
<profile>
358+
<id>skip-spotless-on-windows</id>
359+
<activation>
360+
<os>
361+
<family>windows</family>
362+
</os>
363+
</activation>
364+
<properties>
365+
<spotless.check.skip>true</spotless.check.skip>
366+
</properties>
367+
</profile>
343368
<profile>
344369
<id>enable-jacoco</id>
345370
<build>

0 commit comments

Comments
 (0)