Skip to content

Commit

Permalink
Fix image-building unit tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
scottfrederick committed Aug 24, 2022
1 parent 5f2f6d3 commit 257e236
Showing 1 changed file with 17 additions and 3 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -318,9 +322,19 @@ private void assertPhaseWasRun(String name, IOConsumer<ContainerConfig> configCo

private IOConsumer<ContainerConfig> 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);
}
};
}

Expand Down

0 comments on commit 257e236

Please sign in to comment.