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
This commit is contained in:
Mitchell Hashimoto 2016-09-27 19:52:12 -07:00
parent 37c880c377
commit ea342b793b
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 39 additions and 20 deletions

View File

@ -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)
}
})
}
}

View File

@ -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

10
vendor/vendor.json vendored
View File

@ -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=",