Skip to content

Commit 39c56a4

Browse files
committed
formatting
1 parent 7938cc2 commit 39c56a4

File tree

1 file changed

+94
-90
lines changed

1 file changed

+94
-90
lines changed
Lines changed: 94 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.testcontainers.containers;
22

3-
import org.junit.Ignore;
43
import org.junit.Test;
54
import org.testcontainers.containers.wait.strategy.Wait;
65

@@ -11,105 +10,110 @@
1110
import java.util.stream.Stream;
1211

1312
import static org.assertj.core.api.Assertions.assertThat;
14-
import static org.assertj.core.api.Assertions.catchThrowable;
1513

1614
public class ComposeContainerDocTest {
1715

18-
private static final int REDIS_PORT = 6379;
19-
private static final int POSTGRES_PORT = 5432;
20-
private static final String DOCKER_COMPOSE_FILE_PATH = "src/test/resources/v2-compose-test-doc.yml";
21-
public static final String ENV_FILE_NAME = "v2-compose-test-doc.env";
16+
private static final int REDIS_PORT = 6379;
17+
private static final int POSTGRES_PORT = 5432;
18+
private static final String DOCKER_COMPOSE_FILE_PATH = "src/test/resources/v2-compose-test-doc.yml";
19+
public static final String ENV_FILE_NAME = "v2-compose-test-doc.env";
2220

23-
@Test
24-
public void testComposeContainerConstructor() {
25-
try (
26-
// composeContainerConstructor {
27-
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
28-
.withExposedService("redis-1", REDIS_PORT)
29-
.withExposedService("postgres-1", POSTGRES_PORT)
30-
// }
31-
) {
32-
compose.start();
21+
@Test
22+
public void testComposeContainerConstructor() {
23+
try (
24+
// composeContainerConstructor {
25+
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
26+
.withExposedService("redis-1", REDIS_PORT)
27+
.withExposedService("postgres-1", POSTGRES_PORT)
28+
// }
29+
) {
30+
compose.start();
3331

34-
// getServiceHostAndPort {
35-
String redisUrl = String.format("%s:%s",
36-
compose.getServiceHost("redis-1", REDIS_PORT),
37-
compose.getServicePort("redis-1", REDIS_PORT)
38-
);
39-
// }
40-
assertThat(redisUrl).isNotBlank();
32+
// getServiceHostAndPort {
33+
String redisUrl = String.format(
34+
"%s:%s",
35+
compose.getServiceHost("redis-1", REDIS_PORT),
36+
compose.getServicePort("redis-1", REDIS_PORT)
37+
);
38+
// }
39+
assertThat(redisUrl).isNotBlank();
4140

42-
containsStartedServices(compose, "redis-1", "postgres-1");
43-
}
44-
}
41+
containsStartedServices(compose, "redis-1", "postgres-1");
42+
}
43+
}
4544

46-
@Test
47-
public void testComposeContainerWithCombinedWaitStrategies() {
48-
try (
49-
// composeContainerWithCombinedWaitStrategies {
50-
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
51-
.withExposedService("redis-1", REDIS_PORT,
52-
Wait.forSuccessfulCommand("redis-cli ping"))
53-
.withExposedService("postgres-1", POSTGRES_PORT,
54-
Wait.forLogMessage(".*database system is ready to accept connections.*\\n", 1))
55-
// }
56-
){
57-
compose.start();
58-
containsStartedServices(compose, "redis-1", "postgres-1");
59-
}
60-
}
45+
@Test
46+
public void testComposeContainerWithCombinedWaitStrategies() {
47+
try (
48+
// composeContainerWithCombinedWaitStrategies {
49+
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
50+
.withExposedService("redis-1", REDIS_PORT, Wait.forSuccessfulCommand("redis-cli ping"))
51+
.withExposedService(
52+
"postgres-1",
53+
POSTGRES_PORT,
54+
Wait.forLogMessage(".*database system is ready to accept connections.*\\n", 1)
55+
)
56+
// }
57+
) {
58+
compose.start();
59+
containsStartedServices(compose, "redis-1", "postgres-1");
60+
}
61+
}
6162

62-
@Test
63-
public void testComposeContainerWaitForPortWithTimeout() {
64-
try (
65-
// composeContainerWaitForPortWithTimeout {
66-
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
67-
.withExposedService("redis-1", REDIS_PORT,
68-
Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(30)))
69-
// }
70-
){
71-
compose.start();
72-
containsStartedServices(compose, "redis-1");
73-
}
74-
}
63+
@Test
64+
public void testComposeContainerWaitForPortWithTimeout() {
65+
try (
66+
// composeContainerWaitForPortWithTimeout {
67+
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
68+
.withExposedService(
69+
"redis-1",
70+
REDIS_PORT,
71+
Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(30))
72+
)
73+
// }
74+
) {
75+
compose.start();
76+
containsStartedServices(compose, "redis-1");
77+
}
78+
}
7579

76-
@Test
77-
public void testComposeContainerWithLocalCompose() {
78-
try (
79-
// composeContainerWithLocalCompose {
80-
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
81-
.withExposedService("redis-1", REDIS_PORT)
82-
.withLocalCompose(true)
83-
// }
84-
){
85-
compose.start();
86-
containsStartedServices(compose, "redis-1");
87-
}
88-
}
80+
@Test
81+
public void testComposeContainerWithLocalCompose() {
82+
try (
83+
// composeContainerWithLocalCompose {
84+
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
85+
.withExposedService("redis-1", REDIS_PORT)
86+
.withLocalCompose(true)
87+
// }
88+
) {
89+
compose.start();
90+
containsStartedServices(compose, "redis-1");
91+
}
92+
}
8993

90-
@Test
91-
public void test() {
92-
try (
93-
// composeContainerWithCopyFiles {
94-
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
95-
.withExposedService("postgres-1", POSTGRES_PORT)
96-
.withCopyFilesInContainer(ENV_FILE_NAME)
97-
// }
98-
){
99-
compose.start();
100-
containsStartedServices(compose, "postgres-1");
101-
}
102-
}
94+
@Test
95+
public void test() {
96+
try (
97+
// composeContainerWithCopyFiles {
98+
ComposeContainer compose = new ComposeContainer(new File(DOCKER_COMPOSE_FILE_PATH))
99+
.withExposedService("postgres-1", POSTGRES_PORT)
100+
.withCopyFilesInContainer(ENV_FILE_NAME)
101+
// }
102+
) {
103+
compose.start();
104+
containsStartedServices(compose, "postgres-1");
105+
}
106+
}
103107

104-
private void containsStartedServices(ComposeContainer compose, String... expectedServices) {
105-
final List<String> containerNames = compose.listChildContainers()
106-
.stream()
107-
.flatMap(it -> Stream.of(it.getNames()))
108-
.collect(Collectors.toList());
108+
private void containsStartedServices(ComposeContainer compose, String... expectedServices) {
109+
final List<String> containerNames = compose
110+
.listChildContainers()
111+
.stream()
112+
.flatMap(it -> Stream.of(it.getNames()))
113+
.collect(Collectors.toList());
109114

110-
for (String service: expectedServices) {
111-
assertThat(containerNames)
112-
.anyMatch(it -> it.endsWith(service));
113-
}
114-
}
115+
for (String service : expectedServices) {
116+
assertThat(containerNames).anyMatch(it -> it.endsWith(service));
117+
}
118+
}
115119
}

0 commit comments

Comments
 (0)