55package file
66
77import (
8+ "encoding/json"
89 "fmt"
910 "testing"
1011
1112 "github.com/dapr/components-contrib/secretstores"
1213 "github.com/dapr/kit/logger"
1314 "github.com/stretchr/testify/assert"
15+ "github.com/stretchr/testify/require"
1416)
1517
1618const secretValue = "secret"
@@ -25,16 +27,16 @@ func TestInit(t *testing.T) {
2527 }
2628 t .Run ("Init with valid metadata" , func (t * testing.T ) {
2729 m .Properties = map [string ]string {
28- "SecretsFile " : "a" ,
29- "NestedSeparator " : "a" ,
30+ "secretsFile " : "a" ,
31+ "nestedSeparator " : "a" ,
3032 }
3133 err := s .Init (m )
3234 assert .Nil (t , err )
3335 })
3436
3537 t .Run ("Init with missing metadata" , func (t * testing.T ) {
3638 m .Properties = map [string ]string {
37- "Dummy " : "a" ,
39+ "dummy " : "a" ,
3840 }
3941 err := s .Init (m )
4042 assert .NotNil (t , err )
@@ -57,8 +59,8 @@ func TestSeparator(t *testing.T) {
5759 }
5860 t .Run ("Init with custom separator" , func (t * testing.T ) {
5961 m .Properties = map [string ]string {
60- "SecretsFile " : "a" ,
61- "NestedSeparator " : "." ,
62+ "secretsFile " : "a" ,
63+ "nestedSeparator " : "." ,
6264 }
6365 err := s .Init (m )
6466 assert .Nil (t , err )
@@ -74,7 +76,7 @@ func TestSeparator(t *testing.T) {
7476
7577 t .Run ("Init with default separator" , func (t * testing.T ) {
7678 m .Properties = map [string ]string {
77- "SecretsFile " : "a" ,
79+ "secretsFile " : "a" ,
7880 }
7981 err := s .Init (m )
8082 assert .Nil (t , err )
@@ -92,8 +94,8 @@ func TestSeparator(t *testing.T) {
9294func TestGetSecret (t * testing.T ) {
9395 m := secretstores.Metadata {}
9496 m .Properties = map [string ]string {
95- "SecretsFile " : "a" ,
96- "NestedSeparator " : "a" ,
97+ "secretsFile " : "a" ,
98+ "nestedSeparator " : "a" ,
9799 }
98100 s := localSecretStore {
99101 logger : logger .NewLogger ("test" ),
@@ -130,8 +132,8 @@ func TestGetSecret(t *testing.T) {
130132func TestBulkGetSecret (t * testing.T ) {
131133 m := secretstores.Metadata {}
132134 m .Properties = map [string ]string {
133- "SecretsFile " : "a" ,
134- "NestedSeparator " : "a" ,
135+ "secretsFile " : "a" ,
136+ "nestedSeparator " : "a" ,
135137 }
136138 s := localSecretStore {
137139 logger : logger .NewLogger ("test" ),
@@ -151,3 +153,60 @@ func TestBulkGetSecret(t *testing.T) {
151153 assert .Equal (t , "secret" , output .Data ["secret" ]["secret" ])
152154 })
153155}
156+
157+ func TestMultiValuedSecrets (t * testing.T ) {
158+ m := secretstores.Metadata {}
159+ m .Properties = map [string ]string {
160+ "secretsFile" : "a" ,
161+ "multiValued" : "true" ,
162+ }
163+ s := localSecretStore {
164+ logger : logger .NewLogger ("test" ),
165+ readLocalFileFn : func (secretsFile string ) (map [string ]interface {}, error ) {
166+ //nolint:gosec
167+ secretsJSON := `
168+ {
169+ "parent": {
170+ "child1": "12345",
171+ "child2": {
172+ "child3": "67890",
173+ "child4": "00000"
174+ }
175+ }
176+ }
177+ `
178+ var secrets map [string ]interface {}
179+ err := json .Unmarshal ([]byte (secretsJSON ), & secrets )
180+
181+ return secrets , err
182+ },
183+ }
184+ err := s .Init (m )
185+ require .NoError (t , err )
186+
187+ t .Run ("successfully retrieve a single multi-valued secret" , func (t * testing.T ) {
188+ req := secretstores.GetSecretRequest {
189+ Name : "parent" ,
190+ }
191+ resp , err := s .GetSecret (req )
192+ require .NoError (t , err )
193+ assert .Equal (t , map [string ]string {
194+ "child1" : "12345" ,
195+ "child2:child3" : "67890" ,
196+ "child2:child4" : "00000" ,
197+ }, resp .Data )
198+ })
199+
200+ t .Run ("successfully retrieve multi-valued secrets" , func (t * testing.T ) {
201+ req := secretstores.BulkGetSecretRequest {}
202+ resp , err := s .BulkGetSecret (req )
203+ require .NoError (t , err )
204+ assert .Equal (t , map [string ]map [string ]string {
205+ "parent" : {
206+ "child1" : "12345" ,
207+ "child2:child3" : "67890" ,
208+ "child2:child4" : "00000" ,
209+ },
210+ }, resp .Data )
211+ })
212+ }
0 commit comments