@@ -17,6 +17,7 @@ limitations under the License.
17
17
package util
18
18
19
19
import (
20
+ "fmt"
20
21
"os"
21
22
"testing"
22
23
"time"
@@ -166,3 +167,37 @@ func TestMakeDir(t *testing.T) {
166
167
err = os .RemoveAll (targetTest )
167
168
assert .NoError (t , err )
168
169
}
170
+
171
+ func TestConvertTagsToMap (t * testing.T ) {
172
+ tests := []struct {
173
+ desc string
174
+ tags string
175
+ expectedOut map [string ]string
176
+ expectedErr error
177
+ }{
178
+ {
179
+ desc : "Improper KeyValuePair" ,
180
+ tags : "foo=bar=gar,lorem=ipsum" ,
181
+ expectedOut : nil ,
182
+ expectedErr : fmt .Errorf ("Tags '%s' are invalid, the format should like: 'key1=value1,key2=value2'" , "foo=bar=gar,lorem=ipsum" ),
183
+ },
184
+ {
185
+ desc : "Missing Key" ,
186
+ tags : "=bar,lorem=ipsum" ,
187
+ expectedOut : nil ,
188
+ expectedErr : fmt .Errorf ("Tags '%s' are invalid, the format should like: 'key1=value1,key2=value2'" , "=bar,lorem=ipsum" ),
189
+ },
190
+ {
191
+ desc : "Successful Input/Output" ,
192
+ tags : "foo=bar,lorem=ipsum" ,
193
+ expectedOut : map [string ]string {"foo" : "bar" , "lorem" : "ipsum" },
194
+ expectedErr : nil ,
195
+ },
196
+ }
197
+
198
+ for _ , test := range tests {
199
+ output , err := ConvertTagsToMap (test .tags )
200
+ assert .Equal (t , test .expectedOut , output , test .desc )
201
+ assert .Equal (t , test .expectedErr , err , test .desc )
202
+ }
203
+ }
0 commit comments