@@ -230,3 +230,55 @@ func TestSetKeyValueInMap(t *testing.T) {
230230 }
231231 }
232232}
233+
234+ func TestReplaceWithMap (t * testing.T ) {
235+ tests := []struct {
236+ desc string
237+ str string
238+ m map [string ]string
239+ expected string
240+ }{
241+ {
242+ desc : "empty string" ,
243+ str : "" ,
244+ expected : "" ,
245+ },
246+ {
247+ desc : "empty map" ,
248+ str : "" ,
249+ m : map [string ]string {},
250+ expected : "" ,
251+ },
252+ {
253+ desc : "empty key" ,
254+ str : "prefix-" + pvNameMetadata ,
255+ m : map [string ]string {"" : "pv" },
256+ expected : "prefix-" + pvNameMetadata ,
257+ },
258+ {
259+ desc : "empty value" ,
260+ str : "prefix-" + pvNameMetadata ,
261+ m : map [string ]string {pvNameMetadata : "" },
262+ expected : "prefix-" ,
263+ },
264+ {
265+ desc : "one replacement" ,
266+ str : "prefix-" + pvNameMetadata ,
267+ m : map [string ]string {pvNameMetadata : "pv" },
268+ expected : "prefix-pv" ,
269+ },
270+ {
271+ desc : "multiple replacements" ,
272+ str : pvcNamespaceMetadata + pvcNameMetadata ,
273+ m : map [string ]string {pvcNamespaceMetadata : "namespace" , pvcNameMetadata : "pvcname" },
274+ expected : "namespacepvcname" ,
275+ },
276+ }
277+
278+ for _ , test := range tests {
279+ result := replaceWithMap (test .str , test .m )
280+ if result != test .expected {
281+ t .Errorf ("test[%s]: unexpected output: %v, expected result: %v" , test .desc , result , test .expected )
282+ }
283+ }
284+ }
0 commit comments