Merge pull request #3433 from monopole/anotherTowards3412

Improve handling of empty resource maps.
This commit is contained in:
Jeff Regan
2021-01-09 07:20:19 -08:00
committed by GitHub
8 changed files with 73 additions and 19 deletions

View File

@@ -163,12 +163,7 @@ func (wn *WNode) GetString(path string) (string, error) {
// Map implements ifc.Kunstructured.
func (wn *WNode) Map() map[string]interface{} {
var result map[string]interface{}
if err := wn.node.YNode().Decode(&result); err != nil {
// Log and die since interface doesn't allow error.
log.Fatalf("failed to decode ynode: %v", err)
}
return result
return wn.node.Map()
}
// MarshalJSON implements ifc.Kunstructured.

View File

@@ -8,6 +8,7 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"sigs.k8s.io/kustomize/api/resid"
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
@@ -480,6 +481,10 @@ func TestGetSlice(t *testing.T) {
}
}
func TestMapEmpty(t *testing.T) {
assert.Equal(t, 0, len(NewWNode().Map()))
}
func TestMap(t *testing.T) {
wn := NewWNode()
if err := wn.UnmarshalJSON([]byte(deploymentLittleJson)); err != nil {