Skip to content

Commit 034baad

Browse files
committed
test(springboot cloudconfig): fix integration test for secret and config store (try1)
Signed-off-by: lony2003 <[email protected]>
1 parent 802d0ec commit 034baad

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

sdk-tests/src/test/java/io/dapr/it/spring/cloudconfig/DaprCloudConfigIT.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.dapr.testcontainers.Component;
66
import io.dapr.testcontainers.DaprContainer;
77
import io.dapr.testcontainers.DaprLogLevel;
8+
import org.junit.jupiter.api.AfterAll;
89
import org.junit.jupiter.api.Tag;
910
import org.junit.jupiter.api.Test;
1011
import org.junit.jupiter.api.extension.ExtendWith;
@@ -14,12 +15,15 @@
1415
import org.springframework.boot.test.context.SpringBootTest;
1516
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
1617
import org.springframework.test.context.ContextConfiguration;
18+
import org.springframework.test.context.DynamicPropertyRegistry;
19+
import org.springframework.test.context.DynamicPropertySource;
1720
import org.springframework.test.context.junit.jupiter.SpringExtension;
1821
import org.testcontainers.containers.Network;
1922
import org.testcontainers.junit.jupiter.Container;
2023
import org.testcontainers.junit.jupiter.Testcontainers;
2124
import redis.clients.jedis.Jedis;
2225

26+
import java.util.List;
2327
import java.util.Map;
2428

2529
import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
@@ -30,6 +34,8 @@
3034
+ "/" + DaprCloudConfigIT.CONFIG_MULTI_NAME + "?type=doc&doc-type=yaml",
3135
"spring.config.import[1]=dapr:config:" + DaprCloudConfigIT.CONFIG_STORE_NAME
3236
+ "/" + DaprCloudConfigIT.CONFIG_SINGLE_NAME + "?type=value",
37+
"dapr.cloudconfig.wait-sidecar-enabled=true",
38+
"dapr.cloudconfig.wait-sidecar-retries=5",
3339
})
3440
@ContextConfiguration(classes = TestDaprCloudConfigConfiguration.class)
3541
@ExtendWith(SpringExtension.class)
@@ -69,13 +75,17 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
6975
@Container
7076
@ServiceConnection
7177
private static final DaprContainer DAPR_CONTAINER = new DaprContainer(IMAGE_TAG)
72-
.withAppName("secret-store-dapr-app")
78+
.withAppName("configuration-dapr-app")
7379
.withNetwork(DAPR_NETWORK)
7480
.withComponent(new Component(CONFIG_STORE_NAME, "configuration.redis", "v1", STORE_PROPERTY))
7581
.withDaprLogLevel(DaprLogLevel.DEBUG)
7682
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
7783
.dependsOn(REDIS_CONTAINER);
7884

85+
static {
86+
DAPR_CONTAINER.setPortBindings(List.of("3500:3500", "50001:50001"));
87+
}
88+
7989
private static Map<String, String> generateStoreProperty() {
8090
return Map.of("redisHost", "redis:6379",
8191
"redisPassword", "");
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package io.dapr.it.spring.cloudconfig;
22

33
public class DaprConfigurationStores {
4-
public static final String YAML_CONFIG = "dapr:\\n spring:\\n demo-config-config:\\n multivalue:\\n v3: cloud";
4+
public static final String YAML_CONFIG = "dapr:\n" +
5+
" spring:\n" +
6+
" demo-config-config:\n" +
7+
" multivalue:\n" +
8+
" v3: cloud";
59
}

sdk-tests/src/test/java/io/dapr/it/spring/cloudconfig/DaprSecretStoreIT.java

+12
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33
import io.dapr.testcontainers.Component;
44
import io.dapr.testcontainers.DaprContainer;
55
import io.dapr.testcontainers.DaprLogLevel;
6+
import org.junit.jupiter.api.AfterAll;
67
import org.junit.jupiter.api.Tag;
78
import org.junit.jupiter.api.Test;
89
import org.junit.jupiter.api.extension.ExtendWith;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
912
import org.springframework.beans.factory.annotation.Value;
1013
import org.springframework.boot.test.context.SpringBootTest;
1114
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
1215
import org.springframework.test.context.ContextConfiguration;
16+
import org.springframework.test.context.DynamicPropertyRegistry;
17+
import org.springframework.test.context.DynamicPropertySource;
1318
import org.springframework.test.context.junit.jupiter.SpringExtension;
1419
import org.testcontainers.containers.Network;
1520
import org.testcontainers.images.builder.Transferable;
1621
import org.testcontainers.junit.jupiter.Container;
1722
import org.testcontainers.junit.jupiter.Testcontainers;
1823

24+
import java.util.List;
1925
import java.util.Map;
2026

2127
import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
@@ -28,6 +34,8 @@
2834
+ "/" + DaprSecretStoreIT.SECRET_SINGLE_NAME + "?type=value",
2935
"spring.config.import[2]=dapr:secret:" + DaprSecretStoreIT.SECRET_STORE_NAME_MULTI
3036
+ "?type=value",
37+
"dapr.cloudconfig.wait-sidecar-enabled=true",
38+
"dapr.cloudconfig.wait-sidecar-retries=5",
3139
})
3240
@ContextConfiguration(classes = TestDaprCloudConfigConfiguration.class)
3341
@ExtendWith(SpringExtension.class)
@@ -57,6 +65,10 @@ public class DaprSecretStoreIT {
5765
.withCopyToContainer(Transferable.of(DaprSecretStores.SINGLE_VALUED_SECRET), "/dapr-secrets/singlevalued.json")
5866
.withCopyToContainer(Transferable.of(DaprSecretStores.MULTI_VALUED_SECRET), "/dapr-secrets/multivalued.json");
5967

68+
static {
69+
DAPR_CONTAINER.setPortBindings(List.of("3500:3500", "50001:50001"));
70+
}
71+
6072
private static Map<String, String> generateSingleValueProperty() {
6173
return Map.of("secretsFile", "/dapr-secrets/singlevalued.json",
6274
"multiValued", "false");

sdk-tests/src/test/java/io/dapr/it/spring/cloudconfig/DaprSecretStores.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class DaprSecretStores {
44
public static final String SINGLE_VALUED_SECRET = "{\n" +
5-
" \"dapr.spring.democonfigsecret.singlevalue\": \"testvalue\",\n" +
5+
" \"dapr.spring.demo-config-secret.singlevalue\": \"testvalue\",\n" +
66
" \"multivalue-properties\": \"dapr.spring.demo-config-secret.multivalue.v1=spring\\ndapr.spring.demo-config-secret.multivalue.v2=dapr\",\n" +
77
" \"multivalue-yaml\": \"dapr:\\n spring:\\n demo-config-secret:\\n multivalue:\\n v3: cloud\"\n" +
88
"}";

0 commit comments

Comments
 (0)