mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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:
parent
7e0408293f
commit
fe4799bd68
@ -254,30 +254,64 @@ func TestStateModuleOrphans_deepNestedNilConfig(t *testing.T) {
|
|||||||
|
|
||||||
func TestStateDeepCopy(t *testing.T) {
|
func TestStateDeepCopy(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
One, Two *State
|
State *State
|
||||||
F func(*State) interface{}
|
|
||||||
}{
|
}{
|
||||||
// Version
|
// Version
|
||||||
{
|
{
|
||||||
&State{Version: 5},
|
&State{Version: 5},
|
||||||
&State{Version: 5},
|
|
||||||
func(s *State) interface{} { return s.Version },
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// TFVersion
|
// TFVersion
|
||||||
{
|
{
|
||||||
&State{TFVersion: "5"},
|
&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 {
|
for i, tc := range cases {
|
||||||
t.Run(fmt.Sprintf("copy-%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("copy-%d", i), func(t *testing.T) {
|
||||||
actual := tc.F(tc.One.DeepCopy())
|
actual := tc.State.DeepCopy()
|
||||||
expected := tc.F(tc.Two)
|
expected := tc.State
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user