testState shouldn't rely on mods from WriteState
The state returned from the testState helper shouldn't rely on any mutations caused by WriteState. The Init function (which is analogous to NewState) shoudl set any required fields.
This commit is contained in:
parent
fba5decae5
commit
501cbeaffe
|
@ -160,7 +160,6 @@ func testReadPlan(t *testing.T, path string) *terraform.Plan {
|
||||||
// testState returns a test State structure that we use for a lot of tests.
|
// testState returns a test State structure that we use for a lot of tests.
|
||||||
func testState() *terraform.State {
|
func testState() *terraform.State {
|
||||||
state := &terraform.State{
|
state := &terraform.State{
|
||||||
Version: 2,
|
|
||||||
Modules: []*terraform.ModuleState{
|
Modules: []*terraform.ModuleState{
|
||||||
&terraform.ModuleState{
|
&terraform.ModuleState{
|
||||||
Path: []string{"root"},
|
Path: []string{"root"},
|
||||||
|
@ -177,20 +176,7 @@ func testState() *terraform.State {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
state.Init()
|
state.Init()
|
||||||
|
return state
|
||||||
// Write and read the state so that it is properly initialized. We
|
|
||||||
// do this since we didn't call the normal NewState constructor.
|
|
||||||
var buf bytes.Buffer
|
|
||||||
if err := terraform.WriteState(state, &buf); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := terraform.ReadState(&buf)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testStateFile(t *testing.T, s *terraform.State) string {
|
func testStateFile(t *testing.T, s *terraform.State) string {
|
||||||
|
|
|
@ -677,6 +677,7 @@ func (s *State) init() {
|
||||||
if s.Version == 0 {
|
if s.Version == 0 {
|
||||||
s.Version = StateVersion
|
s.Version = StateVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.moduleByPath(rootModulePath) == nil {
|
if s.moduleByPath(rootModulePath) == nil {
|
||||||
s.addModule(rootModulePath)
|
s.addModule(rootModulePath)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue