File tree Expand file tree Collapse file tree 4 files changed +37
-4
lines changed
Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -91,8 +91,8 @@ func (wn *WNode) GetFieldValue(path string) (interface{}, error) {
9191 // Return value as slice for SequenceNode kind
9292 if yn .Kind == yaml .SequenceNode {
9393 var result []interface {}
94- for _ , node := range yn .Content {
95- result = append ( result , node . Value )
94+ if err := yn .Decode ( & result ); err != nil {
95+ return nil , err
9696 }
9797 return result , nil
9898 }
Original file line number Diff line number Diff line change @@ -377,6 +377,39 @@ func TestGetFieldValueReturnsSlice(t *testing.T) {
377377 }
378378}
379379
380+ func TestGetFieldValueReturnsSliceOfMappings (t * testing.T ) {
381+ bytes , err := yaml .Marshal (makeBigMap ())
382+ if err != nil {
383+ t .Fatalf ("unexpected yaml.Marshal err: %v" , err )
384+ }
385+ rNode , err := kyaml .Parse (string (bytes ))
386+ if err != nil {
387+ t .Fatalf ("unexpected yaml.Marshal err: %v" , err )
388+ }
389+ wn := FromRNode (rNode )
390+ expected := []interface {}{
391+ map [string ]interface {}{
392+ "field1" : "idx0foo" ,
393+ "field2" : "idx0bar" ,
394+ },
395+ map [string ]interface {}{
396+ "field1" : "idx1foo" ,
397+ "field2" : "idx1bar" ,
398+ },
399+ map [string ]interface {}{
400+ "field1" : "idx2foo" ,
401+ "field2" : "idx2bar" ,
402+ },
403+ }
404+ actual , err := wn .GetFieldValue ("those" )
405+ if err != nil {
406+ t .Fatalf ("error getting slice: %v" , err )
407+ }
408+ if diff := cmp .Diff (expected , actual ); diff != "" {
409+ t .Fatalf ("actual slice does not deep equal expected slice:\n %v" , diff )
410+ }
411+ }
412+
380413func TestGetFieldValueReturnsString (t * testing.T ) {
381414 wn := NewWNode ()
382415 if err := wn .UnmarshalJSON ([]byte (deploymentBiggerJson )); err != nil {
Original file line number Diff line number Diff line change @@ -19,3 +19,5 @@ exclude (
1919 sigs.k8s.io/kustomize/api v0.2.0
2020 sigs.k8s.io/kustomize/cmd/config v0.2.0
2121)
22+
23+ replace sigs.k8s.io/kustomize/api v0.7.0 => ../api
Original file line number Diff line number Diff line change @@ -623,8 +623,6 @@ k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl
623623mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed /go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc =
624624mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b /go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4 =
625625mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f /go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw =
626- sigs.k8s.io/kustomize/api v0.7.0 h1:djxH9k1izeU1BvdP1i23qqKwhmWu2BuKNEKr/Da7Dpw =
627- sigs.k8s.io/kustomize/api v0.7.0 /go.mod h1:3TxKEyaxwOIfHmRbQF14hDUSRmVQI0iSn8qDA5zaO/0 =
628626sigs.k8s.io/kustomize/cmd/config v0.8.6 h1:Rr7eyD+h32OfruN6V+cgUqHRpC2Y5ZnjjAPbjhKFLGE =
629627sigs.k8s.io/kustomize/cmd/config v0.8.6 /go.mod h1:e4PgdLUNnkf+Iapvjyb6gTG9DZQkDZIR6uS1Bv4YA6s =
630628sigs.k8s.io/kustomize/kyaml v0.10.3 h1:ARSJUMN/c3k31DYxRfZ+vp/UepUQjg9zCwny7Oj908I =
You can’t perform that action at this time.
0 commit comments