Make consistent use of Property for Gradle task configuration
Closes gh-32769
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -58,6 +58,7 @@ class IntegratingWithActuatorDocumentationTests {
|
||||
assertThat(properties).containsEntry("build.version", "1.2.3");
|
||||
assertThat(properties).containsEntry("build.group", "com.example");
|
||||
assertThat(properties).containsEntry("build.name", "Example application");
|
||||
assertThat(properties).containsKey("build.time");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -71,6 +72,16 @@ class IntegratingWithActuatorDocumentationTests {
|
||||
assertThat(properties).containsEntry("build.b", "bravo");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void buildInfoExcludeTime() {
|
||||
this.gradleBuild.script("src/docs/gradle/integrating-with-actuator/build-info-exclude-time")
|
||||
.build("bootBuildInfo");
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
|
||||
assertThat(file).isFile();
|
||||
Properties properties = buildInfoProperties(file);
|
||||
assertThat(properties).doesNotContainKey("build.time");
|
||||
}
|
||||
|
||||
private Properties buildInfoProperties(File file) {
|
||||
assertThat(file).isFile();
|
||||
Properties properties = new Properties();
|
||||
|
||||
@@ -112,7 +112,7 @@ class BuildInfoIntegrationTests {
|
||||
void reproducibleOutputWithFixedTime() throws IOException, InterruptedException {
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
File buildInfoProperties = new File(this.gradleBuild.getProjectDir(), "build/build-info.properties");
|
||||
File buildInfoProperties = new File(this.gradleBuild.getProjectDir(), "build/buildInfo/build-info.properties");
|
||||
String firstHash = FileUtils.sha1Hash(buildInfoProperties);
|
||||
assertThat(buildInfoProperties.delete()).isTrue();
|
||||
Thread.sleep(1500);
|
||||
@@ -123,17 +123,7 @@ class BuildInfoIntegrationTests {
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void removePropertiesUsingNulls() {
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties buildInfoProperties = buildInfoProperties();
|
||||
assertThat(buildInfoProperties).doesNotContainKey("build.group");
|
||||
assertThat(buildInfoProperties).doesNotContainKey("build.artifact");
|
||||
assertThat(buildInfoProperties).doesNotContainKey("build.version");
|
||||
assertThat(buildInfoProperties).doesNotContainKey("build.name");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void removePropertiesUsingEmptyStrings() {
|
||||
void excludeProperties() {
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties buildInfoProperties = buildInfoProperties();
|
||||
assertThat(buildInfoProperties).doesNotContainKey("build.group");
|
||||
@@ -143,7 +133,7 @@ class BuildInfoIntegrationTests {
|
||||
}
|
||||
|
||||
private Properties buildInfoProperties() {
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/build-info.properties");
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/buildInfo/build-info.properties");
|
||||
assertThat(file).isFile();
|
||||
Properties properties = new Properties();
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
|
||||
@@ -60,21 +60,14 @@ class BuildInfoTests {
|
||||
@Test
|
||||
void customArtifactIsReflectedInProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setArtifact("custom");
|
||||
task.getProperties().getArtifact().set("custom");
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.artifact", "custom");
|
||||
}
|
||||
|
||||
@Test
|
||||
void artifactCanBeRemovedFromPropertiesUsingNull() {
|
||||
void artifactCanBeExcludedFromProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setArtifact(null);
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.artifact");
|
||||
}
|
||||
|
||||
@Test
|
||||
void artifactCanBeRemovedFromPropertiesUsingEmptyString() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setArtifact("");
|
||||
task.getExcludes().addAll("artifact");
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.artifact");
|
||||
}
|
||||
|
||||
@@ -88,42 +81,28 @@ class BuildInfoTests {
|
||||
@Test
|
||||
void customGroupIsReflectedInProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setGroup("com.example");
|
||||
task.getProperties().getGroup().set("com.example");
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.group", "com.example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void groupCanBeRemovedFromPropertiesUsingNull() {
|
||||
void groupCanBeExcludedFromProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setGroup(null);
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.group");
|
||||
}
|
||||
|
||||
@Test
|
||||
void groupCanBeRemovedFromPropertiesUsingEmptyString() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setGroup("");
|
||||
task.getExcludes().add("group");
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.group");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customNameIsReflectedInProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setName("Example");
|
||||
task.getProperties().getName().set("Example");
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.name", "Example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameCanBeRemovedFromPropertiesUsingNull() {
|
||||
void nameCanBeExludedRemovedFromProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setName(null);
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameCanBeRemovedFromPropertiesUsingEmptyString() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setName("");
|
||||
task.getExcludes().add("name");
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.name");
|
||||
}
|
||||
|
||||
@@ -137,45 +116,36 @@ class BuildInfoTests {
|
||||
@Test
|
||||
void customVersionIsReflectedInProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setVersion("2.3.4");
|
||||
task.getProperties().getVersion().set("2.3.4");
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.version", "2.3.4");
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionCanBeRemovedFromPropertiesUsingNull() {
|
||||
void versionCanBeExcludedFromProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setVersion(null);
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.version");
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionCanBeRemovedFromPropertiesUsingEmptyString() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setVersion("");
|
||||
task.getExcludes().add("version");
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.version");
|
||||
}
|
||||
|
||||
@Test
|
||||
void timeIsSetInProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.time",
|
||||
DateTimeFormatter.ISO_INSTANT.format(task.getProperties().getTime()));
|
||||
assertThat(buildInfoProperties(task)).containsKey("build.time");
|
||||
}
|
||||
|
||||
@Test
|
||||
void timeCanBeRemovedFromProperties() {
|
||||
void timeCanBeExcludedFromProperties() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setTime(null);
|
||||
task.getExcludes().add("time");
|
||||
assertThat(buildInfoProperties(task)).doesNotContainKey("build.time");
|
||||
}
|
||||
|
||||
@Test
|
||||
void timeCanBeCustomizedInProperties() {
|
||||
Instant now = Instant.now();
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setTime(now);
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.time",
|
||||
DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(now.toEpochMilli())));
|
||||
String isoTime = DateTimeFormatter.ISO_INSTANT.format(Instant.now());
|
||||
task.getProperties().getTime().set(isoTime);
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.time", isoTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,16 +153,22 @@ class BuildInfoTests {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().getAdditional().put("a", "alpha");
|
||||
task.getProperties().getAdditional().put("b", "bravo");
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.a", "alpha");
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.b", "bravo");
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.a", "alpha").containsEntry("build.b", "bravo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void additionalPropertiesCanBeExcluded() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().getAdditional().put("a", "alpha");
|
||||
task.getExcludes().add("b");
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.a", "alpha").doesNotContainKey("b");
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullAdditionalPropertyProducesInformativeFailure() {
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().getAdditional().put("a", null);
|
||||
assertThatThrownBy(() -> buildInfoProperties(task))
|
||||
.hasMessage("Additional property 'a' is illegal as its value is null");
|
||||
assertThatThrownBy(() -> task.getProperties().getAdditional().put("a", null))
|
||||
.hasMessage("Cannot add an entry with a null value to a property of type Map.");
|
||||
}
|
||||
|
||||
private Project createProject(String projectName) {
|
||||
@@ -209,7 +185,7 @@ class BuildInfoTests {
|
||||
|
||||
private Properties buildInfoProperties(BuildInfo task) {
|
||||
task.generateBuildProperties();
|
||||
return buildInfoProperties(new File(task.getDestinationDir(), "build-info.properties"));
|
||||
return buildInfoProperties(new File(task.getDestinationDir().get().getAsFile(), "build-info.properties"));
|
||||
}
|
||||
|
||||
private Properties buildInfoProperties(File file) {
|
||||
|
||||
@@ -451,7 +451,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
@Test
|
||||
void jarWhenLayersDisabledShouldNotContainLayersIndex() throws IOException {
|
||||
List<String> entryNames = getEntryNames(createLayeredJar((configuration) -> configuration.setEnabled(false)));
|
||||
List<String> entryNames = getEntryNames(
|
||||
createLayeredJar((configuration) -> configuration.getEnabled().set(false)));
|
||||
assertThat(entryNames).doesNotContain(this.indexPath + "layers.idx");
|
||||
}
|
||||
|
||||
@@ -519,7 +520,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
dependencies.intoLayer("my-internal-deps", (spec) -> spec.include("com.example:*:*"));
|
||||
dependencies.intoLayer("my-deps");
|
||||
});
|
||||
layered.setLayerOrder("my-deps", "my-internal-deps", "my-snapshot-deps", "resources", "application");
|
||||
layered.getLayerOrder()
|
||||
.set(List.of("my-deps", "my-internal-deps", "my-snapshot-deps", "resources", "application"));
|
||||
});
|
||||
try (JarFile jarFile = new JarFile(jar)) {
|
||||
List<String> entryNames = getEntryNames(jar);
|
||||
@@ -567,7 +569,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
@Test
|
||||
void whenArchiveIsLayeredAndIncludeLayerToolsIsFalseThenLayerToolsAreNotAddedToTheJar() throws IOException {
|
||||
List<String> entryNames = getEntryNames(
|
||||
createLayeredJar((configuration) -> configuration.setIncludeLayerTools(false)));
|
||||
createLayeredJar((configuration) -> configuration.getIncludeLayerTools().set(false)));
|
||||
assertThat(entryNames)
|
||||
.doesNotContain(this.indexPath + "layers/dependencies/lib/spring-boot-jarmode-layertools.jar");
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenProjectVersionIsUnspecifiedThenItIsIgnoredWhenDerivingImageName() {
|
||||
assertThat(this.buildImage.getImageName()).isEqualTo("docker.io/library/build-image-test");
|
||||
assertThat(this.buildImage.getImageName().get()).isEqualTo("docker.io/library/build-image-test");
|
||||
BuildRequest request = this.buildImage.createRequest();
|
||||
assertThat(request.getName().getDomain()).isEqualTo("docker.io");
|
||||
assertThat(request.getName().getName()).isEqualTo("library/build-image-test");
|
||||
@@ -73,7 +73,7 @@ class BootBuildImageTests {
|
||||
@Test
|
||||
void whenProjectVersionIsSpecifiedThenItIsUsedInTagOfImageName() {
|
||||
this.project.setVersion("1.2.3");
|
||||
assertThat(this.buildImage.getImageName()).isEqualTo("docker.io/library/build-image-test:1.2.3");
|
||||
assertThat(this.buildImage.getImageName().get()).isEqualTo("docker.io/library/build-image-test:1.2.3");
|
||||
BuildRequest request = this.buildImage.createRequest();
|
||||
assertThat(request.getName().getDomain()).isEqualTo("docker.io");
|
||||
assertThat(request.getName().getName()).isEqualTo("library/build-image-test");
|
||||
@@ -84,8 +84,8 @@ class BootBuildImageTests {
|
||||
@Test
|
||||
void whenImageNameIsSpecifiedThenItIsUsedInRequest() {
|
||||
this.project.setVersion("1.2.3");
|
||||
this.buildImage.setImageName("example.com/test/build-image:1.0");
|
||||
assertThat(this.buildImage.getImageName()).isEqualTo("example.com/test/build-image:1.0");
|
||||
this.buildImage.getImageName().set("example.com/test/build-image:1.0");
|
||||
assertThat(this.buildImage.getImageName().get()).isEqualTo("example.com/test/build-image:1.0");
|
||||
BuildRequest request = this.buildImage.createRequest();
|
||||
assertThat(request.getName().getDomain()).isEqualTo("example.com");
|
||||
assertThat(request.getName().getName()).isEqualTo("test/build-image");
|
||||
@@ -102,8 +102,8 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenIndividualEntriesAreAddedToTheEnvironmentThenTheyAreIncludedInTheRequest() {
|
||||
this.buildImage.environment("ALPHA", "a");
|
||||
this.buildImage.environment("BRAVO", "b");
|
||||
this.buildImage.getEnvironment().put("ALPHA", "a");
|
||||
this.buildImage.getEnvironment().put("BRAVO", "b");
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("ALPHA", "a").containsEntry("BRAVO", "b")
|
||||
.hasSize(2);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ class BootBuildImageTests {
|
||||
Map<String, String> environment = new HashMap<>();
|
||||
environment.put("ALPHA", "a");
|
||||
environment.put("BRAVO", "b");
|
||||
this.buildImage.environment(environment);
|
||||
this.buildImage.getEnvironment().putAll(environment);
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("ALPHA", "a").containsEntry("BRAVO", "b")
|
||||
.hasSize(2);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ class BootBuildImageTests {
|
||||
Map<String, String> environment = new HashMap<>();
|
||||
environment.put("ALPHA", "a");
|
||||
environment.put("BRAVO", "b");
|
||||
this.buildImage.setEnvironment(environment);
|
||||
this.buildImage.getEnvironment().set(environment);
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("ALPHA", "a").containsEntry("BRAVO", "b")
|
||||
.hasSize(2);
|
||||
}
|
||||
@@ -133,15 +133,15 @@ class BootBuildImageTests {
|
||||
Map<String, String> environment = new HashMap<>();
|
||||
environment.put("ALPHA", "a");
|
||||
environment.put("BRAVO", "b");
|
||||
this.buildImage.environment("C", "Charlie");
|
||||
this.buildImage.setEnvironment(environment);
|
||||
this.buildImage.getEnvironment().put("C", "Charlie");
|
||||
this.buildImage.getEnvironment().set(environment);
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("ALPHA", "a").containsEntry("BRAVO", "b")
|
||||
.hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenJavaVersionIsSetInEnvironmentItIsIncludedInTheRequest() {
|
||||
this.buildImage.environment("BP_JVM_VERSION", "from-env");
|
||||
this.buildImage.getEnvironment().put("BP_JVM_VERSION", "from-env");
|
||||
this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_1_8);
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JVM_VERSION", "from-env").hasSize(1);
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenTargetCompatibilityIsSetThenJavaVersionIsAddedToEnvironment() {
|
||||
this.buildImage.environment("ALPHA", "a");
|
||||
this.buildImage.getEnvironment().put("ALPHA", "a");
|
||||
this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_11);
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("ALPHA", "a")
|
||||
.containsEntry("BP_JVM_VERSION", "11.*").hasSize(2);
|
||||
@@ -167,7 +167,7 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenVerboseLoggingIsEnabledThenRequestHasVerboseLoggingEnabled() {
|
||||
this.buildImage.setVerboseLogging(true);
|
||||
this.buildImage.getVerboseLogging().set(true);
|
||||
assertThat(this.buildImage.createRequest().isVerboseLogging()).isTrue();
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenCleanCacheIsEnabledThenRequestHasCleanCacheEnabled() {
|
||||
this.buildImage.setCleanCache(true);
|
||||
this.buildImage.getCleanCache().set(true);
|
||||
assertThat(this.buildImage.createRequest().isCleanCache()).isTrue();
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenBuilderIsConfiguredThenRequestUsesSpecifiedBuilder() {
|
||||
this.buildImage.setBuilder("example.com/test/builder:1.2");
|
||||
this.buildImage.getBuilder().set("example.com/test/builder:1.2");
|
||||
assertThat(this.buildImage.createRequest().getBuilder().getName()).isEqualTo("test/builder");
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenRunImageIsConfiguredThenRequestUsesSpecifiedRunImage() {
|
||||
this.buildImage.setRunImage("example.com/test/run:1.0");
|
||||
this.buildImage.getRunImage().set("example.com/test/run:1.0");
|
||||
assertThat(this.buildImage.createRequest().getRunImage().getName()).isEqualTo("test/run");
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenPullPolicyIsConfiguredThenRequestHasPullPolicy() {
|
||||
this.buildImage.setPullPolicy(PullPolicy.NEVER);
|
||||
this.buildImage.getPullPolicy().set(PullPolicy.NEVER);
|
||||
assertThat(this.buildImage.createRequest().getPullPolicy()).isEqualTo(PullPolicy.NEVER);
|
||||
}
|
||||
|
||||
@@ -227,22 +227,22 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenBuildpacksAreConfiguredThenRequestHasBuildpacks() {
|
||||
this.buildImage.setBuildpacks(Arrays.asList("example/buildpack1", "example/buildpack2"));
|
||||
this.buildImage.getBuildpacks().set(Arrays.asList("example/buildpack1", "example/buildpack2"));
|
||||
assertThat(this.buildImage.createRequest().getBuildpacks()).containsExactly(
|
||||
BuildpackReference.of("example/buildpack1"), BuildpackReference.of("example/buildpack2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenEntriesAreAddedToBuildpacksThenRequestHasBuildpacks() {
|
||||
this.buildImage.buildpacks(Arrays.asList("example/buildpack1", "example/buildpack2"));
|
||||
this.buildImage.getBuildpacks().addAll(Arrays.asList("example/buildpack1", "example/buildpack2"));
|
||||
assertThat(this.buildImage.createRequest().getBuildpacks()).containsExactly(
|
||||
BuildpackReference.of("example/buildpack1"), BuildpackReference.of("example/buildpack2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenIndividualEntriesAreAddedToBuildpacksThenRequestHasBuildpacks() {
|
||||
this.buildImage.buildpack("example/buildpack1");
|
||||
this.buildImage.buildpack("example/buildpack2");
|
||||
this.buildImage.getBuildpacks().add("example/buildpack1");
|
||||
this.buildImage.getBuildpacks().add("example/buildpack2");
|
||||
assertThat(this.buildImage.createRequest().getBuildpacks()).containsExactly(
|
||||
BuildpackReference.of("example/buildpack1"), BuildpackReference.of("example/buildpack2"));
|
||||
}
|
||||
@@ -254,29 +254,30 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenBindingsAreConfiguredThenRequestHasBindings() {
|
||||
this.buildImage.setBindings(Arrays.asList("host-src:container-dest:ro", "volume-name:container-dest:rw"));
|
||||
this.buildImage.getBindings().set(Arrays.asList("host-src:container-dest:ro", "volume-name:container-dest:rw"));
|
||||
assertThat(this.buildImage.createRequest().getBindings())
|
||||
.containsExactly(Binding.of("host-src:container-dest:ro"), Binding.of("volume-name:container-dest:rw"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenEntriesAreAddedToBindingsThenRequestHasBindings() {
|
||||
this.buildImage.bindings(Arrays.asList("host-src:container-dest:ro", "volume-name:container-dest:rw"));
|
||||
this.buildImage.getBindings()
|
||||
.addAll(Arrays.asList("host-src:container-dest:ro", "volume-name:container-dest:rw"));
|
||||
assertThat(this.buildImage.createRequest().getBindings())
|
||||
.containsExactly(Binding.of("host-src:container-dest:ro"), Binding.of("volume-name:container-dest:rw"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenIndividualEntriesAreAddedToBindingsThenRequestHasBindings() {
|
||||
this.buildImage.binding("host-src:container-dest:ro");
|
||||
this.buildImage.binding("volume-name:container-dest:rw");
|
||||
this.buildImage.getBindings().add("host-src:container-dest:ro");
|
||||
this.buildImage.getBindings().add("volume-name:container-dest:rw");
|
||||
assertThat(this.buildImage.createRequest().getBindings())
|
||||
.containsExactly(Binding.of("host-src:container-dest:ro"), Binding.of("volume-name:container-dest:rw"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenNetworkIsConfiguredThenRequestHasNetwork() {
|
||||
this.buildImage.setNetwork("test");
|
||||
this.buildImage.getNetwork().set("test");
|
||||
assertThat(this.buildImage.createRequest().getNetwork()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@@ -287,25 +288,25 @@ class BootBuildImageTests {
|
||||
|
||||
@Test
|
||||
void whenTagsAreConfiguredThenRequestHasTags() {
|
||||
this.buildImage.setTags(
|
||||
Arrays.asList("my-app:latest", "example.com/my-app:0.0.1-SNAPSHOT", "example.com/my-app:latest"));
|
||||
this.buildImage.getTags()
|
||||
.set(Arrays.asList("my-app:latest", "example.com/my-app:0.0.1-SNAPSHOT", "example.com/my-app:latest"));
|
||||
assertThat(this.buildImage.createRequest().getTags()).containsExactly(ImageReference.of("my-app:latest"),
|
||||
ImageReference.of("example.com/my-app:0.0.1-SNAPSHOT"), ImageReference.of("example.com/my-app:latest"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenEntriesAreAddedToTagsThenRequestHasTags() {
|
||||
this.buildImage
|
||||
.tags(Arrays.asList("my-app:latest", "example.com/my-app:0.0.1-SNAPSHOT", "example.com/my-app:latest"));
|
||||
this.buildImage.getTags().addAll(
|
||||
Arrays.asList("my-app:latest", "example.com/my-app:0.0.1-SNAPSHOT", "example.com/my-app:latest"));
|
||||
assertThat(this.buildImage.createRequest().getTags()).containsExactly(ImageReference.of("my-app:latest"),
|
||||
ImageReference.of("example.com/my-app:0.0.1-SNAPSHOT"), ImageReference.of("example.com/my-app:latest"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenIndividualEntriesAreAddedToTagsThenRequestHasTags() {
|
||||
this.buildImage.tag("my-app:latest");
|
||||
this.buildImage.tag("example.com/my-app:0.0.1-SNAPSHOT");
|
||||
this.buildImage.tag("example.com/my-app:latest");
|
||||
this.buildImage.getTags().add("my-app:latest");
|
||||
this.buildImage.getTags().add("example.com/my-app:0.0.1-SNAPSHOT");
|
||||
this.buildImage.getTags().add("example.com/my-app:latest");
|
||||
assertThat(this.buildImage.createRequest().getTags()).containsExactly(ImageReference.of("my-app:latest"),
|
||||
ImageReference.of("example.com/my-app:0.0.1-SNAPSHOT"), ImageReference.of("example.com/my-app:latest"));
|
||||
}
|
||||
|
||||
@@ -16,11 +16,16 @@
|
||||
|
||||
package org.springframework.boot.gradle.tasks.bundling;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.gradle.api.GradleException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration;
|
||||
import org.springframework.boot.buildpack.platform.docker.configuration.DockerHost;
|
||||
import org.springframework.boot.gradle.junit.GradleProjectBuilder;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -34,10 +39,17 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*/
|
||||
class DockerSpecTests {
|
||||
|
||||
private DockerSpec dockerSpec;
|
||||
|
||||
@BeforeEach
|
||||
void prepareDockerSpec(@TempDir File temp) {
|
||||
this.dockerSpec = GradleProjectBuilder.builder().withProjectDir(temp).build().getObjects()
|
||||
.newInstance(DockerSpec.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithDefaults() {
|
||||
DockerSpec dockerSpec = new DockerSpec();
|
||||
DockerConfiguration dockerConfiguration = dockerSpec.asDockerConfiguration();
|
||||
DockerConfiguration dockerConfiguration = this.dockerSpec.asDockerConfiguration();
|
||||
assertThat(dockerConfiguration.getHost()).isNull();
|
||||
assertThat(dockerConfiguration.getBuilderRegistryAuthentication()).isNull();
|
||||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()))
|
||||
@@ -47,17 +59,16 @@ class DockerSpecTests {
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithHostConfiguration() {
|
||||
DockerSpec dockerSpec = new DockerSpec();
|
||||
dockerSpec.setHost("docker.example.com");
|
||||
dockerSpec.setTlsVerify(true);
|
||||
dockerSpec.setCertPath("/tmp/ca-cert");
|
||||
DockerConfiguration dockerConfiguration = dockerSpec.asDockerConfiguration();
|
||||
this.dockerSpec.getHost().set("docker.example.com");
|
||||
this.dockerSpec.getTlsVerify().set(true);
|
||||
this.dockerSpec.getCertPath().set("/tmp/ca-cert");
|
||||
DockerConfiguration dockerConfiguration = this.dockerSpec.asDockerConfiguration();
|
||||
DockerHost host = dockerConfiguration.getHost();
|
||||
assertThat(host.getAddress()).isEqualTo("docker.example.com");
|
||||
assertThat(host.isSecure()).isEqualTo(true);
|
||||
assertThat(host.getCertificatePath()).isEqualTo("/tmp/ca-cert");
|
||||
assertThat(dockerConfiguration.isBindHostToBuilder()).isFalse();
|
||||
assertThat(dockerSpec.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull();
|
||||
assertThat(this.dockerSpec.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull();
|
||||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()))
|
||||
.contains("\"username\" : \"\"").contains("\"password\" : \"\"").contains("\"email\" : \"\"")
|
||||
.contains("\"serveraddress\" : \"\"");
|
||||
@@ -65,15 +76,14 @@ class DockerSpecTests {
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithHostConfigurationNoTlsVerify() {
|
||||
DockerSpec dockerSpec = new DockerSpec();
|
||||
dockerSpec.setHost("docker.example.com");
|
||||
DockerConfiguration dockerConfiguration = dockerSpec.asDockerConfiguration();
|
||||
this.dockerSpec.getHost().set("docker.example.com");
|
||||
DockerConfiguration dockerConfiguration = this.dockerSpec.asDockerConfiguration();
|
||||
DockerHost host = dockerConfiguration.getHost();
|
||||
assertThat(host.getAddress()).isEqualTo("docker.example.com");
|
||||
assertThat(host.isSecure()).isEqualTo(false);
|
||||
assertThat(host.getCertificatePath()).isNull();
|
||||
assertThat(dockerConfiguration.isBindHostToBuilder()).isFalse();
|
||||
assertThat(dockerSpec.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull();
|
||||
assertThat(this.dockerSpec.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull();
|
||||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()))
|
||||
.contains("\"username\" : \"\"").contains("\"password\" : \"\"").contains("\"email\" : \"\"")
|
||||
.contains("\"serveraddress\" : \"\"");
|
||||
@@ -81,16 +91,15 @@ class DockerSpecTests {
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithBindHostToBuilder() {
|
||||
DockerSpec dockerSpec = new DockerSpec();
|
||||
dockerSpec.setHost("docker.example.com");
|
||||
dockerSpec.setBindHostToBuilder(true);
|
||||
DockerConfiguration dockerConfiguration = dockerSpec.asDockerConfiguration();
|
||||
this.dockerSpec.getHost().set("docker.example.com");
|
||||
this.dockerSpec.getBindHostToBuilder().set(true);
|
||||
DockerConfiguration dockerConfiguration = this.dockerSpec.asDockerConfiguration();
|
||||
DockerHost host = dockerConfiguration.getHost();
|
||||
assertThat(host.getAddress()).isEqualTo("docker.example.com");
|
||||
assertThat(host.isSecure()).isEqualTo(false);
|
||||
assertThat(host.getCertificatePath()).isNull();
|
||||
assertThat(dockerConfiguration.isBindHostToBuilder()).isTrue();
|
||||
assertThat(dockerSpec.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull();
|
||||
assertThat(this.dockerSpec.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull();
|
||||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()))
|
||||
.contains("\"username\" : \"\"").contains("\"password\" : \"\"").contains("\"email\" : \"\"")
|
||||
.contains("\"serveraddress\" : \"\"");
|
||||
@@ -98,12 +107,19 @@ class DockerSpecTests {
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithUserAuth() {
|
||||
DockerSpec dockerSpec = new DockerSpec(
|
||||
new DockerSpec.DockerRegistrySpec("user1", "secret1", "https://docker1.example.com",
|
||||
"docker1@example.com"),
|
||||
new DockerSpec.DockerRegistrySpec("user2", "secret2", "https://docker2.example.com",
|
||||
"docker2@example.com"));
|
||||
DockerConfiguration dockerConfiguration = dockerSpec.asDockerConfiguration();
|
||||
this.dockerSpec.builderRegistry((registry) -> {
|
||||
registry.getUsername().set("user1");
|
||||
registry.getPassword().set("secret1");
|
||||
registry.getUrl().set("https://docker1.example.com");
|
||||
registry.getEmail().set("docker1@example.com");
|
||||
});
|
||||
this.dockerSpec.publishRegistry((registry) -> {
|
||||
registry.getUsername().set("user2");
|
||||
registry.getPassword().set("secret2");
|
||||
registry.getUrl().set("https://docker2.example.com");
|
||||
registry.getEmail().set("docker2@example.com");
|
||||
});
|
||||
DockerConfiguration dockerConfiguration = this.dockerSpec.asDockerConfiguration();
|
||||
assertThat(decoded(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))
|
||||
.contains("\"username\" : \"user1\"").contains("\"password\" : \"secret1\"")
|
||||
.contains("\"email\" : \"docker1@example.com\"")
|
||||
@@ -112,32 +128,36 @@ class DockerSpecTests {
|
||||
.contains("\"username\" : \"user2\"").contains("\"password\" : \"secret2\"")
|
||||
.contains("\"email\" : \"docker2@example.com\"")
|
||||
.contains("\"serveraddress\" : \"https://docker2.example.com\"");
|
||||
assertThat(dockerSpec.asDockerConfiguration().getHost()).isNull();
|
||||
assertThat(this.dockerSpec.asDockerConfiguration().getHost()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithIncompleteBuilderUserAuthFails() {
|
||||
DockerSpec.DockerRegistrySpec builderRegistry = new DockerSpec.DockerRegistrySpec("user", null,
|
||||
"https://docker.example.com", "docker@example.com");
|
||||
DockerSpec dockerSpec = new DockerSpec(builderRegistry, null);
|
||||
assertThatExceptionOfType(GradleException.class).isThrownBy(dockerSpec::asDockerConfiguration)
|
||||
this.dockerSpec.builderRegistry((registry) -> {
|
||||
registry.getUsername().set("user1");
|
||||
registry.getUrl().set("https://docker1.example.com");
|
||||
registry.getEmail().set("docker1@example.com");
|
||||
});
|
||||
assertThatExceptionOfType(GradleException.class).isThrownBy(this.dockerSpec::asDockerConfiguration)
|
||||
.withMessageContaining("Invalid Docker builder registry configuration");
|
||||
}
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithIncompletePublishUserAuthFails() {
|
||||
DockerSpec.DockerRegistrySpec publishRegistry = new DockerSpec.DockerRegistrySpec("user2", null,
|
||||
"https://docker2.example.com", "docker2@example.com");
|
||||
DockerSpec dockerSpec = new DockerSpec(null, publishRegistry);
|
||||
assertThatExceptionOfType(GradleException.class).isThrownBy(dockerSpec::asDockerConfiguration)
|
||||
this.dockerSpec.publishRegistry((registry) -> {
|
||||
registry.getUsername().set("user2");
|
||||
registry.getUrl().set("https://docker2.example.com");
|
||||
registry.getEmail().set("docker2@example.com");
|
||||
});
|
||||
assertThatExceptionOfType(GradleException.class).isThrownBy(this.dockerSpec::asDockerConfiguration)
|
||||
.withMessageContaining("Invalid Docker publish registry configuration");
|
||||
}
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithTokenAuth() {
|
||||
DockerSpec dockerSpec = new DockerSpec(new DockerSpec.DockerRegistrySpec("token1"),
|
||||
new DockerSpec.DockerRegistrySpec("token2"));
|
||||
DockerConfiguration dockerConfiguration = dockerSpec.asDockerConfiguration();
|
||||
this.dockerSpec.builderRegistry((registry) -> registry.getToken().set("token1"));
|
||||
this.dockerSpec.publishRegistry((registry) -> registry.getToken().set("token2"));
|
||||
DockerConfiguration dockerConfiguration = this.dockerSpec.asDockerConfiguration();
|
||||
assertThat(decoded(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))
|
||||
.contains("\"identitytoken\" : \"token1\"");
|
||||
assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()))
|
||||
@@ -146,12 +166,12 @@ class DockerSpecTests {
|
||||
|
||||
@Test
|
||||
void asDockerConfigurationWithUserAndTokenAuthFails() {
|
||||
DockerSpec.DockerRegistrySpec builderRegistry = new DockerSpec.DockerRegistrySpec();
|
||||
builderRegistry.setUsername("user");
|
||||
builderRegistry.setPassword("secret");
|
||||
builderRegistry.setToken("token");
|
||||
DockerSpec dockerSpec = new DockerSpec(builderRegistry, null);
|
||||
assertThatExceptionOfType(GradleException.class).isThrownBy(dockerSpec::asDockerConfiguration)
|
||||
this.dockerSpec.builderRegistry((registry) -> {
|
||||
registry.getUsername().set("user");
|
||||
registry.getPassword().set("secret");
|
||||
registry.getToken().set("token");
|
||||
});
|
||||
assertThatExceptionOfType(GradleException.class).isThrownBy(this.dockerSpec::asDockerConfiguration)
|
||||
.withMessageContaining("Invalid Docker builder registry configuration");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user