1414package io .dapr .it .secrets ;
1515
1616import io .dapr .it .testcontainers .TestContainerNetworks ;
17-
1817import io .dapr .client .DaprClient ;
1918import io .dapr .it .testcontainers .DaprClientFactory ;
2019import io .dapr .testcontainers .Component ;
2120import io .dapr .testcontainers .DaprContainer ;
2221import org .junit .jupiter .api .BeforeAll ;
23- import org .junit .jupiter .api .BeforeEach ;
2422import org .junit .jupiter .api .Tag ;
2523import org .junit .jupiter .api .Test ;
26- import org .testcontainers .containers .GenericContainer ;
2724import org .testcontainers .containers .Network ;
25+ import org .testcontainers .images .builder .Transferable ;
2826import org .testcontainers .junit .jupiter .Container ;
2927import org .testcontainers .junit .jupiter .Testcontainers ;
3028
3129import java .util .Map ;
32- import java .util .UUID ;
3330
3431import static io .dapr .it .testcontainers .ContainerConstants .DAPR_RUNTIME_IMAGE_TAG ;
3532import static org .junit .jupiter .api .Assertions .assertEquals ;
3633import static org .junit .jupiter .api .Assertions .assertThrows ;
3734import static org .junit .jupiter .api .Assertions .assertTrue ;
3835
3936/**
40- * Test Secrets Store APIs backed by redis secret store.
37+ * Test Secrets Store APIs backed by local file secret store.
4138 */
4239@ Testcontainers
4340@ Tag ("testcontainers" )
4441public class SecretsClientIT {
4542
4643 private static final String SECRETS_STORE_NAME = "localSecretStore" ;
47-
48- private static final String KEY1 = UUID .randomUUID ().toString ();
49-
50- private static final String KYE2 = UUID .randomUUID ().toString ();
51- private static final String REDIS_ALIAS = "secrets-redis" ;
44+ private static final String SECRET_FILE_PATH = "/dapr-resources/secrets.json" ;
45+
46+ private static final String KEY1 = "metrics" ;
47+ private static final String KEY2 = "person" ;
48+ private static final String SECRET_FILE_CONTENT = "{\n "
49+ + " \" " + KEY1 + "\" : {\n "
50+ + " \" title\" : \" The Metrics IV\" ,\n "
51+ + " \" year\" : \" 2020\" \n "
52+ + " },\n "
53+ + " \" " + KEY2 + "\" : {\n "
54+ + " \" name\" : \" Jon Doe\" \n "
55+ + " }\n "
56+ + "}\n " ;
5257
5358 private static final Network NETWORK = TestContainerNetworks .STATE_NETWORK ;
5459
55- @ Container
56- private static final GenericContainer <?> REDIS = new GenericContainer <>("redis:7-alpine" )
57- .withNetwork (NETWORK )
58- .withNetworkAliases (REDIS_ALIAS );
59-
6060 @ Container
6161 private static final DaprContainer DAPR_CONTAINER = new DaprContainer (DAPR_RUNTIME_IMAGE_TAG )
6262 .withNetwork (NETWORK )
6363 .withAppName ("secrets-it" )
64+ .withCopyToContainer (Transferable .of (SECRET_FILE_CONTENT ), SECRET_FILE_PATH )
6465 .withComponent (new Component (
6566 SECRETS_STORE_NAME ,
66- "secretstores.redis " ,
67+ "secretstores.local.file " ,
6768 "v1" ,
68- Map .of ("redisHost" , REDIS_ALIAS + ":6379" , "redisPassword" , "" )))
69- .dependsOn (REDIS );
69+ Map .of ("secretsFile" , SECRET_FILE_PATH , "multiValued" , "true" )));
7070
7171 @ BeforeAll
7272 public static void init () throws Exception {
@@ -75,14 +75,6 @@ public static void init() throws Exception {
7575 }
7676 }
7777
78- @ BeforeEach
79- public void setup () throws Exception {
80- REDIS .execInContainer ("redis-cli" , "DEL" , KEY1 );
81- REDIS .execInContainer ("redis-cli" , "DEL" , KYE2 );
82- REDIS .execInContainer ("redis-cli" , "HSET" , KEY1 , "title" , "The Metrics IV" , "year" , "2020" );
83- REDIS .execInContainer ("redis-cli" , "HSET" , KYE2 , "name" , "Jon Doe" );
84- }
85-
8678 @ Test
8779 public void getSecret () throws Exception {
8880 try (DaprClient daprClient = DaprClientFactory .createDaprClientBuilder (DAPR_CONTAINER ).build ()) {
@@ -101,8 +93,8 @@ public void getBulkSecret() throws Exception {
10193 assertEquals (2 , data .get (KEY1 ).size ());
10294 assertEquals ("The Metrics IV" , data .get (KEY1 ).get ("title" ));
10395 assertEquals ("2020" , data .get (KEY1 ).get ("year" ));
104- assertEquals (1 , data .get (KYE2 ).size ());
105- assertEquals ("Jon Doe" , data .get (KYE2 ).get ("name" ));
96+ assertEquals (1 , data .get (KEY2 ).size ());
97+ assertEquals ("Jon Doe" , data .get (KEY2 ).get ("name" ));
10698 }
10799 }
108100
0 commit comments