38
38
import org .junit .jupiter .api .TestTemplate ;
39
39
import org .junit .jupiter .api .condition .DisabledOnOs ;
40
40
import org .junit .jupiter .api .condition .OS ;
41
- import org .testcontainers .containers .GenericContainer ;
42
- import org .testcontainers .containers .wait .strategy .Wait ;
43
41
44
42
import org .springframework .boot .buildpack .platform .docker .DockerApi ;
45
43
import org .springframework .boot .buildpack .platform .docker .type .ImageName ;
@@ -70,13 +68,10 @@ void buildsImageWithDefaultBuilder() throws IOException {
70
68
String projectName = this .gradleBuild .getProjectDir ().getName ();
71
69
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
72
70
assertThat (result .getOutput ()).contains ("docker.io/library/" + projectName );
73
- ImageReference imageReference = ImageReference .of (ImageName .of (projectName ));
74
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
75
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
76
- }
77
- finally {
78
- new DockerApi ().image ().remove (imageReference , false );
79
- }
71
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" );
72
+ assertThat (result .getOutput ()).contains ("env: BP_JVM_VERSION=8.*" );
73
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack done" );
74
+ removeImage (projectName );
80
75
}
81
76
82
77
@ TestTemplate
@@ -88,16 +83,13 @@ void buildsImageWithWarPackaging() throws IOException {
88
83
String projectName = this .gradleBuild .getProjectDir ().getName ();
89
84
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
90
85
assertThat (result .getOutput ()).contains ("docker.io/library/" + projectName );
86
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" );
87
+ assertThat (result .getOutput ()).contains ("env: BP_JVM_VERSION=8.*" );
88
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack done" );
91
89
File buildLibs = new File (this .gradleBuild .getProjectDir (), "build/libs" );
92
90
assertThat (buildLibs .listFiles ())
93
91
.containsExactly (new File (buildLibs , this .gradleBuild .getProjectDir ().getName () + ".war" ));
94
- ImageReference imageReference = ImageReference .of (ImageName .of (projectName ));
95
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
96
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
97
- }
98
- finally {
99
- new DockerApi ().image ().remove (imageReference , false );
100
- }
92
+ removeImage (projectName );
101
93
}
102
94
103
95
@ TestTemplate
@@ -108,16 +100,12 @@ void buildsImageWithWarPackagingAndJarConfiguration() throws IOException {
108
100
String projectName = this .gradleBuild .getProjectDir ().getName ();
109
101
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
110
102
assertThat (result .getOutput ()).contains ("docker.io/library/" + projectName );
103
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" );
104
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack done" );
111
105
File buildLibs = new File (this .gradleBuild .getProjectDir (), "build/libs" );
112
106
assertThat (buildLibs .listFiles ())
113
107
.containsExactly (new File (buildLibs , this .gradleBuild .getProjectDir ().getName () + ".war" ));
114
- ImageReference imageReference = ImageReference .of (ImageName .of (projectName ));
115
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
116
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
117
- }
118
- finally {
119
- new DockerApi ().image ().remove (imageReference , false );
120
- }
108
+ removeImage (projectName );
121
109
}
122
110
123
111
@ TestTemplate
@@ -127,13 +115,9 @@ void buildsImageWithCustomName() throws IOException {
127
115
BuildResult result = this .gradleBuild .build ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" );
128
116
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
129
117
assertThat (result .getOutput ()).contains ("example/test-image-name" );
130
- ImageReference imageReference = ImageReference .of (ImageName .of ("example/test-image-name" ));
131
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
132
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
133
- }
134
- finally {
135
- new DockerApi ().image ().remove (imageReference , false );
136
- }
118
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" );
119
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack done" );
120
+ removeImage ("example/test-image-name" );
137
121
}
138
122
139
123
@ TestTemplate
@@ -143,56 +127,38 @@ void buildsImageWithCustomBuilderAndRunImage() throws IOException {
143
127
BuildResult result = this .gradleBuild .build ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" );
144
128
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
145
129
assertThat (result .getOutput ()).contains ("example/test-image-custom" );
146
- ImageReference imageReference = ImageReference .of (ImageName .of ("example/test-image-custom" ));
147
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
148
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
149
- }
150
- finally {
151
- new DockerApi ().image ().remove (imageReference , false );
152
- }
130
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" );
131
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack done" );
132
+ removeImage ("example/test-image-custom" );
153
133
}
154
134
155
135
@ TestTemplate
156
136
void buildsImageWithCommandLineOptions () throws IOException {
157
137
writeMainClass ();
158
138
writeLongNameResource ();
159
139
BuildResult result = this .gradleBuild .build ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" ,
160
- "--imageName=example/test-image-cmd" , "--builder=paketobuildpacks/builder:full" ,
161
- "--runImage=paketobuildpacks/run:full-cnb" );
140
+ "--imageName=example/test-image-cmd" ,
141
+ "--builder=projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" ,
142
+ "--runImage=projects.registry.vmware.com/springboot/run:tiny-cnb" );
162
143
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
163
144
assertThat (result .getOutput ()).contains ("example/test-image-cmd" );
164
- ImageReference imageReference = ImageReference .of (ImageName .of ("example/test-image-cmd" ));
165
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
166
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
167
- }
168
- finally {
169
- new DockerApi ().image ().remove (imageReference , false );
170
- }
145
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" );
146
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack done" );
147
+ removeImage ("example/test-image-cmd" );
171
148
}
172
149
173
150
@ TestTemplate
174
151
void buildsImageWithPullPolicy () throws IOException {
175
152
writeMainClass ();
176
153
writeLongNameResource ();
177
154
String projectName = this .gradleBuild .getProjectDir ().getName ();
178
- ImageReference imageReference = ImageReference .of (ImageName .of (projectName ));
179
-
180
155
BuildResult result = this .gradleBuild .build ("bootBuildImage" , "--pullPolicy=ALWAYS" );
181
156
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
182
157
assertThat (result .getOutput ()).contains ("Pulled builder image" ).contains ("Pulled run image" );
183
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
184
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
185
- }
186
-
187
158
result = this .gradleBuild .build ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" );
188
159
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
189
160
assertThat (result .getOutput ()).doesNotContain ("Pulled builder image" ).doesNotContain ("Pulled run image" );
190
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
191
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
192
- }
193
- finally {
194
- new DockerApi ().image ().remove (imageReference , false );
195
- }
161
+ removeImage (projectName );
196
162
}
197
163
198
164
@ TestTemplate
@@ -203,13 +169,9 @@ void buildsImageWithBuildpackFromBuilder() throws IOException {
203
169
String projectName = this .gradleBuild .getProjectDir ().getName ();
204
170
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
205
171
assertThat (result .getOutput ()).contains ("docker.io/library/" + projectName );
206
- ImageReference imageReference = ImageReference .of (ImageName .of (projectName ));
207
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
208
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
209
- }
210
- finally {
211
- new DockerApi ().image ().remove (imageReference , false );
212
- }
172
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" )
173
+ .contains ("---> Test Info buildpack done" );
174
+ removeImage (projectName );
213
175
}
214
176
215
177
@ TestTemplate
@@ -220,11 +182,10 @@ void buildsImageWithBuildpackFromDirectory() throws IOException {
220
182
writeBuildpackContent ();
221
183
BuildResult result = this .gradleBuild .build ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" );
222
184
String projectName = this .gradleBuild .getProjectDir ().getName ();
223
- ImageReference imageReference = ImageReference .of (ImageName .of (projectName ));
224
185
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
225
186
assertThat (result .getOutput ()).contains ("docker.io/library/" + projectName );
226
187
assertThat (result .getOutput ()).contains ("---> Hello World buildpack" );
227
- new DockerApi (). image (). remove ( imageReference , false );
188
+ removeImage ( projectName );
228
189
}
229
190
230
191
@ TestTemplate
@@ -236,11 +197,10 @@ void buildsImageWithBuildpackFromTarGzip() throws IOException {
236
197
tarGzipBuildpackContent ();
237
198
BuildResult result = this .gradleBuild .build ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" );
238
199
String projectName = this .gradleBuild .getProjectDir ().getName ();
239
- ImageReference imageReference = ImageReference .of (ImageName .of (projectName ));
240
200
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
241
201
assertThat (result .getOutput ()).contains ("docker.io/library/" + projectName );
242
202
assertThat (result .getOutput ()).contains ("---> Hello World buildpack" );
243
- new DockerApi (). image (). remove ( imageReference , false );
203
+ removeImage ( projectName );
244
204
}
245
205
246
206
@ TestTemplate
@@ -251,24 +211,26 @@ void buildsImageWithBuildpacksFromImages() throws IOException {
251
211
String projectName = this .gradleBuild .getProjectDir ().getName ();
252
212
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
253
213
assertThat (result .getOutput ()).contains ("docker.io/library/" + projectName );
254
- ImageReference imageReference = ImageReference .of (ImageName .of (projectName ));
255
- try (GenericContainer <?> container = new GenericContainer <>(imageReference .toString ())) {
256
- container .waitingFor (Wait .forLogMessage ("Launched\\ n" , 1 )).start ();
257
- }
258
- finally {
259
- new DockerApi ().image ().remove (imageReference , false );
260
- }
214
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" )
215
+ .contains ("---> Test Info buildpack done" );
216
+ removeImage (projectName );
261
217
}
262
218
263
219
@ TestTemplate
264
- void failsWithBindingContainingInvalidCertificate () throws IOException {
220
+ void buildsImageWithBinding () throws IOException {
265
221
writeMainClass ();
266
222
writeLongNameResource ();
267
223
writeCertificateBindingFiles ();
268
- BuildResult result = this .gradleBuild .buildAndFail ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" );
269
- assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .FAILED );
270
- assertThat (result .getOutput ()).contains ("failed to decode certificate" )
271
- .contains ("/platform/bindings/certificates/test.crt" );
224
+ BuildResult result = this .gradleBuild .build ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" );
225
+ String projectName = this .gradleBuild .getProjectDir ().getName ();
226
+ assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .SUCCESS );
227
+ assertThat (result .getOutput ()).contains ("docker.io/library/" + projectName );
228
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack building" );
229
+ assertThat (result .getOutput ()).contains ("binding: certificates/type=ca-certificates" );
230
+ assertThat (result .getOutput ()).contains ("binding: certificates/test1.crt=---certificate one---" );
231
+ assertThat (result .getOutput ()).contains ("binding: certificates/test2.crt=---certificate two---" );
232
+ assertThat (result .getOutput ()).contains ("---> Test Info buildpack done" );
233
+ removeImage (projectName );
272
234
}
273
235
274
236
@ TestTemplate
@@ -286,6 +248,7 @@ void failsWithBuilderError() throws IOException {
286
248
writeLongNameResource ();
287
249
BuildResult result = this .gradleBuild .buildAndFail ("bootBuildImage" , "--pullPolicy=IF_NOT_PRESENT" );
288
250
assertThat (result .task (":bootBuildImage" ).getOutcome ()).isEqualTo (TaskOutcome .FAILED );
251
+ assertThat (result .getOutput ()).contains ("Forced builder failure" );
289
252
assertThat (result .getOutput ()).containsPattern ("Builder lifecycle '.*' failed with status code" );
290
253
}
291
254
@@ -410,10 +373,19 @@ private void writeCertificateBindingFiles() throws IOException {
410
373
try (PrintWriter writer = new PrintWriter (new FileWriter (type ))) {
411
374
writer .print ("ca-certificates" );
412
375
}
413
- File cert = new File (bindingDir , "test .crt" );
414
- try (PrintWriter writer = new PrintWriter (new FileWriter (cert ))) {
415
- writer .println ("not a valid certificate" );
376
+ File cert1 = new File (bindingDir , "test1 .crt" );
377
+ try (PrintWriter writer = new PrintWriter (new FileWriter (cert1 ))) {
378
+ writer .println ("--- certificate one--- " );
416
379
}
380
+ File cert2 = new File (bindingDir , "test2.crt" );
381
+ try (PrintWriter writer = new PrintWriter (new FileWriter (cert2 ))) {
382
+ writer .println ("---certificate two---" );
383
+ }
384
+ }
385
+
386
+ private void removeImage (String name ) throws IOException {
387
+ ImageReference imageReference = ImageReference .of (ImageName .of (name ));
388
+ new DockerApi ().image ().remove (imageReference , false );
417
389
}
418
390
419
391
}
0 commit comments