-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerPreflightCheckTest.java
More file actions
88 lines (74 loc) · 4.11 KB
/
DockerPreflightCheckTest.java
File metadata and controls
88 lines (74 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.gitranker.api.testsupport;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class DockerPreflightCheckTest {
@Test
@DisplayName("docker daemon이 reachable이면 성공 결과를 반환한다")
void should_returnSuccess_when_dockerDaemonIsReachable() {
DockerPreflightCheck check = new DockerPreflightCheck(command -> {
if (command.equals(List.of("docker", "context", "show"))) {
return CommandResult.success("orbstack\n", "");
}
if (command.equals(List.of("docker", "version", "--format", "{{.Server.APIVersion}}"))) {
return CommandResult.success("1.51\n", "");
}
throw new IllegalArgumentException("Unexpected command: " + command);
});
DockerPreflightResult result = check.run();
assertThat(result.isSuccess()).isTrue();
assertThat(result.message())
.isEqualTo("Docker preflight passed. context=orbstack serverApiVersion=1.51");
}
@Test
@DisplayName("docker daemon에 연결할 수 없으면 환경 문제를 설명하는 실패 결과를 반환한다")
void should_returnHelpfulFailure_when_dockerDaemonIsUnavailable() {
DockerPreflightCheck check = new DockerPreflightCheck(command -> {
if (command.equals(List.of("docker", "context", "show"))) {
return CommandResult.success("orbstack\n", "");
}
if (command.equals(List.of("docker", "version", "--format", "{{.Server.APIVersion}}"))) {
return CommandResult.failure(
1,
"",
"Cannot connect to the Docker daemon at unix:///tmp/docker.sock. Is the docker daemon running?");
}
throw new IllegalArgumentException("Unexpected command: " + command);
});
DockerPreflightResult result = check.run();
assertThat(result.isSuccess()).isFalse();
assertThat(result.message()).contains("Docker preflight failed for Testcontainers integration tests.");
assertThat(result.message()).contains("Cause: Docker daemon is not reachable from the current shell.");
assertThat(result.message()).contains("Context: orbstack");
assertThat(result.message()).contains("docker version");
assertThat(result.message()).contains("./gradlew test jacocoTestCoverageVerification");
assertThat(result.message()).contains("./gradlew integrationTest");
}
@Test
@DisplayName("docker CLI가 없으면 설치 전제조건을 안내하는 실패 결과를 반환한다")
void should_returnHelpfulFailure_when_dockerCliIsMissing() {
DockerPreflightCheck check = new DockerPreflightCheck(command -> {
if (command.equals(List.of("docker", "context", "show"))) {
return CommandResult.failure(127, "", "docker: command not found");
}
if (command.equals(List.of("docker", "version", "--format", "{{.Server.APIVersion}}"))) {
return CommandResult.failure(127, "", "docker: command not found");
}
throw new IllegalArgumentException("Unexpected command: " + command);
});
DockerPreflightResult result = check.run();
assertThat(result.isSuccess()).isFalse();
assertThat(result.message()).contains("Cause: Docker CLI is not installed or not available on PATH.");
assertThat(result.message()).contains("Context: unavailable");
assertThat(result.message()).contains("Install Docker Desktop, OrbStack, or another compatible Docker runtime.");
}
@Test
@DisplayName("failure result는 zero exit code를 허용하지 않는다")
void should_rejectZeroExitCode_when_creatingFailureResult() {
assertThatThrownBy(() -> CommandResult.failure(0, "", "unexpected"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Failure result must have non-zero exit code");
}
}