Restore support for docker compose versions earlier than 2.24
Fixes gh-43710
This commit is contained in:
@@ -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);
|
||||
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");
|
||||
assertThat(command.deserialize("[]")).isNull();
|
||||
}
|
||||
|
||||
@@ -79,7 +91,7 @@ class DockerCliCommandTests {
|
||||
void composeDown() {
|
||||
DockerCliCommand<?> command = new DockerCliCommand.ComposeDown(Duration.ofSeconds(1));
|
||||
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
||||
assertThat(command.getCommand()).containsExactly("down", "--timeout", "1");
|
||||
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("down", "--timeout", "1");
|
||||
assertThat(command.deserialize("[]")).isNull();
|
||||
}
|
||||
|
||||
@@ -88,7 +100,7 @@ class DockerCliCommandTests {
|
||||
DockerCliCommand<?> command = new DockerCliCommand.ComposeStart(LogLevel.INFO);
|
||||
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
||||
assertThat(command.getLogLevel()).isEqualTo(LogLevel.INFO);
|
||||
assertThat(command.getCommand()).containsExactly("start");
|
||||
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("start");
|
||||
assertThat(command.deserialize("[]")).isNull();
|
||||
}
|
||||
|
||||
@@ -96,8 +108,23 @@ class DockerCliCommandTests {
|
||||
void composeStop() {
|
||||
DockerCliCommand<?> command = new DockerCliCommand.ComposeStop(Duration.ofSeconds(1));
|
||||
assertThat(command.getType()).isEqualTo(DockerCliCommand.Type.DOCKER_COMPOSE);
|
||||
assertThat(command.getCommand()).containsExactly("stop", "--timeout", "1");
|
||||
assertThat(command.getCommand(COMPOSE_VERSION)).containsExactly("stop", "--timeout", "1");
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user