Skip to content

Commit b35d1ec

Browse files
committed
Revert "Use test harness for image building integration tests"
This reverts commit da9d8d6. See gh-25838
1 parent 51d57e1 commit b35d1ec

File tree

26 files changed

+145
-285
lines changed

26 files changed

+145
-285
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java

+46-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,8 @@
2929
import org.gradle.testkit.runner.TaskOutcome;
3030
import org.junit.jupiter.api.TestTemplate;
3131
import org.junit.jupiter.api.extension.ExtendWith;
32+
import org.testcontainers.containers.GenericContainer;
33+
import org.testcontainers.containers.wait.strategy.Wait;
3234

3335
import org.springframework.boot.buildpack.platform.docker.DockerApi;
3436
import org.springframework.boot.buildpack.platform.docker.type.ImageName;
@@ -59,10 +61,14 @@ void buildsImageWithDefaultBuilder() throws IOException {
5961
String projectName = this.gradleBuild.getProjectDir().getName();
6062
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
6163
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
62-
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
63-
assertThat(result.getOutput()).contains("env: BP_JVM_VERSION=8.*");
64-
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
65-
removeImage(projectName);
64+
assertThat(result.getOutput()).contains("paketo-buildpacks/builder");
65+
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
66+
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
67+
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
68+
}
69+
finally {
70+
new DockerApi().image().remove(imageReference, false);
71+
}
6672
}
6773

6874
@TestTemplate
@@ -72,10 +78,14 @@ void buildsImageWithCustomName() throws IOException {
7278
BuildResult result = this.gradleBuild.build("bootBuildImage");
7379
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
7480
assertThat(result.getOutput()).contains("example/test-image-name");
75-
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
76-
assertThat(result.getOutput()).contains("env: BP_JVM_VERSION=8.*");
77-
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
78-
removeImage("example/test-image-name");
81+
assertThat(result.getOutput()).contains("paketo-buildpacks/builder");
82+
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-name"));
83+
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
84+
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
85+
}
86+
finally {
87+
new DockerApi().image().remove(imageReference, false);
88+
}
7989
}
8090

8191
@TestTemplate
@@ -85,26 +95,34 @@ void buildsImageWithCustomBuilderAndRunImage() throws IOException {
8595
BuildResult result = this.gradleBuild.build("bootBuildImage");
8696
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
8797
assertThat(result.getOutput()).contains("example/test-image-custom");
88-
assertThat(result.getOutput()).contains("springci/spring-boot-cnb-builder:0.0.1");
89-
assertThat(result.getOutput()).contains("paketobuildpacks/run:tiny-cnb");
90-
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
91-
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
92-
removeImage("example/test-image-custom");
98+
assertThat(result.getOutput()).contains("paketobuildpacks/builder:full");
99+
assertThat(result.getOutput()).contains("paketobuildpacks/run:full-cnb");
100+
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-custom"));
101+
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
102+
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
103+
}
104+
finally {
105+
new DockerApi().image().remove(imageReference, false);
106+
}
93107
}
94108

95109
@TestTemplate
96110
void buildsImageWithCommandLineOptions() throws IOException {
97111
writeMainClass();
98112
writeLongNameResource();
99113
BuildResult result = this.gradleBuild.build("bootBuildImage", "--imageName=example/test-image-cmd",
100-
"--builder=springci/spring-boot-cnb-builder:0.0.1", "--runImage=paketobuildpacks/run:tiny-cnb");
114+
"--builder=paketobuildpacks/builder:full", "--runImage=paketobuildpacks/run:full-cnb");
101115
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
102116
assertThat(result.getOutput()).contains("example/test-image-cmd");
103-
assertThat(result.getOutput()).contains("springci/spring-boot-cnb-builder:0.0.1");
104-
assertThat(result.getOutput()).contains("paketobuildpacks/run:tiny-cnb");
105-
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
106-
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
107-
removeImage("example/test-image-cmd");
117+
assertThat(result.getOutput()).contains("paketobuildpacks/builder:full");
118+
assertThat(result.getOutput()).contains("paketobuildpacks/run:full-cnb");
119+
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-cmd"));
120+
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
121+
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
122+
}
123+
finally {
124+
new DockerApi().image().remove(imageReference, false);
125+
}
108126
}
109127

110128
@TestTemplate
@@ -122,7 +140,6 @@ void failsWithBuilderError() {
122140
writeLongNameResource();
123141
BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage");
124142
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.FAILED);
125-
assertThat(result.getOutput()).contains("Forced builder failure");
126143
assertThat(result.getOutput()).containsPattern("Builder lifecycle '.*' failed with status code");
127144
}
128145

@@ -153,12 +170,17 @@ void buildsImageWithWarPackagingAndJarConfiguration() throws IOException {
153170
String projectName = this.gradleBuild.getProjectDir().getName();
154171
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
155172
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
156-
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
157-
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
173+
assertThat(result.getOutput()).contains("paketo-buildpacks/builder");
158174
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
159175
assertThat(buildLibs.listFiles())
160176
.containsExactly(new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".war"));
161-
removeImage(projectName);
177+
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
178+
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
179+
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
180+
}
181+
finally {
182+
new DockerApi().image().remove(imageReference, false);
183+
}
162184
}
163185

164186
private void writeMainClass() {
@@ -200,9 +222,4 @@ private void writeLongNameResource() {
200222
}
201223
}
202224

203-
private void removeImage(String name) throws IOException {
204-
ImageReference imageReference = ImageReference.of(ImageName.of(name));
205-
new DockerApi().image().remove(imageReference, false);
206-
}
207-
208225
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithCommandLineOptions.gradle

-7
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithCustomBuilderAndRunImage.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ targetCompatibility = '1.8'
88

99
bootBuildImage {
1010
imageName = "example/test-image-custom"
11-
builder = "springci/spring-boot-cnb-builder:0.0.1"
12-
runImage = "paketobuildpacks/run:tiny-cnb"
11+
builder = "paketobuildpacks/builder:full"
12+
runImage = "paketobuildpacks/run:full-cnb"
1313
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithCustomName.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ targetCompatibility = '1.8'
88

99
bootBuildImage {
1010
imageName = "example/test-image-name"
11-
builder = "springci/spring-boot-cnb-builder:0.0.1"
1211
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithWarPackagingAndJarConfiguration.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,3 @@ bootBuildImage {
99

1010
sourceCompatibility = '1.8'
1111
targetCompatibility = '1.8'
12-
13-
bootBuildImage {
14-
builder = "springci/spring-boot-cnb-builder:0.0.1"
15-
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-failsWithBuilderError.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ sourceCompatibility = '1.8'
77
targetCompatibility = '1.8'
88

99
bootBuildImage {
10-
builder = "springci/spring-boot-cnb-builder:0.0.1"
11-
environment = ["FORCE_FAILURE": "true"]
10+
environment = ["BP_JVM_VERSION": "13.9.9"]
1211
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,3 @@ if (project.hasProperty('applyWarPlugin')) {
99

1010
sourceCompatibility = '1.8'
1111
targetCompatibility = '1.8'
12-
13-
bootBuildImage {
14-
builder = "springci/spring-boot-cnb-builder:0.0.1"
15-
}

0 commit comments

Comments
 (0)