mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
added test case for no values
This commit is contained in:
@@ -393,7 +393,7 @@ func (f FieldMatcher) Filter(rn *RNode) (*RNode, error) {
|
|||||||
return rn, nil
|
return rn, nil
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
case f.Value.YNode() != nil && rn.value.Value == f.Value.YNode().Value:
|
case GetValue(rn) == GetValue(f.Value):
|
||||||
return rn, nil
|
return rn, nil
|
||||||
default:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|||||||
@@ -137,6 +137,27 @@ func TestElementSetter(t *testing.T) {
|
|||||||
_, err = node.Pipe(ElementSetter{Values: []string{"b"}})
|
_, err = node.Pipe(ElementSetter{Values: []string{"b"}})
|
||||||
assert.EqualError(t, err, "wrong Node Kind for expected: ScalarNode was MappingNode: value: {a: b}")
|
assert.EqualError(t, err, "wrong Node Kind for expected: ScalarNode was MappingNode: value: {a: b}")
|
||||||
|
|
||||||
|
node = MustParse(`
|
||||||
|
- a: b
|
||||||
|
- c: d
|
||||||
|
`)
|
||||||
|
// If given a key and no values, ElementSetter will
|
||||||
|
// change node to be an empty list
|
||||||
|
rn, err = node.Pipe(ElementSetter{Keys: []string{"a"}})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Nil(t, rn)
|
||||||
|
assert.Equal(t, `[]
|
||||||
|
`, assertNoErrorString(t)(node.String()))
|
||||||
|
|
||||||
|
node = MustParse(`
|
||||||
|
- a: b
|
||||||
|
- c: d
|
||||||
|
`)
|
||||||
|
// Return error because ElementSetter will assume all elements are scalar when
|
||||||
|
// there is only value provided.
|
||||||
|
_, err = node.Pipe(ElementSetter{Values: []string{"b"}})
|
||||||
|
assert.EqualError(t, err, "wrong Node Kind for expected: ScalarNode was MappingNode: value: {a: b}")
|
||||||
|
|
||||||
node = MustParse(`
|
node = MustParse(`
|
||||||
- a
|
- a
|
||||||
- b
|
- b
|
||||||
|
|||||||
Reference in New Issue
Block a user