Merge branch '3.4.x'

Closes gh-43718
This commit is contained in:
Phillip Webb
2025-01-07 19:23:01 -08:00
3 changed files with 105 additions and 26 deletions

View File

@@ -21,6 +21,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.boot.docker.compose.core.DockerCliCommand.ComposeVersion;
import org.springframework.boot.logging.LogLevel;
import static org.assertj.core.api.Assertions.assertThat;
@@ -34,11 +35,13 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class DockerCliCommandTests {
private static final ComposeVersion COMPOSE_VERSION = ComposeVersion.of("2.31.0");
@Test
void context() {
DockerCliCommand<?> command = new DockerCliCommand.Context();
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER);
assertThat(command.getCommand()).containsExactly("context", "ls", "--format={{ json . }}");
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("context", "ls", "--format={{ json . }}");
assertThat(command.deserialize("[]")).isInstanceOf(List.class);
}
@@ -46,7 +49,8 @@ class DockerCliCommandTests {
void inspect() {
DockerCliCommand<?> command = new DockerCliCommand.Inspect(List.of("123", "345"));
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER);
assertThat(command.getCommand()).containsExactly("inspect", "--format={{ json . }}", "123", "345");
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("inspect", "--format={{ json . }}", "123",
"345");
assertThat(command.deserialize("[]")).isInstanceOf(List.class);
}
@@ -54,7 +58,7 @@ class DockerCliCommandTests {
void composeConfig() {
DockerCliCommand<?> command = new DockerCliCommand.ComposeConfig();
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
assertThat(command.getCommand()).containsExactly("config", "--format=json");
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("config", "--format=json");
assertThat(command.deserialize("{}")).isInstanceOf(DockerCliComposeConfigResponse.class);
}
@@ -62,7 +66,15 @@ class DockerCliCommandTests {
void composePs() {
DockerCliCommand<?> command = new DockerCliCommand.ComposePs();
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
assertThat(command.getCommand()).containsExactly("ps", "--orphans=false", "--format=json");
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("ps", "--orphans=false", "--format=json");
assertThat(command.deserialize("[]")).isInstanceOf(List.class);
}
@Test
void composePsWhenLessThanV224() {
DockerCliCommand<?> command = new DockerCliCommand.ComposePs();
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
assertThat(command.getCommand(ComposeVersion.of("2.23"))).containsExactly("ps", "--format=json");
assertThat(command.deserialize("[]")).isInstanceOf(List.class);
}
@@ -71,7 +83,7 @@ class DockerCliCommandTests {
DockerCliCommand<?> command = new DockerCliCommand.ComposeUp(LogLevel.INFO, List.of("--renew-anon-volumes"));
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
assertThat(command.getLogLevel()).isEqualTo(LogLevel.INFO);
assertThat(command.getCommand()).containsExactly("up", "--no-color", "--detach", "--wait",
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("up", "--no-color", "--detach", "--wait",
"--renew-anon-volumes");
assertThat(command.deserialize("[]")).isNull();
}
@@ -81,7 +93,7 @@ class DockerCliCommandTests {
DockerCliCommand<?> command = new DockerCliCommand.ComposeDown(Duration.ofSeconds(1),
List.of("--remove-orphans"));
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
assertThat(command.getCommand()).containsExactly("down", "--timeout", "1", "--remove-orphans");
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("down", "--timeout", "1", "--remove-orphans");
assertThat(command.deserialize("[]")).isNull();
}
@@ -90,7 +102,7 @@ class DockerCliCommandTests {
DockerCliCommand<?> command = new DockerCliCommand.ComposeStart(LogLevel.INFO, List.of("--dry-run"));
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
assertThat(command.getLogLevel()).isEqualTo(LogLevel.INFO);
assertThat(command.getCommand()).containsExactly("start", "--dry-run");
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("start", "--dry-run");
assertThat(command.deserialize("[]")).isNull();
}
@@ -98,8 +110,23 @@ class DockerCliCommandTests {
void composeStop() {
DockerCliCommand<?> command = new DockerCliCommand.ComposeStop(Duration.ofSeconds(1), List.of("--dry-run"));
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
assertThat(command.getCommand()).containsExactly("stop", "--timeout", "1", "--dry-run");
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("stop", "--timeout", "1", "--dry-run");
assertThat(command.deserialize("[]")).isNull();
}
@Test
void composeVersionTests() {
ComposeVersion version = ComposeVersion.of("2.31.0-desktop");
assertThat(version.major()).isEqualTo(2);
assertThat(version.minor()).isEqualTo(31);
assertThat(version.isLessThan(1, 0)).isFalse();
assertThat(version.isLessThan(2, 0)).isFalse();
assertThat(version.isLessThan(2, 31)).isFalse();
assertThat(version.isLessThan(2, 32)).isTrue();
assertThat(version.isLessThan(3, 0)).isTrue();
ComposeVersion versionWithPrefix = ComposeVersion.of("v2.31.0-desktop");
assertThat(versionWithPrefix.major()).isEqualTo(2);
assertThat(versionWithPrefix.minor()).isEqualTo(31);
}
}