Skip to content

Commit 6ea6f02

Browse files
committed
adding test to validate canonical names with substitutes
Signed-off-by: salaboy <[email protected]>
1 parent 5e9fd8b commit 6ea6f02

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public class DaprContainer extends GenericContainer<DaprContainer> {
5656
private static final YamlConverter<Subscription> SUBSCRIPTION_CONVERTER = new SubscriptionYamlConverter(YAML_MAPPER);
5757
private static final YamlConverter<HttpEndpoint> HTTPENDPOINT_CONVERTER = new HttpEndpointYamlConverter(YAML_MAPPER);
5858
private static final YamlConverter<Configuration> CONFIGURATION_CONVERTER = new ConfigurationYamlConverter(
59-
YAML_MAPPER);
59+
YAML_MAPPER);
6060
private static final WaitStrategy WAIT_STRATEGY = Wait.forHttp("/v1.0/healthz/outbound")
61-
.forPort(DAPRD_DEFAULT_HTTP_PORT)
62-
.forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode <= 399);
61+
.forPort(DAPRD_DEFAULT_HTTP_PORT)
62+
.forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode <= 399);
6363

6464
private final Set<Component> components = new HashSet<>();
6565
private final Set<Subscription> subscriptions = new HashSet<>();
@@ -82,6 +82,7 @@ public class DaprContainer extends GenericContainer<DaprContainer> {
8282

8383
/**
8484
* Creates a new Dapr container.
85+
*
8586
* @param dockerImageName Docker image name.
8687
*/
8788
public DaprContainer(DockerImageName dockerImageName) {
@@ -94,6 +95,7 @@ public DaprContainer(DockerImageName dockerImageName) {
9495

9596
/**
9697
* Creates a new Dapr container.
98+
*
9799
* @param image Docker image name.
98100
*/
99101
public DaprContainer(String image) {
@@ -213,6 +215,7 @@ public DaprContainer withComponent(Component component) {
213215

214216
/**
215217
* Adds a Dapr component from a YAML file.
218+
*
216219
* @param path Path to the YAML file.
217220
* @return This container.
218221
*/
@@ -227,7 +230,7 @@ public DaprContainer withComponent(Path path) {
227230
String type = (String) spec.get("type");
228231
String version = (String) spec.get("version");
229232
List<Map<String, String>> specMetadata =
230-
(List<Map<String, String>>) spec.getOrDefault("metadata", Collections.emptyList());
233+
(List<Map<String, String>>) spec.getOrDefault("metadata", Collections.emptyList());
231234

232235
ArrayList<MetadataEntry> metadataEntries = new ArrayList<>();
233236

@@ -268,17 +271,17 @@ protected void configure() {
268271

269272
if (this.placementContainer == null) {
270273
this.placementContainer = new DaprPlacementContainer(this.placementDockerImageName)
271-
.withNetwork(getNetwork())
272-
.withNetworkAliases(placementService)
273-
.withReuse(this.shouldReusePlacement);
274+
.withNetwork(getNetwork())
275+
.withNetworkAliases(placementService)
276+
.withReuse(this.shouldReusePlacement);
274277
this.placementContainer.start();
275278
}
276279

277280
if (this.schedulerContainer == null) {
278281
this.schedulerContainer = new DaprSchedulerContainer(this.schedulerDockerImageName)
279-
.withNetwork(getNetwork())
280-
.withNetworkAliases(schedulerService)
281-
.withReuse(this.shouldReuseScheduler);
282+
.withNetwork(getNetwork())
283+
.withNetworkAliases(schedulerService)
284+
.withReuse(this.shouldReuseScheduler);
282285
this.schedulerContainer.start();
283286
}
284287

@@ -394,6 +397,14 @@ public static DockerImageName getDefaultImageName() {
394397
return DEFAULT_IMAGE_NAME;
395398
}
396399

400+
public DockerImageName getPlacementDockerImageName() {
401+
return placementDockerImageName;
402+
}
403+
404+
public DockerImageName getSchedulerDockerImageName() {
405+
return schedulerDockerImageName;
406+
}
407+
397408
// Required by spotbugs plugin
398409
@Override
399410
public boolean equals(Object o) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.dapr.testcontainers;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.testcontainers.utility.DockerImageName;
5+
6+
import static io.dapr.testcontainers.DaprContainerConstants.DAPR_RUNTIME_IMAGE_TAG;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class DaprContainerTest {
10+
11+
@Test
12+
public void schedulerAndPlacementCustomImagesTest() {
13+
14+
DaprContainer dapr = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
15+
.withAppName("dapr-app")
16+
.withSchedulerImage(DockerImageName.parse("custom/scheduler:1.15.4")
17+
.asCompatibleSubstituteFor("daprio/scheduler:1.15.4"))
18+
.withPlacementImage(DockerImageName.parse("custom/placement:1.15.4")
19+
.asCompatibleSubstituteFor("daprio/placement:1.15.4"))
20+
.withAppPort(8081)
21+
.withDaprLogLevel(DaprLogLevel.DEBUG)
22+
.withAppChannelAddress("host.testcontainers.internal");
23+
24+
25+
assertEquals("custom/placement:1.15.4", dapr.getPlacementDockerImageName().asCanonicalNameString());
26+
assertEquals("custom/scheduler:1.15.4", dapr.getSchedulerDockerImageName().asCanonicalNameString());
27+
28+
}
29+
}

0 commit comments

Comments
 (0)