Add failing test for nil IsntanceState in State

A nil InstanceState within State/Modules/Resources/Deposed will panic
during a deep copy. The panic needs to be fixed in copystructure, but
the nil probably should have been normalized out before we got here too.
This commit is contained in:
James Bardin 2016-10-13 11:16:03 -04:00
parent 7e0408293f
commit fe4799bd68

View File

@ -254,30 +254,64 @@ func TestStateModuleOrphans_deepNestedNilConfig(t *testing.T) {
func TestStateDeepCopy(t *testing.T) {
cases := []struct {
One, Two *State
F func(*State) interface{}
State *State
}{
// Version
{
&State{Version: 5},
&State{Version: 5},
func(s *State) interface{} { return s.Version },
},
// TFVersion
{
&State{TFVersion: "5"},
&State{TFVersion: "5"},
func(s *State) interface{} { return s.TFVersion },
},
// Modules
{
&State{
Version: 6,
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"test_instance.foo": &ResourceState{
Primary: &InstanceState{
Meta: map[string]string{},
},
},
},
},
},
},
},
// Deposed
{
&State{
Version: 6,
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"test_instance.foo": &ResourceState{
Primary: &InstanceState{
Meta: map[string]string{},
},
Deposed: []*InstanceState{
{ID: "test"},
nil,
},
},
},
},
},
},
},
}
for i, tc := range cases {
t.Run(fmt.Sprintf("copy-%d", i), func(t *testing.T) {
actual := tc.F(tc.One.DeepCopy())
expected := tc.F(tc.Two)
actual := tc.State.DeepCopy()
expected := tc.State
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("Bad: %d\n\n%s\n\n%s", i, actual, expected)
t.Fatalf("Expected: %#v\nRecevied: %#v\n", expected, actual)
}
})
}