mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Add tests for IsNil
This commit is contained in:
@@ -36,7 +36,7 @@ func MakeNullNode() *RNode {
|
|||||||
// IsMissingOrNull is true if the RNode is nil or explicitly tagged null.
|
// IsMissingOrNull is true if the RNode is nil or explicitly tagged null.
|
||||||
// TODO: make this a method on RNode.
|
// TODO: make this a method on RNode.
|
||||||
func IsMissingOrNull(node *RNode) bool {
|
func IsMissingOrNull(node *RNode) bool {
|
||||||
return IsNil(node) || node.YNode().Tag == NodeTagNull
|
return node.IsNil() || node.YNode().Tag == NodeTagNull
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated. Use IsMissingOrNull instead.
|
// Deprecated. Use IsMissingOrNull instead.
|
||||||
@@ -49,13 +49,8 @@ func IsEmptyMap(node *RNode) bool {
|
|||||||
return IsMissingOrNull(node) || IsYNodeEmptyMap(node.YNode())
|
return IsMissingOrNull(node) || IsYNodeEmptyMap(node.YNode())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNil return true if the node is nil, or its underlying YNode is nil.
|
|
||||||
func IsNil(node *RNode) bool {
|
|
||||||
return node == nil || node.YNode() == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsNull(node *RNode) bool {
|
func IsNull(node *RNode) bool {
|
||||||
return !IsNil(node) && node.YNode().Tag == NodeTagNull
|
return !node.IsNil() && node.YNode().Tag == NodeTagNull
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsFieldEmpty(node *MapNode) bool {
|
func IsFieldEmpty(node *MapNode) bool {
|
||||||
@@ -377,6 +372,11 @@ const (
|
|||||||
LabelsField = "labels"
|
LabelsField = "labels"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsNil is true if the node is nil, or its underlying YNode is nil.
|
||||||
|
func (rn *RNode) IsNil() bool {
|
||||||
|
return rn == nil || rn.YNode() == nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetMeta returns the ResourceMeta for an RNode
|
// GetMeta returns the ResourceMeta for an RNode
|
||||||
func (rn *RNode) GetMeta() (ResourceMeta, error) {
|
func (rn *RNode) GetMeta() (ResourceMeta, error) {
|
||||||
if IsMissingOrNull(rn) {
|
if IsMissingOrNull(rn) {
|
||||||
|
|||||||
@@ -220,3 +220,27 @@ func TestIsEmptyMap(t *testing.T) {
|
|||||||
t.Fatalf("input: empty map")
|
t.Fatalf("input: empty map")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsNil(t *testing.T) {
|
||||||
|
var rn *RNode
|
||||||
|
|
||||||
|
if !rn.IsNil() {
|
||||||
|
t.Fatalf("uninitialized RNode should be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !NewRNode(nil).IsNil() {
|
||||||
|
t.Fatalf("missing value YNode should be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if MakeNullNode().IsNil() {
|
||||||
|
t.Fatalf("value tagged null is not nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if NewMapRNode(nil).IsNil() {
|
||||||
|
t.Fatalf("empty map not nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if NewListRNode().IsNil() {
|
||||||
|
t.Fatalf("empty list not nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user