terraform: ResourceConfig.DeepCopy should handle the nil case
This commit is contained in:
parent
37f5c6ae26
commit
d37bb87bf2
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue