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.
|
||||
func testState() *terraform.State {
|
||||
state := &terraform.State{
|
||||
Version: 2,
|
||||
Modules: []*terraform.ModuleState{
|
||||
&terraform.ModuleState{
|
||||
Path: []string{"root"},
|
||||
|
@ -177,20 +176,7 @@ func testState() *terraform.State {
|
|||
},
|
||||
}
|
||||
state.Init()
|
||||
|
||||
// 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
|
||||
return state
|
||||
}
|
||||
|
||||
func testStateFile(t *testing.T, s *terraform.State) string {
|
||||
|
|
|
@ -677,6 +677,7 @@ func (s *State) init() {
|
|||
if s.Version == 0 {
|
||||
s.Version = StateVersion
|
||||
}
|
||||
|
||||
if s.moduleByPath(rootModulePath) == nil {
|
||||
s.addModule(rootModulePath)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue