Merge branch '2.3.x'

Closes gh-22180
This commit is contained in:
Andy Wilkinson
2020-07-01 11:44:00 +01:00
8 changed files with 80 additions and 23 deletions

View File

@@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* Tests for {@link BuildOwner}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
class BuildOwnerTests {
@@ -54,7 +55,7 @@ class BuildOwnerTests {
Map<String, String> env = new LinkedHashMap<>();
env.put("CNB_GROUP_ID", "456");
assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env))
.withMessage("Missing 'CNB_USER_ID' value from the builder environment");
.withMessage("Missing 'CNB_USER_ID' value from the builder environment '" + env + "'");
}
@Test
@@ -62,7 +63,7 @@ class BuildOwnerTests {
Map<String, String> env = new LinkedHashMap<>();
env.put("CNB_USER_ID", "123");
assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env))
.withMessage("Missing 'CNB_GROUP_ID' value from the builder environment");
.withMessage("Missing 'CNB_GROUP_ID' value from the builder environment '" + env + "'");
}
@Test
@@ -71,7 +72,7 @@ class BuildOwnerTests {
env.put("CNB_USER_ID", "nope");
env.put("CNB_GROUP_ID", "456");
assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env))
.withMessage("Malformed 'CNB_USER_ID' value 'nope' in the builder environment");
.withMessage("Malformed 'CNB_USER_ID' value 'nope' in the builder environment '" + env + "'");
}
@Test
@@ -80,7 +81,7 @@ class BuildOwnerTests {
env.put("CNB_USER_ID", "123");
env.put("CNB_GROUP_ID", "nope");
assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env))
.withMessage("Malformed 'CNB_GROUP_ID' value 'nope' in the builder environment");
.withMessage("Malformed 'CNB_GROUP_ID' value 'nope' in the builder environment '" + env + "'");
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.boot.buildpack.platform.build;
import java.io.IOException;
import java.util.Collections;
import org.junit.jupiter.api.Test;
@@ -34,6 +35,7 @@ import static org.mockito.Mockito.mock;
*
* @author Phillip Webb
* @author Scott Frederick
* @author Andy Wilkinson
*/
class BuilderMetadataTests extends AbstractJsonTests {
@@ -69,8 +71,9 @@ class BuilderMetadataTests extends AbstractJsonTests {
Image image = mock(Image.class);
ImageConfig imageConfig = mock(ImageConfig.class);
given(image.getConfig()).willReturn(imageConfig);
given(imageConfig.getLabels()).willReturn(Collections.singletonMap("alpha", "a"));
assertThatIllegalArgumentException().isThrownBy(() -> BuilderMetadata.fromImage(image))
.withMessage("No 'io.buildpacks.builder.metadata' label found in image config");
.withMessage("No 'io.buildpacks.builder.metadata' label found in image config labels 'alpha'");
}
@Test

View File

@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.entry;
* Tests for {@link ImageConfig}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
class ImageConfigTests extends AbstractJsonTests {
@@ -42,6 +43,20 @@ class ImageConfigTests extends AbstractJsonTests {
entry("CNB_STACK_ID", "org.cloudfoundry.stacks.cflinuxfs3"));
}
@Test
void whenConfigHasNoEnvThenImageConfigEnvIsEmpty() throws Exception {
ImageConfig imageConfig = getMinimalImageConfig();
Map<String, String> env = imageConfig.getEnv();
assertThat(env).isEmpty();
}
@Test
void whenConfigHasNoLabelsThenImageConfigLabelsIsEmpty() throws Exception {
ImageConfig imageConfig = getMinimalImageConfig();
Map<String, String> env = imageConfig.getLabels();
assertThat(env).isEmpty();
}
@Test
void getLabelsReturnsLabels() throws Exception {
ImageConfig imageConfig = getImageConfig();
@@ -63,4 +78,8 @@ class ImageConfigTests extends AbstractJsonTests {
return new ImageConfig(getObjectMapper().readTree(getContent("image-config.json")));
}
private ImageConfig getMinimalImageConfig() throws IOException {
return new ImageConfig(getObjectMapper().readTree(getContent("minimal-image-config.json")));
}
}

View File

@@ -0,0 +1,19 @@
{
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": null,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
}