mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Add RNode.IsNilOrEmpty and test.
This commit is contained in:
@@ -383,6 +383,15 @@ func (rn *RNode) IsTaggedNull() bool {
|
|||||||
return !rn.IsNil() && IsYNodeTaggedNull(rn.YNode())
|
return !rn.IsNil() && IsYNodeTaggedNull(rn.YNode())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNilOrEmpty is true if the node is nil,
|
||||||
|
// has no YNode, or has YNode that appears empty.
|
||||||
|
func (rn *RNode) IsNilOrEmpty() bool {
|
||||||
|
return rn.IsNil() ||
|
||||||
|
IsYNodeTaggedNull(rn.YNode()) ||
|
||||||
|
IsYNodeEmptyMap(rn.YNode()) ||
|
||||||
|
IsYNodeEmptySeq(rn.YNode())
|
||||||
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
@@ -323,3 +323,35 @@ func TestIsTaggedNull(t *testing.T) {
|
|||||||
t.Fatalf("empty list should not be tagged null")
|
t.Fatalf("empty list should not be tagged null")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRNodeIsNilOrEmpty(t *testing.T) {
|
||||||
|
var rn *RNode
|
||||||
|
|
||||||
|
if !rn.IsNilOrEmpty() {
|
||||||
|
t.Fatalf("uninitialized RNode should be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !NewRNode(nil).IsNilOrEmpty() {
|
||||||
|
t.Fatalf("missing value YNode should be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !MakeNullNode().IsNilOrEmpty() {
|
||||||
|
t.Fatalf("value tagged null should be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !NewMapRNode(nil).IsNilOrEmpty() {
|
||||||
|
t.Fatalf("empty map should be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
if NewMapRNode(&map[string]string{"foo": "bar"}).IsNilOrEmpty() {
|
||||||
|
t.Fatalf("non-empty map should not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !NewListRNode().IsNilOrEmpty() {
|
||||||
|
t.Fatalf("empty list should be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
if NewListRNode("foo").IsNilOrEmpty() {
|
||||||
|
t.Fatalf("non-empty list should not be empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user