From 37c880c377adb51652d7b75f67005a8a8d00d37f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Sep 2016 19:16:29 -0700 Subject: [PATCH] Update reflectwalk to fix failing tests As part of working on ResourceConfig.DeepCopy, Equal I updated reflectwalk (to fix some issues in the new functions) but this introduced more issues in other parts of Terraform. This update fixes those. --- config/interpolate_walk_test.go | 18 ++++++------ .../mitchellh/reflectwalk/reflectwalk.go | 28 ++++++------------- vendor/vendor.json | 6 ++-- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/config/interpolate_walk_test.go b/config/interpolate_walk_test.go index 70067a99cb..35b8f1f579 100644 --- a/config/interpolate_walk_test.go +++ b/config/interpolate_walk_test.go @@ -179,13 +179,15 @@ func TestInterpolationWalker_replace(t *testing.T) { return tc.Value, nil } - w := &interpolationWalker{F: fn, Replace: true} - if err := reflectwalk.Walk(tc.Input, w); err != nil { - t.Fatalf("err: %s", err) - } - - if !reflect.DeepEqual(tc.Input, tc.Output) { - t.Fatalf("%d: bad:\n\nexpected:%#v\ngot:%#v", i, tc.Output, tc.Input) - } + t.Run(fmt.Sprintf("walk-%d", i), func(t *testing.T) { + w := &interpolationWalker{F: fn, Replace: true} + if err := reflectwalk.Walk(tc.Input, w); err != nil { + t.Fatalf("err: %s", err) + } + + if !reflect.DeepEqual(tc.Input, tc.Output) { + t.Fatalf("%d: bad:\n\nexpected:%#v\ngot:%#v", i, tc.Output, tc.Input) + } + }) } } diff --git a/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go b/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go index fafd443a43..6066014c49 100644 --- a/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go +++ b/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go @@ -76,6 +76,14 @@ func Walk(data, walker interface{}) (err error) { } func walk(v reflect.Value, w interface{}) (err error) { + // We preserve the original value here because if it is an interface + // type, we want to pass that directly into the walkPrimitive, so that + // we can set it. + originalV := v + if v.Kind() == reflect.Interface { + v = v.Elem() + } + // Determine if we're receiving a pointer and if so notify the walker. pointer := false if v.Kind() == reflect.Ptr { @@ -96,14 +104,6 @@ func walk(v reflect.Value, w interface{}) (err error) { }() } - // We preserve the original value here because if it is an interface - // type, we want to pass that directly into the walkPrimitive, so that - // we can set it. - originalV := v - if v.Kind() == reflect.Interface { - v = v.Elem() - } - k := v.Kind() if k >= reflect.Int && k <= reflect.Complex128 { k = reflect.Int @@ -143,12 +143,6 @@ func walkMap(v reflect.Value, w interface{}) error { for _, k := range v.MapKeys() { kv := v.MapIndex(k) - // if the map value type is an interface, we need to extract the Elem - // for the next call to walk - if kv.Kind() == reflect.Interface { - kv = kv.Elem() - } - if mw, ok := w.(MapWalker); ok { if err := mw.MapElem(v, k, kv); err != nil { return err @@ -208,12 +202,6 @@ func walkSlice(v reflect.Value, w interface{}) (err error) { for i := 0; i < v.Len(); i++ { elem := v.Index(i) - // if the value type is an interface, we need to extract the Elem - // for the next call to walk - if elem.Kind() == reflect.Interface { - elem = elem.Elem() - } - if sw, ok := w.(SliceWalker); ok { if err := sw.SliceElem(i, elem); err != nil { return err diff --git a/vendor/vendor.json b/vendor/vendor.json index 8bd359be97..4b9d1902e2 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1507,10 +1507,10 @@ "revision": "6e6954073784f7ee67b28f2d22749d6479151ed7" }, { - "checksumSHA1": "Qfbnn/PnYNR2ZHraUeHTxT4H7lM=", + "checksumSHA1": "5fFCVadmQVH6jqnB6Zd739s28QM=", "path": "github.com/mitchellh/reflectwalk", - "revision": "2d53f44828cae4c770d745a3560e37d3356774a6", - "revisionTime": "2016-09-27T21:55:38Z" + "revision": "84fc159ad78a797bb094a1e0c364392d837e1cd8", + "revisionTime": "2016-09-28T02:14:22Z" }, { "checksumSHA1": "/iig5lYSPCL3C8J7e4nTAevYNDE=",