Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ private void parseAndValidate() {

private void validateNoContainerNameSpecified(String serviceName, Map<String, ?> serviceDefinitionMap) {
if (serviceDefinitionMap.containsKey("container_name")) {
throw new IllegalStateException(
String.format(
"Compose file %s has 'container_name' property set for service '%s' but this property is not supported by Testcontainers, consider removing it",
composeFileName,
serviceName
)
log.warn(
"Compose file {} has 'container_name' property set for service '{}'. " +
"This property is not supported by Testcontainers and will be ignored.",
composeFileName,
serviceName
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,35 @@ class ParsedDockerComposeFileValidationTest {
public Path temporaryFolder;

@Test
void shouldValidate() {
void shouldIgnoreContainerNameV1() {
File file = new File("src/test/resources/docker-compose-container-name-v1.yml");
assertThatThrownBy(() -> {
new ParsedDockerComposeFile(file);
})
.hasMessageContaining(file.getAbsolutePath())
.hasMessageContaining("'container_name' property set for service 'redis'");
// container_name should be ignored (with a warning log) instead of throwing an exception
assertThatNoException().isThrownBy(() -> new ParsedDockerComposeFile(file));
}

@Test
void shouldRejectContainerNameV1() {
assertThatThrownBy(() -> {
new ParsedDockerComposeFile(ImmutableMap.of("redis", ImmutableMap.of("container_name", "redis")));
})
.hasMessageContaining("'container_name' property set for service 'redis'");
void shouldIgnoreContainerNameInMapV1() {
// container_name should be ignored (with a warning log) instead of throwing an exception
assertThatNoException()
.isThrownBy(() ->
new ParsedDockerComposeFile(ImmutableMap.of("redis", ImmutableMap.of("container_name", "redis")))
);
}

@Test
void shouldRejectContainerNameV2() {
assertThatThrownBy(() -> {
void shouldIgnoreContainerNameV2() {
// container_name should be ignored (with a warning log) instead of throwing an exception
assertThatNoException()
.isThrownBy(() ->
new ParsedDockerComposeFile(
ImmutableMap.of(
"version",
"2",
"services",
ImmutableMap.of("redis", ImmutableMap.of("container_name", "redis"))
)
);
})
.hasMessageContaining("'container_name' property set for service 'redis'");
)
);
}

@Test
Expand Down