-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interface to customize CreateContainerCmd (#7421)
Add `CreateContainerCmdModifier` interface to customize `CreateContainerCmd`. Customization is applied after Testcontainers configuration is set.
- Loading branch information
1 parent
6e81732
commit d9519f9
Showing
6 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
core/src/main/java/org/testcontainers/core/CreateContainerCmdModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.testcontainers.core; | ||
|
||
import com.github.dockerjava.api.command.CreateContainerCmd; | ||
|
||
/** | ||
* Callback interface that can be used to customize a {@link CreateContainerCmd}. | ||
*/ | ||
public interface CreateContainerCmdModifier { | ||
/** | ||
* Callback to modify a {@link CreateContainerCmd} instance. | ||
*/ | ||
CreateContainerCmd modify(CreateContainerCmd createContainerCmd); | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/test/java/org/testcontainers/custom/TestCreateContainerCmdModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.testcontainers.custom; | ||
|
||
import com.github.dockerjava.api.command.CreateContainerCmd; | ||
import org.testcontainers.core.CreateContainerCmdModifier; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class TestCreateContainerCmdModifier implements CreateContainerCmdModifier { | ||
|
||
@Override | ||
public CreateContainerCmd modify(CreateContainerCmd createContainerCmd) { | ||
Map<String, String> labels = new HashMap<>(); | ||
labels.put("project", "testcontainers-java"); | ||
labels.put("scope", "global"); | ||
return createContainerCmd.withLabels(labels); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
core/src/test/resources/META-INF/services/org.testcontainers.core.CreateContainerCmdModifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.testcontainers.custom.TestCreateContainerCmdModifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters