diff --git a/api/filters/replacement/replacement.go b/api/filters/replacement/replacement.go index 0fec3449735..bff8bba4110 100644 --- a/api/filters/replacement/replacement.go +++ b/api/filters/replacement/replacement.go @@ -172,7 +172,7 @@ func getReplacement(nodes []*yaml.RNode, r *types.Replacement) (*yaml.RNode, err return nil, err } if rn.IsNilOrEmpty() { - return nil, fmt.Errorf("fieldPath `%s` is missing for replacement source %s", r.Source.FieldPath, r.Source) + return nil, fmt.Errorf("fieldPath `%s` is missing for replacement source %s", r.Source.FieldPath, r.Source.ResId) } return getRefinedValue(r.Source.Options, rn) diff --git a/api/filters/replacement/replacement_test.go b/api/filters/replacement/replacement_test.go index bae167c577b..9ca7a4e0e89 100644 --- a/api/filters/replacement/replacement_test.go +++ b/api/filters/replacement/replacement_test.go @@ -269,7 +269,7 @@ spec: - select: kind: Deployment `, - expectedErr: "multiple matches for selector ~G_~V_Deployment|~X|~N", + expectedErr: "multiple matches for selector {kind: Deployment}", }, "replacement has no source": { input: `apiVersion: v1 @@ -1514,9 +1514,9 @@ kind: Deployment metadata: name: pre-deploy annotations: - internal.config.kubernetes.io/previousNames: deploy,deploy - internal.config.kubernetes.io/previousKinds: CronJob,Deployment - internal.config.kubernetes.io/previousNamespaces: default,default + internal.config.kubernetes.io/previousNames: deploy;deploy + internal.config.kubernetes.io/previousKinds: CronJob;Deployment + internal.config.kubernetes.io/previousNamespaces: default;default spec: template: spec: @@ -1543,9 +1543,9 @@ kind: Deployment metadata: name: pre-deploy annotations: - internal.config.kubernetes.io/previousNames: deploy,deploy - internal.config.kubernetes.io/previousKinds: CronJob,Deployment - internal.config.kubernetes.io/previousNamespaces: default,default + internal.config.kubernetes.io/previousNames: deploy;deploy + internal.config.kubernetes.io/previousKinds: CronJob;Deployment + internal.config.kubernetes.io/previousNamespaces: default;default spec: template: spec: @@ -1586,7 +1586,7 @@ data: options: create: true `, - expectedErr: "fieldPath `data.httpPort` is missing for replacement source ~G_~V_ConfigMap|~X|ports-from:data.httpPort", + expectedErr: "fieldPath `data.httpPort` is missing for replacement source {kind: ConfigMap, name: ports-from}", }, "annotationSelector": { input: `apiVersion: v1 diff --git a/api/internal/accumulator/namereferencetransformer_test.go b/api/internal/accumulator/namereferencetransformer_test.go index 31ec435362f..eba8fb882ab 100644 --- a/api/internal/accumulator/namereferencetransformer_test.go +++ b/api/internal/accumulator/namereferencetransformer_test.go @@ -521,7 +521,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) { }, }).ResMap(), expectedErr: `updating name reference in 'rules/resourceNames' field of ` + - `'rbac.authorization.k8s.io_v1_ClusterRole|~X|cr'` + + `'{group: rbac.authorization.k8s.io, version: v1, kind: ClusterRole, name: cr}'` + `: considering field 'rules/resourceNames' of object apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole diff --git a/api/internal/utils/makeResIds.go b/api/internal/utils/makeResIds.go index 17f25168e6f..c2a2bfe4957 100644 --- a/api/internal/utils/makeResIds.go +++ b/api/internal/utils/makeResIds.go @@ -8,6 +8,8 @@ import ( "sigs.k8s.io/kustomize/kyaml/yaml" ) +const Separator = ";" + // MakeResIds returns all of an RNode's current and previous Ids func MakeResIds(n *yaml.RNode) ([]resid.ResId, error) { var result []resid.ResId @@ -36,9 +38,9 @@ func PrevIds(n *yaml.RNode) ([]resid.ResId, error) { if _, ok := annotations[BuildAnnotationPreviousNames]; !ok { return nil, nil } - names := strings.Split(annotations[BuildAnnotationPreviousNames], ",") - ns := strings.Split(annotations[BuildAnnotationPreviousNamespaces], ",") - kinds := strings.Split(annotations[BuildAnnotationPreviousKinds], ",") + names := strings.Split(annotations[BuildAnnotationPreviousNames], Separator) + ns := strings.Split(annotations[BuildAnnotationPreviousNamespaces], Separator) + kinds := strings.Split(annotations[BuildAnnotationPreviousKinds], Separator) // This should never happen if len(names) != len(ns) || len(names) != len(kinds) { return nil, fmt.Errorf( diff --git a/api/krusty/complexcomposition_test.go b/api/krusty/complexcomposition_test.go index 12855a40429..2ccf774c470 100644 --- a/api/krusty/complexcomposition_test.go +++ b/api/krusty/complexcomposition_test.go @@ -368,7 +368,7 @@ resources: t.Fatalf("Expected resource accumulation error") } if !strings.Contains( - err.Error(), "already registered id: apps_v1_StatefulSet|~X|my-sts") { + err.Error(), "already registered id: {group: apps, version: v1, kind: StatefulSet, name: my-sts}") { t.Fatalf("Unexpected err: %v", err) } } @@ -459,7 +459,7 @@ resources: t.Fatalf("Expected resource accumulation error") } if !strings.Contains( - err.Error(), "already registered id: apps_v1_StatefulSet|~X|my-sts") { + err.Error(), "already registered id: {group: apps, version: v1, kind: StatefulSet, name: my-sts}") { t.Fatalf("Unexpected err: %v", err) } } diff --git a/api/krusty/component_test.go b/api/krusty/component_test.go index 8629c2f12d3..cab7ac31377 100644 --- a/api/krusty/component_test.go +++ b/api/krusty/component_test.go @@ -589,7 +589,7 @@ components: - ../comp-b`), }, runPath: "prod", - expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|proxy", + expectedError: "may not add resource with an already registered id: {version: v1, kind: Deployment, name: proxy}", }, "components-cannot-add-the-same-base": { input: []FileGen{writeTestBase, @@ -608,7 +608,7 @@ components: - ../comp-b`), }, runPath: "prod", - expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|storefront", + expectedError: "may not add resource with an already registered id: {version: v1, kind: Deployment, name: storefront}", }, "components-cannot-add-bases-containing-the-same-resource": { input: []FileGen{writeTestBase, @@ -639,7 +639,7 @@ components: - ../comp-b`), }, runPath: "prod", - expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|proxy", + expectedError: "may not add resource with an already registered id: {version: v1, kind: Deployment, name: proxy}", }, } diff --git a/api/krusty/diamondcomposition_test.go b/api/krusty/diamondcomposition_test.go index 430e62563d6..d0475930866 100644 --- a/api/krusty/diamondcomposition_test.go +++ b/api/krusty/diamondcomposition_test.go @@ -141,7 +141,7 @@ resources: t.Fatalf("Expected resource accumulation error") } if !strings.Contains( - err.Error(), "already registered id: apps_v1_Deployment|~X|my-deployment") { + err.Error(), "already registered id: {group: apps, version: v1, kind: Deployment, name: my-deployment}") { t.Fatalf("Unexpected err: %v", err) } } diff --git a/api/krusty/repeatbase_test.go b/api/krusty/repeatbase_test.go index c68a9dccd07..26823ba6e13 100644 --- a/api/krusty/repeatbase_test.go +++ b/api/krusty/repeatbase_test.go @@ -128,7 +128,8 @@ spec: err := th.RunWithErr("mango", th.MakeDefaultOptions()) if !strings.Contains( - err.Error(), "multiple matches for Id apps_v1_Deployment|~X|banana; failed to find unique target for patch") { + err.Error(), "multiple matches for Id {group: apps, version: v1, kind: Deployment, name: banana};"+ + " failed to find unique target for patch {group: apps, version: v1, kind: Deployment, name: banana}") { t.Fatalf("Unexpected err: %v", err) } diff --git a/api/resmap/reswrangler.go b/api/resmap/reswrangler.go index 31bfe1fee98..291efb5bb71 100644 --- a/api/resmap/reswrangler.go +++ b/api/resmap/reswrangler.go @@ -215,7 +215,7 @@ func (m *resWrangler) GetById( if err != nil { return nil, fmt.Errorf( "%s; failed to find unique target for patch %s", - err.Error(), id.GvknString()) + err.Error(), id.String()) } return r, nil } diff --git a/api/resmap/reswrangler_test.go b/api/resmap/reswrangler_test.go index a47dddab7f1..dc743fcf0e1 100644 --- a/api/resmap/reswrangler_test.go +++ b/api/resmap/reswrangler_test.go @@ -356,9 +356,9 @@ func TestGetMatchingResourcesByAnyId(t *testing.T) { "metadata": map[string]interface{}{ "name": "new-bob", "annotations": map[string]interface{}{ - "internal.config.kubernetes.io/previousKinds": "ConfigMap,ConfigMap", - "internal.config.kubernetes.io/previousNames": "bob,bob2", - "internal.config.kubernetes.io/previousNamespaces": "default,default", + "internal.config.kubernetes.io/previousKinds": "ConfigMap;ConfigMap", + "internal.config.kubernetes.io/previousNames": "bob;bob2", + "internal.config.kubernetes.io/previousNamespaces": "default;default", }, }, }) diff --git a/api/resource/resource.go b/api/resource/resource.go index 7f8bfbd7db9..6c2445a1514 100644 --- a/api/resource/resource.go +++ b/api/resource/resource.go @@ -194,7 +194,7 @@ func (r *Resource) appendCsvAnnotation(name, value string) { } annotations := r.GetAnnotations() if existing, ok := annotations[name]; ok { - annotations[name] = existing + "," + value + annotations[name] = existing + utils.Separator + value } else { annotations[name] = value } @@ -218,7 +218,7 @@ func (r *Resource) getCsvAnnotation(name string) []string { if _, ok := annotations[name]; !ok { return nil } - return strings.Split(annotations[name], ",") + return strings.Split(annotations[name], utils.Separator) } // PrefixesSuffixesEquals is conceptually doing the same task diff --git a/api/resource/resource_test.go b/api/resource/resource_test.go index de6c495e0c9..533bff66203 100644 --- a/api/resource/resource_test.go +++ b/api/resource/resource_test.go @@ -996,9 +996,9 @@ metadata: kind: Secret metadata: annotations: - internal.config.kubernetes.io/previousKinds: Secret,Secret - internal.config.kubernetes.io/previousNames: oldName,oldName2 - internal.config.kubernetes.io/previousNamespaces: default,default + internal.config.kubernetes.io/previousKinds: Secret;Secret + internal.config.kubernetes.io/previousNames: oldName;oldName2 + internal.config.kubernetes.io/previousNamespaces: default;default name: newName `, }, @@ -1020,9 +1020,9 @@ metadata: kind: Secret metadata: annotations: - internal.config.kubernetes.io/previousKinds: Secret,Secret - internal.config.kubernetes.io/previousNames: oldName,oldName2 - internal.config.kubernetes.io/previousNamespaces: default,oldNamespace + internal.config.kubernetes.io/previousKinds: Secret;Secret + internal.config.kubernetes.io/previousNames: oldName;oldName2 + internal.config.kubernetes.io/previousNamespaces: default;oldNamespace name: newName namespace: newNamespace `, @@ -1089,9 +1089,9 @@ metadata: kind: Secret metadata: annotations: - internal.config.kubernetes.io/previousKinds: Secret,Secret - internal.config.kubernetes.io/previousNames: oldName,oldName2 - internal.config.kubernetes.io/previousNamespaces: default,oldNamespace + internal.config.kubernetes.io/previousKinds: Secret;Secret + internal.config.kubernetes.io/previousNames: oldName;oldName2 + internal.config.kubernetes.io/previousNamespaces: default;oldNamespace name: newName namespace: newNamespace `, @@ -1367,6 +1367,7 @@ spec: t.Fatalf("expected '%s', got '%s'", expected, actual) } } + func TestSetGvk(t *testing.T) { r, err := factory.FromBytes([]byte(` apiVersion: v1 @@ -1377,7 +1378,7 @@ spec: numReplicas: 1 `)) assert.NoError(t, err) - r.SetGvk(resid.GvkFromString("grp_ver_knd")) + r.SetGvk(resid.GvkFromString("group: grp, version: ver, kind: knd")) gvk := r.GetGvk() if expected, actual := "grp", gvk.Group; expected != actual { t.Fatalf("expected '%s', got '%s'", expected, actual) @@ -1390,6 +1391,7 @@ spec: } } +// nolint func TestRefBy(t *testing.T) { r, err := factory.FromBytes([]byte(` apiVersion: v1 @@ -1400,30 +1402,31 @@ spec: numReplicas: 1 `)) assert.NoError(t, err) - r.AppendRefBy(resid.FromString("gr1_ver1_knd1|ns1|name1")) + r.AppendRefBy(resid.FromString("{group: gr1, version: ver1, kind: knd1, namespace: ns1, name: name1}")) assert.Equal(t, r.RNode.MustString(), `apiVersion: v1 kind: Deployment metadata: name: clown annotations: - internal.config.kubernetes.io/refBy: gr1_ver1_knd1|ns1|name1 + internal.config.kubernetes.io/refBy: '{group: gr1, version: ver1, kind: knd1, name: name1, namespace: ns1}' spec: numReplicas: 1 `) - assert.Equal(t, r.GetRefBy(), []resid.ResId{resid.FromString("gr1_ver1_knd1|ns1|name1")}) + assert.Equal(t, r.GetRefBy(), []resid.ResId{resid.FromString( + "{group: gr1, version: ver1, kind: knd1, namespace: ns1, name: name1}")}) - r.AppendRefBy(resid.FromString("gr2_ver2_knd2|ns2|name2")) + r.AppendRefBy(resid.FromString("{group: gr2, version: ver2, kind: knd2, namespace: ns2, name: name2}")) assert.Equal(t, r.RNode.MustString(), `apiVersion: v1 kind: Deployment metadata: name: clown annotations: - internal.config.kubernetes.io/refBy: gr1_ver1_knd1|ns1|name1,gr2_ver2_knd2|ns2|name2 + internal.config.kubernetes.io/refBy: '{group: gr1, version: ver1, kind: knd1, name: name1, namespace: ns1};{group: gr2, version: ver2, kind: knd2, name: name2, namespace: ns2}' spec: numReplicas: 1 `) assert.Equal(t, r.GetRefBy(), []resid.ResId{ - resid.FromString("gr1_ver1_knd1|ns1|name1"), - resid.FromString("gr2_ver2_knd2|ns2|name2"), + resid.FromString("{group: gr1, version: ver1, kind: knd1, namespace: ns1, name: name1}"), + resid.FromString("{group: gr2, version: ver2, kind: knd2, namespace: ns2, name: name2}"), }) } diff --git a/kustomize/commands/build/writer.go b/kustomize/commands/build/writer.go index aef2a6a2542..531417b8e71 100644 --- a/kustomize/commands/build/writer.go +++ b/kustomize/commands/build/writer.go @@ -58,6 +58,9 @@ func (w Writer) write(path, fName string, res *resource.Resource) error { } func fileName(res *resource.Resource) string { - return strings.ToLower(res.GetGvk().StringWoEmptyField()) + - "_" + strings.ToLower(res.GetName()) + ".yaml" + gvk := res.GetGvk() + return strings.ToLower( + strings.Trim( + strings.Join( + []string{gvk.Group, gvk.Version, gvk.Kind, res.GetName()}, "_")+".yaml", "_")) } diff --git a/kyaml/resid/gvk.go b/kyaml/resid/gvk.go index 21dad78d333..cbffeae7194 100644 --- a/kyaml/resid/gvk.go +++ b/kyaml/resid/gvk.go @@ -4,6 +4,7 @@ package resid import ( + "fmt" "strings" "sigs.k8s.io/kustomize/kyaml/openapi" @@ -48,53 +49,27 @@ func ParseGroupVersion(apiVersion string) (group, version string) { // GvkFromString makes a Gvk from the output of Gvk.String(). func GvkFromString(s string) Gvk { - values := strings.Split(s, fieldSep) - if len(values) != 3 { - // ...then the string didn't come from Gvk.String(). - return Gvk{ - Group: noGroup, - Version: noVersion, - Kind: noKind, + result := Gvk{} + values := strings.Split(strings.Trim(s, "{}"), separator) + for i := range values { + value := strings.Split(values[i], ": ") + switch value[0] { + case "group": + result.Group = value[1] + case "version": + result.Version = value[1] + case "kind": + result.Kind = value[1] } } - g := values[0] - if g == noGroup { - g = "" - } - v := values[1] - if v == noVersion { - v = "" - } - k := values[2] - if k == noKind { - k = "" - } - return NewGvk(g, v, k) + return result } -// Values that are brief but meaningful in logs. -const ( - noGroup = "~G" - noVersion = "~V" - noKind = "~K" - fieldSep = "_" -) - // String returns a string representation of the GVK. func (x Gvk) String() string { - g := x.Group - if g == "" { - g = noGroup - } - v := x.Version - if v == "" { - v = noVersion - } - k := x.Kind - if k == "" { - k = noKind - } - return strings.Join([]string{g, v, k}, fieldSep) + bytes, _ := yaml.Marshal(x) + idString := strings.Join(strings.Split(strings.TrimSpace(string(bytes)), "\n"), separator) + return fmt.Sprintf("{%s}", idString) } // ApiVersion returns the combination of Group and Version @@ -108,22 +83,6 @@ func (x Gvk) ApiVersion() string { return sb.String() } -// StringWoEmptyField returns a string representation of the GVK. Non-exist -// fields will be omitted. -func (x Gvk) StringWoEmptyField() string { - var s []string - if x.Group != "" { - s = append(s, x.Group) - } - if x.Version != "" { - s = append(s, x.Version) - } - if x.Kind != "" { - s = append(s, x.Kind) - } - return strings.Join(s, fieldSep) -} - // Equals returns true if the Gvk's have equal fields. func (x Gvk) Equals(o Gvk) bool { return x.Group == o.Group && x.Version == o.Version && x.Kind == o.Kind diff --git a/kyaml/resid/gvk_test.go b/kyaml/resid/gvk_test.go index cb3b9faddd0..9b68734818e 100644 --- a/kyaml/resid/gvk_test.go +++ b/kyaml/resid/gvk_test.go @@ -85,16 +85,15 @@ func TestIsLessThan1(t *testing.T) { var stringTests = []struct { x Gvk s string - r string }{ - {Gvk{}, "~G_~V_~K", ""}, - {Gvk{Kind: "k"}, "~G_~V_k", "k"}, - {Gvk{Version: "v"}, "~G_v_~K", "v"}, - {Gvk{Version: "v", Kind: "k"}, "~G_v_k", "v_k"}, - {Gvk{Group: "g"}, "g_~V_~K", "g"}, - {Gvk{Group: "g", Kind: "k"}, "g_~V_k", "g_k"}, - {Gvk{Group: "g", Version: "v"}, "g_v_~K", "g_v"}, - {Gvk{Group: "g", Version: "v", Kind: "k"}, "g_v_k", "g_v_k"}, + {Gvk{}, "{{}}"}, + {Gvk{Kind: "k"}, "{kind: k}"}, + {Gvk{Version: "v"}, "{version: v}"}, + {Gvk{Version: "v", Kind: "k"}, "{version: v, kind: k}"}, + {Gvk{Group: "g"}, "{group: g}"}, + {Gvk{Group: "g", Kind: "k"}, "{group: g, kind: k}"}, + {Gvk{Group: "g", Version: "v"}, "{group: g, version: v}"}, + {Gvk{Group: "g", Version: "v", Kind: "k"}, "{group: g, version: v, kind: k}"}, } func TestString(t *testing.T) { @@ -127,12 +126,6 @@ func TestApiVersion(t *testing.T) { } } -func TestStringWoEmptyField(t *testing.T) { - for _, hey := range stringTests { - assert.Equal(t, hey.r, hey.x.StringWoEmptyField()) - } -} - func TestParseGroupVersion(t *testing.T) { tests := []struct { input string diff --git a/kyaml/resid/resid.go b/kyaml/resid/resid.go index 9a51c3716e1..b90640d3223 100644 --- a/kyaml/resid/resid.go +++ b/kyaml/resid/resid.go @@ -4,8 +4,11 @@ package resid import ( + "fmt" "reflect" "strings" + + "sigs.k8s.io/kustomize/kyaml/yaml" ) // ResId is an identifier of a k8s resource object. @@ -39,47 +42,37 @@ func NewResIdKindOnly(k string, n string) ResId { const ( noNamespace = "~X" noName = "~N" - separator = "|" + separator = ", " TotallyNotANamespace = "_non_namespaceable_" DefaultNamespace = "default" ) // String of ResId based on GVK, name and prefix func (id ResId) String() string { - ns := id.Namespace - if ns == "" { - ns = noNamespace - } - nm := id.Name - if nm == "" { - nm = noName - } - return strings.Join( - []string{id.Gvk.String(), ns, nm}, separator) + bytes, _ := yaml.Marshal(id) + idString := strings.Join(strings.Split(strings.TrimSpace(string(bytes)), "\n"), separator) + return fmt.Sprintf("{%s}", idString) } func FromString(s string) ResId { - values := strings.Split(s, separator) - g := GvkFromString(values[0]) - - ns := values[1] - if ns == noNamespace { - ns = "" + result := ResId{} + values := strings.Split(strings.Trim(s, "{}"), separator) + for i := range values { + value := strings.Split(values[i], ": ") + switch value[0] { + case "group": + result.Gvk.Group = value[1] + case "version": + result.Gvk.Version = value[1] + case "kind": + result.Gvk.Kind = value[1] + case "name": + result.Name = value[1] + case "namespace": + result.Namespace = value[1] + } } - nm := values[2] - if nm == noName { - nm = "" - } - return ResId{ - Gvk: g, - Namespace: ns, - Name: nm, - } -} - -// GvknString of ResId based on GVK and name -func (id ResId) GvknString() string { - return id.Gvk.String() + separator + id.Name + return result } // GvknEquals returns true if the other id matches diff --git a/kyaml/resid/resid_test.go b/kyaml/resid/resid_test.go index 0ad979ce88c..89a11bddccc 100644 --- a/kyaml/resid/resid_test.go +++ b/kyaml/resid/resid_test.go @@ -5,6 +5,8 @@ package resid import ( "testing" + + "github.com/stretchr/testify/assert" ) var resIdStringTests = []struct { @@ -17,7 +19,7 @@ var resIdStringTests = []struct { Gvk: Gvk{Group: "g", Version: "v", Kind: "k"}, Name: "nm", }, - "g_v_k|ns|nm", + "{group: g, version: v, kind: k, name: nm, namespace: ns}", }, { ResId{ @@ -25,7 +27,7 @@ var resIdStringTests = []struct { Gvk: Gvk{Version: "v", Kind: "k"}, Name: "nm", }, - "~G_v_k|ns|nm", + "{version: v, kind: k, name: nm, namespace: ns}", }, { ResId{ @@ -33,7 +35,7 @@ var resIdStringTests = []struct { Gvk: Gvk{Kind: "k"}, Name: "nm", }, - "~G_~V_k|ns|nm", + "{kind: k, name: nm, namespace: ns}", }, { ResId{ @@ -41,126 +43,34 @@ var resIdStringTests = []struct { Gvk: Gvk{}, Name: "nm", }, - "~G_~V_~K|ns|nm", - }, - { - ResId{ - Gvk: Gvk{}, - Name: "nm", - }, - "~G_~V_~K|~X|nm", + "{name: nm, namespace: ns}", }, { ResId{ Gvk: Gvk{}, Name: "nm", }, - "~G_~V_~K|~X|nm", + "{name: nm}", }, { ResId{ Gvk: Gvk{}, }, - "~G_~V_~K|~X|~N", - }, - { - ResId{ - Gvk: Gvk{}, - }, - "~G_~V_~K|~X|~N", + "{{}}", }, { ResId{}, - "~G_~V_~K|~X|~N", + "{{}}", }, } func TestResIdString(t *testing.T) { for _, hey := range resIdStringTests { - if hey.x.String() != hey.s { - t.Fatalf("Actual: %v, Expected: '%s'", hey.x, hey.s) - } - } -} - -var gvknStringTests = []struct { - x ResId - s string -}{ - { - ResId{ - Namespace: "ns", - Gvk: Gvk{Group: "g", Version: "v", Kind: "k"}, - Name: "nm", - }, - "g_v_k|nm", - }, - { - ResId{ - Namespace: "ns", - Gvk: Gvk{Version: "v", Kind: "k"}, - Name: "nm", - }, - "~G_v_k|nm", - }, - { - ResId{ - Namespace: "ns", - Gvk: Gvk{Kind: "k"}, - Name: "nm", - }, - "~G_~V_k|nm", - }, - { - ResId{ - Namespace: "ns", - Gvk: Gvk{}, - Name: "nm", - }, - "~G_~V_~K|nm", - }, - { - ResId{ - Gvk: Gvk{}, - Name: "nm", - }, - "~G_~V_~K|nm", - }, - { - ResId{ - Gvk: Gvk{}, - Name: "nm", - }, - "~G_~V_~K|nm", - }, - { - ResId{ - Gvk: Gvk{}, - }, - "~G_~V_~K|", - }, - { - ResId{ - Gvk: Gvk{}, - }, - "~G_~V_~K|", - }, - { - ResId{}, - "~G_~V_~K|", - }, -} - -func TestGvknString(t *testing.T) { - for _, hey := range gvknStringTests { - if hey.x.GvknString() != hey.s { - t.Fatalf("Actual: %s, Expected: '%s'", hey.x.GvknString(), hey.s) - } + assert.Equal(t, hey.x.String(), hey.s) } } func TestResIdEquals(t *testing.T) { - var GvknEqualsTest = []struct { id1 ResId id2 ResId diff --git a/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go b/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go index 0a7e0a291b1..3c388535f82 100644 --- a/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go +++ b/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go @@ -218,7 +218,7 @@ spec: t.Fatalf("No match should return an error") } if err.Error() != - "resource with name service does not match a config with the following GVK [~G_~V_Deployment]" { + "resource with name service does not match a config with the following GVK [{kind: Deployment}]" { t.Fatalf("Unexpected error: %v", err) } }