Skip to content

Commit

Permalink
backport of commit bac4e0a
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Mar 25, 2021
1 parent 5287cb0 commit 1181fe5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
9 changes: 5 additions & 4 deletions states/state_deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ func (o *ResourceInstanceObject) DeepCopy() *ResourceInstanceObject {
}

return &ResourceInstanceObject{
Value: o.Value,
Status: o.Status,
Private: private,
Dependencies: dependencies,
Value: o.Value,
Status: o.Status,
Private: private,
Dependencies: dependencies,
CreateBeforeDestroy: o.CreateBeforeDestroy,
}
}

Expand Down
38 changes: 33 additions & 5 deletions states/state_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package states

import (
"reflect"
"testing"

"github.com/go-test/deep"
Expand Down Expand Up @@ -191,6 +192,32 @@ func TestState(t *testing.T) {
}
}

func TestStateDeepCopyObject(t *testing.T) {
obj := &ResourceInstanceObject{
Value: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("id"),
}),
Private: []byte("private"),
Status: ObjectReady,
Dependencies: []addrs.ConfigResource{
{
Module: addrs.RootModule,
Resource: addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "test_instance",
Name: "bar",
},
},
},
CreateBeforeDestroy: true,
}

objCopy := obj.DeepCopy()
if !reflect.DeepEqual(obj, objCopy) {
t.Fatalf("not equal\n%#v\n%#v", obj, objCopy)
}
}

func TestStateDeepCopy(t *testing.T) {
state := NewState()

Expand All @@ -209,11 +236,12 @@ func TestStateDeepCopy(t *testing.T) {
Name: "baz",
}.Instance(addrs.IntKey(0)),
&ResourceInstanceObjectSrc{
Status: ObjectReady,
SchemaVersion: 1,
AttrsJSON: []byte(`{"woozles":"confuzles"}`),
Private: []byte("private data"),
Dependencies: []addrs.ConfigResource{},
Status: ObjectReady,
SchemaVersion: 1,
AttrsJSON: []byte(`{"woozles":"confuzles"}`),
Private: []byte("private data"),
Dependencies: []addrs.ConfigResource{},
CreateBeforeDestroy: true,
},
addrs.AbsProviderConfig{
Provider: addrs.NewDefaultProvider("test"),
Expand Down

0 comments on commit 1181fe5

Please sign in to comment.