Skip to content

Commit

Permalink
test(springboot cloudconfig): fix integration test for secret and con…
Browse files Browse the repository at this point in the history
…fig store (try1)

Signed-off-by: lony2003 <[email protected]>
  • Loading branch information
lony2003 committed Mar 8, 2025
1 parent 802d0ec commit 383a076
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.testcontainers.containers.Network;
import org.testcontainers.junit.jupiter.Container;
Expand All @@ -30,6 +32,9 @@
+ "/" + DaprCloudConfigIT.CONFIG_MULTI_NAME + "?type=doc&doc-type=yaml",
"spring.config.import[1]=dapr:config:" + DaprCloudConfigIT.CONFIG_STORE_NAME
+ "/" + DaprCloudConfigIT.CONFIG_SINGLE_NAME + "?type=value",
"dapr.cloudconfig.wait-sidecar-enabled=true",
"dapr.cloudconfig.wait-sidecar-retries=5",
"dapr.cloudconfig.timeout=20000"
})
@ContextConfiguration(classes = TestDaprCloudConfigConfiguration.class)
@ExtendWith(SpringExtension.class)
Expand Down Expand Up @@ -69,7 +74,7 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
@Container
@ServiceConnection
private static final DaprContainer DAPR_CONTAINER = new DaprContainer(IMAGE_TAG)
.withAppName("secret-store-dapr-app")
.withAppName("configuration-dapr-app")
.withNetwork(DAPR_NETWORK)
.withComponent(new Component(CONFIG_STORE_NAME, "configuration.redis", "v1", STORE_PROPERTY))
.withDaprLogLevel(DaprLogLevel.DEBUG)
Expand All @@ -81,6 +86,18 @@ private static Map<String, String> generateStoreProperty() {
"redisPassword", "");
}

@DynamicPropertySource
static void dynamicProperties(DynamicPropertyRegistry registry) {
Logger logger = LoggerFactory.getLogger(DaprCloudConfigIT.class);

logger.info("Now get dapr port and update config http:{}, grpc:{}", DAPR_CONTAINER.getHttpPort(),
DAPR_CONTAINER.getGrpcPort());

registry.add("dapr.client.http-port", DAPR_CONTAINER::getHttpPort);
registry.add("dapr.client.grpc-port", DAPR_CONTAINER::getGrpcPort);
}


@Value("${dapr.spring.demo-config-config.singlevalue}")
String valueConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.testcontainers.containers.Network;
import org.testcontainers.images.builder.Transferable;
Expand All @@ -28,6 +32,9 @@
+ "/" + DaprSecretStoreIT.SECRET_SINGLE_NAME + "?type=value",
"spring.config.import[2]=dapr:secret:" + DaprSecretStoreIT.SECRET_STORE_NAME_MULTI
+ "?type=value",
"dapr.cloudconfig.wait-sidecar-enabled=true",
"dapr.cloudconfig.wait-sidecar-retries=5",
"dapr.cloudconfig.timeout=20000"
})
@ContextConfiguration(classes = TestDaprCloudConfigConfiguration.class)
@ExtendWith(SpringExtension.class)
Expand Down Expand Up @@ -68,6 +75,17 @@ private static Map<String, String> generateMultiValueProperty() {
"multiValued", "true");
}

@DynamicPropertySource
static void dynamicProperties(DynamicPropertyRegistry registry) {
Logger logger = LoggerFactory.getLogger(DaprSecretStoreIT.class);

logger.info("Now get dapr port and update config http:{}, grpc:{}", DAPR_CONTAINER.getHttpPort(),
DAPR_CONTAINER.getGrpcPort());

registry.add("dapr.client.http-port", DAPR_CONTAINER::getHttpPort);
registry.add("dapr.client.grpc-port", DAPR_CONTAINER::getGrpcPort);
}

@Value("${dapr.spring.demo-config-secret.singlevalue}")
String singleValue;

Expand Down

0 comments on commit 383a076

Please sign in to comment.