@@ -62,35 +62,40 @@ func TestConvertTagsToMap(t *testing.T) {
6262 testCases := []struct {
6363 desc string
6464 tags string
65+ tagsDelimiter string
6566 expectedOutput map [string ]string
6667 expectedError bool
6768 }{
6869 {
6970 desc : "should return empty map when tag is empty" ,
7071 tags : "" ,
72+ tagsDelimiter : "," ,
7173 expectedOutput : map [string ]string {},
7274 expectedError : false ,
7375 },
7476 {
75- desc : "sing valid tag should be converted" ,
76- tags : "key=value" ,
77+ desc : "sing valid tag should be converted" ,
78+ tags : "key=value" ,
79+ tagsDelimiter : "," ,
7780 expectedOutput : map [string ]string {
7881 "key" : "value" ,
7982 },
8083 expectedError : false ,
8184 },
8285 {
83- desc : "multiple valid tags should be converted" ,
84- tags : "key1=value1,key2=value2" ,
86+ desc : "multiple valid tags should be converted" ,
87+ tags : "key1=value1,key2=value2" ,
88+ tagsDelimiter : "," ,
8589 expectedOutput : map [string ]string {
8690 "key1" : "value1" ,
8791 "key2" : "value2" ,
8892 },
8993 expectedError : false ,
9094 },
9195 {
92- desc : "whitespaces should be trimmed" ,
93- tags : "key1=value1, key2=value2" ,
96+ desc : "whitespaces should be trimmed" ,
97+ tags : "key1=value1, key2=value2" ,
98+ tagsDelimiter : "," ,
9499 expectedOutput : map [string ]string {
95100 "key1" : "value1" ,
96101 "key2" : "value2" ,
@@ -100,31 +105,55 @@ func TestConvertTagsToMap(t *testing.T) {
100105 {
101106 desc : "should return error for invalid format" ,
102107 tags : "foo,bar" ,
108+ tagsDelimiter : "," ,
103109 expectedOutput : nil ,
104110 expectedError : true ,
105111 },
106112 {
107113 desc : "should return error for when key is missed" ,
108114 tags : "key1=value1,=bar" ,
115+ tagsDelimiter : "," ,
109116 expectedOutput : nil ,
110117 expectedError : true ,
111118 },
112119 {
113120 desc : "should return error for invalid characters in key" ,
114121 tags : "key/1=value1,<bar" ,
122+ tagsDelimiter : "," ,
115123 expectedOutput : nil ,
116124 expectedError : true ,
117125 },
118126 {
119127 desc : "should return success for special characters in value" ,
120128 tags : "key1=value1,key2=<>%&?/." ,
129+ tagsDelimiter : "," ,
121130 expectedOutput : map [string ]string {"key1" : "value1" , "key2" : "<>%&?/." },
122131 expectedError : false ,
123132 },
133+ {
134+ desc : "should return success for empty tagsDelimiter" ,
135+ tags : "key1=value1,key2=value2" ,
136+ tagsDelimiter : "" ,
137+ expectedOutput : map [string ]string {
138+ "key1" : "value1" ,
139+ "key2" : "value2" ,
140+ },
141+ expectedError : false ,
142+ },
143+ {
144+ desc : "should return success for special tagsDelimiter and tag values containing commas and equal sign" ,
145+ tags : "key1=aGVsbG8=;key2=value-2, value-3" ,
146+ tagsDelimiter : ";" ,
147+ expectedOutput : map [string ]string {
148+ "key1" : "aGVsbG8=" ,
149+ "key2" : "value-2, value-3" ,
150+ },
151+ expectedError : false ,
152+ },
124153 }
125154
126155 for i , c := range testCases {
127- m , err := ConvertTagsToMap (c .tags )
156+ m , err := ConvertTagsToMap (c .tags , c . tagsDelimiter )
128157 if c .expectedError {
129158 assert .NotNil (t , err , "TestCase[%d]: %s" , i , c .desc )
130159 } else {
0 commit comments