terraform: Diff.DeepCopy test to catch a bug that in copystructure

This was fixed upstream but keeping the test around to prevent
regressions.
This commit is contained in:
Mitchell Hashimoto 2016-10-03 11:13:49 -07:00
parent 742af8752b
commit 5053872e82
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 37 additions and 0 deletions

View File

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

View File

@ -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() {