Fix LifecycleTests for security options on Windows

Fixes gh-37598
pull/37612/head
Scott Frederick 1 year ago
parent 8fec430347
commit 9811cc030f

@ -262,7 +262,7 @@ class LifecycleTests {
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
BuildRequest request = getTestRequest().withSecurityOptions(List.of("label=user:USER", "label=role:ROLE"));
createLifecycle(request).execute();
assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-security-opts.json"));
assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-security-opts.json", true));
assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
}
@ -370,12 +370,16 @@ class LifecycleTests {
}
private IOConsumer<ContainerConfig> withExpectedConfig(String name) {
return withExpectedConfig(name, false);
}
private IOConsumer<ContainerConfig> withExpectedConfig(String name, boolean expectSecurityOptAlways) {
return (config) -> {
try {
InputStream in = getClass().getResourceAsStream(name);
String jsonString = FileCopyUtils.copyToString(new InputStreamReader(in, StandardCharsets.UTF_8));
JSONObject json = new JSONObject(jsonString);
if (Platform.isWindows()) {
if (!expectSecurityOptAlways && Platform.isWindows()) {
JSONObject hostConfig = json.getJSONObject("HostConfig");
hostConfig.remove("SecurityOpt");
}

Loading…
Cancel
Save