From 5053872e82dcbf813d6a302cbe75e861ff15068e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 3 Oct 2016 11:13:49 -0700 Subject: [PATCH] terraform: Diff.DeepCopy test to catch a bug that in copystructure This was fixed upstream but keeping the test around to prevent regressions. --- terraform/diff.go | 4 ++++ terraform/diff_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/terraform/diff.go b/terraform/diff.go index b43e16ee8..33d27f714 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -292,6 +292,10 @@ func (d *ModuleDiff) String() string { return buf.String() } +func (d *ModuleDiff) GoString() string { + return fmt.Sprintf("*%#v", *d) +} + // InstanceDiff is the diff of a resource from some state to another. type InstanceDiff struct { mu sync.Mutex diff --git a/terraform/diff_test.go b/terraform/diff_test.go index faffcbbcc..6239bc413 100644 --- a/terraform/diff_test.go +++ b/terraform/diff_test.go @@ -115,6 +115,39 @@ func TestModuleDiff_ChangeType(t *testing.T) { } } +func TestDiff_DeepCopy(t *testing.T) { + cases := map[string]*Diff{ + "empty": &Diff{}, + + "basic diff": &Diff{ + Modules: []*ModuleDiff{ + &ModuleDiff{ + Path: []string{"root"}, + Resources: map[string]*InstanceDiff{ + "aws_instance.foo": &InstanceDiff{ + Attributes: map[string]*ResourceAttrDiff{ + "num": &ResourceAttrDiff{ + Old: "0", + New: "2", + }, + }, + }, + }, + }, + }, + }, + } + + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + dup := tc.DeepCopy() + if !reflect.DeepEqual(dup, tc) { + t.Fatalf("\n%#v\n\n%#v", dup, tc) + } + }) + } +} + func TestModuleDiff_Empty(t *testing.T) { diff := new(ModuleDiff) if !diff.Empty() {