mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-16 17:33:14 +00:00
Simplify map conversion logic
This commit is contained in:
@@ -140,23 +140,21 @@ func TestAddAnnotationNoKey(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid annotation: :nokey (empty key)" {
|
||||
if err.Error() != "invalid annotation: ':nokey' (need k:v pair where v may be quoted)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAnnotationTooManyColons(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomization()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddAnnotation(fakeFS, v.Validator)
|
||||
args := []string{"key:v1:v2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyNoCall()
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid annotation: key:v1:v2 (too many colons, quote the values)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,23 +248,21 @@ func TestAddLabelNoKey(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid label: :nokey (empty key)" {
|
||||
if err.Error() != "invalid label: ':nokey' (need k:v pair where v may be quoted)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddLabelTooManyColons(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomization()
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdAddLabel(fakeFS, v.Validator)
|
||||
args := []string{"key:v1:v2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyNoCall()
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid label: key:v1:v2 (too many colons, quote the values)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
v.VerifyCall()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,11 +297,12 @@ func TestAddLabelMultipleArgs(t *testing.T) {
|
||||
|
||||
func TestConvertToMap(t *testing.T) {
|
||||
var o addMetadataOptions
|
||||
args := "a:b,c:\"d\",e:\"f:g\""
|
||||
args := "a:b,c:\"d\",e:\"f:g\",g:h:k"
|
||||
expected := make(map[string]string)
|
||||
expected["a"] = "b"
|
||||
expected["c"] = "d"
|
||||
expected["e"] = "f:g"
|
||||
expected["g"] = "h:k"
|
||||
|
||||
result, err := o.convertToMap(args)
|
||||
if err != nil {
|
||||
@@ -320,13 +317,13 @@ func TestConvertToMap(t *testing.T) {
|
||||
|
||||
func TestConvertToMapError(t *testing.T) {
|
||||
var o addMetadataOptions
|
||||
args := "a:b,c:\"d\",e:f:g"
|
||||
args := "a:b,c:\"d\",:f:g"
|
||||
|
||||
_, err := o.convertToMap(args)
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "invalid annotation: e:f:g (too many colons, quote the values)" {
|
||||
if err.Error() != "invalid annotation: ':f:g' (need k:v pair where v may be quoted)" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user