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 034baad
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.dapr.testcontainers.Component;
import io.dapr.testcontainers.DaprContainer;
import io.dapr.testcontainers.DaprLogLevel;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -14,12 +15,15 @@
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;
import org.testcontainers.junit.jupiter.Testcontainers;
import redis.clients.jedis.Jedis;

import java.util.List;
import java.util.Map;

import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
Expand All @@ -30,6 +34,8 @@
+ "/" + 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",
})
@ContextConfiguration(classes = TestDaprCloudConfigConfiguration.class)
@ExtendWith(SpringExtension.class)
Expand Down Expand Up @@ -69,13 +75,17 @@ 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)
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
.dependsOn(REDIS_CONTAINER);

static {
DAPR_CONTAINER.setPortBindings(List.of("3500:3500", "50001:50001"));
}

private static Map<String, String> generateStoreProperty() {
return Map.of("redisHost", "redis:6379",
"redisPassword", "");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.dapr.it.spring.cloudconfig;

public class DaprConfigurationStores {
public static final String YAML_CONFIG = "dapr:\\n spring:\\n demo-config-config:\\n multivalue:\\n v3: cloud";
public static final String YAML_CONFIG = "dapr:\n" +
" spring:\n" +
" demo-config-config:\n" +
" multivalue:\n" +
" v3: cloud";
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
import io.dapr.testcontainers.Component;
import io.dapr.testcontainers.DaprContainer;
import io.dapr.testcontainers.DaprLogLevel;
import org.junit.jupiter.api.AfterAll;
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;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.util.List;
import java.util.Map;

import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
Expand All @@ -28,6 +34,8 @@
+ "/" + 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",
})
@ContextConfiguration(classes = TestDaprCloudConfigConfiguration.class)
@ExtendWith(SpringExtension.class)
Expand Down Expand Up @@ -57,6 +65,10 @@ public class DaprSecretStoreIT {
.withCopyToContainer(Transferable.of(DaprSecretStores.SINGLE_VALUED_SECRET), "/dapr-secrets/singlevalued.json")
.withCopyToContainer(Transferable.of(DaprSecretStores.MULTI_VALUED_SECRET), "/dapr-secrets/multivalued.json");

static {
DAPR_CONTAINER.setPortBindings(List.of("3500:3500", "50001:50001"));
}

private static Map<String, String> generateSingleValueProperty() {
return Map.of("secretsFile", "/dapr-secrets/singlevalued.json",
"multiValued", "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

0 comments on commit 034baad

Please sign in to comment.