terraform: ResourceConfig.DeepCopy should handle the nil case

This commit is contained in:
Mitchell Hashimoto 2016-09-30 11:29:59 -07:00
parent 37f5c6ae26
commit d37bb87bf2
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 13 additions and 0 deletions

View File

@ -98,6 +98,11 @@ func NewResourceConfig(c *config.RawConfig) *ResourceConfig {
// to modify any of the structures that are part of the resource config without
// affecting the original configuration.
func (c *ResourceConfig) DeepCopy() *ResourceConfig {
// DeepCopying a nil should return a nil to avoid panics
if c == nil {
return nil
}
// Copy, this will copy all the exported attributes
copy, err := copystructure.Config{Lock: true}.Copy(c)
if err != nil {

View File

@ -239,6 +239,14 @@ func TestResourceConfigGet(t *testing.T) {
}
}
func TestResourceConfigDeepCopy_nil(t *testing.T) {
var nilRc *ResourceConfig
actual := nilRc.DeepCopy()
if actual != nil {
t.Fatalf("bad: %#v", actual)
}
}
func TestResourceConfigEqual_nil(t *testing.T) {
var nilRc *ResourceConfig
notNil := NewResourceConfig(nil)