@@ -17,6 +17,7 @@ limitations under the License.
17
17
package add
18
18
19
19
import (
20
+ "reflect"
20
21
"testing"
21
22
22
23
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
@@ -103,6 +104,32 @@ func TestAddAnnotationManyArgs(t *testing.T) {
103
104
}
104
105
}
105
106
107
+ func TestAddAnnotationValueQuoted (t * testing.T ) {
108
+ fakeFS := fs .MakeFakeFS ()
109
+ fakeFS .WriteTestKustomization ()
110
+ v := validators .MakeHappyMapValidator (t )
111
+ cmd := newCmdAddAnnotation (fakeFS , v .Validator )
112
+ args := []string {"k1:\" v1\" " }
113
+ err := cmd .RunE (cmd , args )
114
+ v .VerifyCall ()
115
+ if err != nil {
116
+ t .Errorf ("unexpected error: %v" , err .Error ())
117
+ }
118
+ }
119
+
120
+ func TestAddAnnotationValueWithColon (t * testing.T ) {
121
+ fakeFS := fs .MakeFakeFS ()
122
+ fakeFS .WriteTestKustomization ()
123
+ v := validators .MakeHappyMapValidator (t )
124
+ cmd := newCmdAddAnnotation (fakeFS , v .Validator )
125
+ args := []string {"k1:\" v1:v2\" " }
126
+ err := cmd .RunE (cmd , args )
127
+ v .VerifyCall ()
128
+ if err != nil {
129
+ t .Errorf ("unexpected error: %v" , err .Error ())
130
+ }
131
+ }
132
+
106
133
func TestAddAnnotationNoKey (t * testing.T ) {
107
134
fakeFS := fs .MakeFakeFS ()
108
135
v := validators .MakeHappyMapValidator (t )
@@ -128,7 +155,7 @@ func TestAddAnnotationTooManyColons(t *testing.T) {
128
155
if err == nil {
129
156
t .Errorf ("expected an error" )
130
157
}
131
- if err .Error () != "invalid annotation: key:v1:v2 (too many colons)" {
158
+ if err .Error () != "invalid annotation: key:v1:v2 (too many colons, quote the values )" {
132
159
t .Errorf ("incorrect error: %v" , err .Error ())
133
160
}
134
161
}
@@ -238,7 +265,7 @@ func TestAddLabelTooManyColons(t *testing.T) {
238
265
if err == nil {
239
266
t .Errorf ("expected an error" )
240
267
}
241
- if err .Error () != "invalid label: key:v1:v2 (too many colons)" {
268
+ if err .Error () != "invalid label: key:v1:v2 (too many colons, quote the values )" {
242
269
t .Errorf ("incorrect error: %v" , err .Error ())
243
270
}
244
271
}
@@ -271,3 +298,35 @@ func TestAddLabelMultipleArgs(t *testing.T) {
271
298
t .Errorf ("incorrect error: %v" , err .Error ())
272
299
}
273
300
}
301
+
302
+ func TestConvertToMap (t * testing.T ) {
303
+ var o addMetadataOptions
304
+ args := "a:b,c:\" d\" ,e:\" f:g\" "
305
+ expected := make (map [string ]string )
306
+ expected ["a" ] = "b"
307
+ expected ["c" ] = "d"
308
+ expected ["e" ] = "f:g"
309
+
310
+ result , err := o .convertToMap (args )
311
+ if err != nil {
312
+ t .Errorf ("unexpected error: %v" , err .Error ())
313
+ }
314
+
315
+ eq := reflect .DeepEqual (expected , result )
316
+ if ! eq {
317
+ t .Errorf ("Converted map does not match expected, expected: %v, result: %v\n " , expected , result )
318
+ }
319
+ }
320
+
321
+ func TestConvertToMapError (t * testing.T ) {
322
+ var o addMetadataOptions
323
+ args := "a:b,c:\" d\" ,e:f:g"
324
+
325
+ _ , err := o .convertToMap (args )
326
+ if err == nil {
327
+ t .Errorf ("expected an error" )
328
+ }
329
+ if err .Error () != "invalid annotation: e:f:g (too many colons, quote the values)" {
330
+ t .Errorf ("incorrect error: %v" , err .Error ())
331
+ }
332
+ }
0 commit comments