|
|
|
|
@ -254,30 +254,66 @@ 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
|
|
|
|
|
// The nil values shouldn't be there if the State was properly init'ed,
|
|
|
|
|
// but the Copy should still work anyway.
|
|
|
|
|
{
|
|
|
|
|
&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)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|