From ea342b793bfc85dcb8006e928ef93837c5e4b39e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Sep 2016 19:52:12 -0700 Subject: [PATCH] Update reflectwalk vendor to fix State.DeepCopy The real reasoning for this can be found in #9, #10, and #11. All these vendor updates aim to fix that issue, with minor adjustments --- terraform/state_test.go | 13 ++++--- .../mitchellh/reflectwalk/reflectwalk.go | 36 +++++++++++++------ vendor/vendor.json | 10 +++--- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/terraform/state_test.go b/terraform/state_test.go index b5a23fafb..569f5ef94 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -3,6 +3,7 @@ package terraform import ( "bytes" "encoding/json" + "fmt" "reflect" "strings" "testing" @@ -272,11 +273,13 @@ func TestStateDeepCopy(t *testing.T) { } for i, tc := range cases { - actual := tc.F(tc.One.DeepCopy()) - expected := tc.F(tc.Two) - if !reflect.DeepEqual(actual, expected) { - t.Fatalf("Bad: %d\n\n%s\n\n%s", i, actual, expected) - } + t.Run(fmt.Sprintf("copy-%d", i), func(t *testing.T) { + actual := tc.F(tc.One.DeepCopy()) + expected := tc.F(tc.Two) + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("Bad: %d\n\n%s\n\n%s", i, actual, expected) + } + }) } } diff --git a/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go b/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go index 6066014c4..ecce023e1 100644 --- a/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go +++ b/vendor/github.com/mitchellh/reflectwalk/reflectwalk.go @@ -76,19 +76,27 @@ 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. + // The logic here is convoluted but very important (tests will fail if + // almost any part is changed). I will try to explain here. + // + // First, we check if the value is an interface, if so, we really need + // to check the interface's VALUE to see whether it is a pointer (pointers + // to interfaces are not allowed). + // + // Check whether the value is then an interface. If so, then set pointer + // to true to notify the user. + // + // At this time, we also set "v" to be the dereferenced value. This is + // because once we've unwrapped the pointer we want to use that value. pointer := false - if v.Kind() == reflect.Ptr { + pointerV := v + if pointerV.Kind() == reflect.Interface { + pointerV = pointerV.Elem() + } + if pointerV.Kind() == reflect.Ptr { pointer = true - v = reflect.Indirect(v) + v = reflect.Indirect(pointerV) } if pw, ok := w.(PointerWalker); ok { if err = pw.PointerEnter(pointer); err != nil { @@ -104,6 +112,14 @@ 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 diff --git a/vendor/vendor.json b/vendor/vendor.json index 4b9d1902e..3e9621e11 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1474,8 +1474,8 @@ { "checksumSHA1": "EDAtec3XSbTjw6gWG+NNScows9M=", "path": "github.com/mitchellh/copystructure", - "revision": "8f3c396a26dadccbd29ee24c76c89166249cc16f", - "revisionTime": "2016-09-27T21:34:29Z" + "revision": "49a4444999946bce1882f9db0eb3ba0a44ed1fbb", + "revisionTime": "2016-09-28T02:49:35Z" }, { "path": "github.com/mitchellh/go-homedir", @@ -1507,10 +1507,10 @@ "revision": "6e6954073784f7ee67b28f2d22749d6479151ed7" }, { - "checksumSHA1": "5fFCVadmQVH6jqnB6Zd739s28QM=", + "checksumSHA1": "kXh6sdGViiRK0REpIWydJvpsyY0=", "path": "github.com/mitchellh/reflectwalk", - "revision": "84fc159ad78a797bb094a1e0c364392d837e1cd8", - "revisionTime": "2016-09-28T02:14:22Z" + "revision": "0c9480f65513be815a88d6076a3d8d95d4274236", + "revisionTime": "2016-09-28T02:49:03Z" }, { "checksumSHA1": "/iig5lYSPCL3C8J7e4nTAevYNDE=",