Add more resid test coverage.

This commit is contained in:
jregan
2019-02-16 11:22:32 -08:00
parent ef3b0672c5
commit d4d993a53c
10 changed files with 411 additions and 121 deletions

View File

@@ -22,23 +22,30 @@ import (
"sigs.k8s.io/kustomize/pkg/gvk"
)
// ResId conflates GroupVersionKind with a textual name to uniquely identify a kubernetes resource (object).
// ResId is an immutable identifier of a k8s resource object.
type ResId struct {
// Gvk of the resource.
gvKind gvk.Gvk
// original name of the resource before transformation.
// name of the resource before transformation.
name string
// namePrefix of the resource
// an untransformed resource has no prefix, fully transformed resource has an arbitrary number of prefixes
// concatenated together.
// namePrefix of the resource.
// An untransformed resource has no prefix.
// A fully transformed resource has an arbitrary
// number of prefixes concatenated together.
prefix string
// nameSuffix of the resource
// an untransformed resource has no suffix, fully transformed resource has an arbitrary number of suffixes
// concatenated together.
// nameSuffix of the resource.
// An untransformed resource has no suffix.
// A fully transformed resource has an arbitrary
// number of suffixes concatenated together.
suffix string
// namespace the resource belongs to
// an untransformed resource has no namespace, fully transformed resource has the namespace from
// the top most overlay
// Namespace the resource belongs to.
// An untransformed resource has no namespace.
// A fully transformed resource has the namespace
// from the top most overlay.
namespace string
}
@@ -108,10 +115,16 @@ func (n ResId) GvknString() string {
return n.gvKind.String() + separator + n.name
}
// GvknEquals return if two ResId have the same Group/Version/Kind and name
// The comparison excludes prefix and suffix
// GvknEquals returns true if the other id matches
// Group/Version/Kind/name.
func (n ResId) GvknEquals(id ResId) bool {
return n.gvKind.Equals(id.gvKind) && n.name == id.name
return n.name == id.name && n.gvKind.Equals(id.gvKind)
}
// NsGvknEquals returns true if the other id matches
// namespace/Group/Version/Kind/name.
func (n ResId) NsGvknEquals(id ResId) bool {
return n.namespace == id.namespace && n.GvknEquals(id)
}
// Gvk returns Group/Version/Kind of the resource.