|
| 1 | +/* |
| 2 | + * Copyright 2012-2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.docker.compose.core; |
| 18 | + |
| 19 | +import java.io.File; |
| 20 | +import java.util.Collections; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Set; |
| 23 | + |
| 24 | +import org.junit.jupiter.api.Assumptions; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +import org.springframework.boot.docker.compose.core.DockerCli.DockerComposeOptions; |
| 28 | +import org.springframework.boot.docker.compose.core.DockerCliCommand.Type; |
| 29 | + |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; |
| 31 | +import static org.mockito.ArgumentMatchers.any; |
| 32 | +import static org.mockito.Mockito.doReturn; |
| 33 | +import static org.mockito.Mockito.mock; |
| 34 | +import static org.mockito.Mockito.spy; |
| 35 | +import static org.mockito.Mockito.when; |
| 36 | + |
| 37 | +class DockerCliTests { |
| 38 | + @Test |
| 39 | + void createCommandWithDockerComposeShouldIncludeCorrectOptions() { |
| 40 | + ProcessRunner mockProcessRunner = mock(ProcessRunner.class); |
| 41 | + when(mockProcessRunner.run(any(String[].class))).thenReturn("{\"version\":\"1.0.0\"}"); |
| 42 | + |
| 43 | + DockerComposeFile mockFile = mock(DockerComposeFile.class); |
| 44 | + when(mockFile.getFiles()).thenReturn(List.of(new File("docker-compose.yml"))); |
| 45 | + |
| 46 | + DockerCli.DockerComposeOptions options = new DockerCli.DockerComposeOptions(mockFile, Set.of("dev"), List.of("--verbose")); |
| 47 | + DockerCli cli = new DockerCli(mockProcessRunner, options); |
| 48 | + |
| 49 | + List<String> command = cli.createCommand(DockerCliCommand.Type.DOCKER_COMPOSE); |
| 50 | + assertThat(command).contains("--file", "docker-compose.yml", "--profile", "dev", "--verbose"); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + void fileConstructorShouldInitializeCorrectly_whenDockerIsRunning() { |
| 55 | + // assume docker is running (아니면 생략 가능) |
| 56 | + Assumptions.assumeTrue(new File("/var/run/docker.sock").exists() || System.getProperty("os.name").startsWith("Windows")); |
| 57 | + |
| 58 | + DockerComposeFile mockFile = mock(DockerComposeFile.class); |
| 59 | + when(mockFile.getFiles()).thenReturn(List.of(new File("docker-compose.yml"))); |
| 60 | + |
| 61 | + DockerCli.DockerComposeOptions options = new DockerCli.DockerComposeOptions(mockFile, Set.of("dev"), List.of("--verbose")); |
| 62 | + |
| 63 | + DockerCli cli = new DockerCli(new File("."), options); // ✅ 여기! 기존 생성자 직접 호출 |
| 64 | + |
| 65 | + List<String> command = cli.createCommand(DockerCliCommand.Type.DOCKER_COMPOSE); |
| 66 | + |
| 67 | + assertThat(command).contains("--file", "docker-compose.yml", "--profile", "dev", "--verbose"); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments