From 257e236b06f276a40e52a0383d6256fecc7ad0e9 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Wed, 24 Aug 2022 13:14:39 -0500 Subject: [PATCH] Fix image-building unit tests on Windows See gh-32000 --- .../platform/build/LifecycleTests.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java index a641427c28ae..ed188ba520bb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java @@ -28,9 +28,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; +import com.sun.jna.Platform; +import org.json.JSONException; +import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; +import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.boot.buildpack.platform.docker.DockerApi; import org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi; @@ -318,9 +322,19 @@ private void assertPhaseWasRun(String name, IOConsumer configCo private IOConsumer withExpectedConfig(String name) { return (config) -> { - InputStream in = getClass().getResourceAsStream(name); - String json = FileCopyUtils.copyToString(new InputStreamReader(in, StandardCharsets.UTF_8)); - assertThat(config.toString()).isEqualToIgnoringWhitespace(json); + try { + InputStream in = getClass().getResourceAsStream(name); + String jsonString = FileCopyUtils.copyToString(new InputStreamReader(in, StandardCharsets.UTF_8)); + JSONObject json = new JSONObject(jsonString); + if (Platform.isWindows()) { + JSONObject hostConfig = json.getJSONObject("HostConfig"); + hostConfig.remove("SecurityOpt"); + } + JSONAssert.assertEquals(config.toString(), json, true); + } + catch (JSONException ex) { + throw new IOException(ex); + } }; }