state: deep copies are required
This commit is contained in:
parent
f3af221866
commit
cc8e6b6331
|
@ -19,7 +19,7 @@ type CacheState struct {
|
||||||
|
|
||||||
// StateReader impl.
|
// StateReader impl.
|
||||||
func (s *CacheState) State() *terraform.State {
|
func (s *CacheState) State() *terraform.State {
|
||||||
return s.state
|
return s.state.DeepCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteState will write and persist the state to the cache.
|
// WriteState will write and persist the state to the cache.
|
||||||
|
|
|
@ -10,7 +10,7 @@ type InmemState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *InmemState) State() *terraform.State {
|
func (s *InmemState) State() *terraform.State {
|
||||||
return s.state
|
return s.state.DeepCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *InmemState) RefreshState() error {
|
func (s *InmemState) RefreshState() error {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (s *LocalState) SetState(state *terraform.State) {
|
||||||
|
|
||||||
// StateReader impl.
|
// StateReader impl.
|
||||||
func (s *LocalState) State() *terraform.State {
|
func (s *LocalState) State() *terraform.State {
|
||||||
return s.state
|
return s.state.DeepCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteState for LocalState always persists the state as well.
|
// WriteState for LocalState always persists the state as well.
|
||||||
|
|
|
@ -18,7 +18,7 @@ type State struct {
|
||||||
|
|
||||||
// StateReader impl.
|
// StateReader impl.
|
||||||
func (s *State) State() *terraform.State {
|
func (s *State) State() *terraform.State {
|
||||||
return s.state
|
return s.state.DeepCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateWriter impl.
|
// StateWriter impl.
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestState(t *testing.T, s interface{}) {
|
||||||
current := TestStateInitial()
|
current := TestStateInitial()
|
||||||
|
|
||||||
// Check that the initial state is correct
|
// Check that the initial state is correct
|
||||||
if state := reader.State(); !reflect.DeepEqual(state, current) {
|
if state := reader.State(); !current.Equal(state) {
|
||||||
t.Fatalf("not initial: %#v\n\n%#v", state, current)
|
t.Fatalf("not initial: %#v\n\n%#v", state, current)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ func TestState(t *testing.T, s interface{}) {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if actual := reader.State(); !reflect.DeepEqual(actual, current) {
|
if actual := reader.State(); !actual.Equal(current) {
|
||||||
t.Fatalf("bad: %#v\n\n%#v", actual, current)
|
t.Fatalf("bad: %#v\n\n%#v", actual, current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ func TestState(t *testing.T, s interface{}) {
|
||||||
|
|
||||||
// Just set the serials the same... Then compare.
|
// Just set the serials the same... Then compare.
|
||||||
actual := reader.State()
|
actual := reader.State()
|
||||||
if !reflect.DeepEqual(actual, current) {
|
if !actual.Equal(current) {
|
||||||
t.Fatalf("bad: %#v\n\n%#v", actual, current)
|
t.Fatalf("bad: %#v\n\n%#v", actual, current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,12 @@ func TestState(t *testing.T, s interface{}) {
|
||||||
if reader.State().Serial <= serial {
|
if reader.State().Serial <= serial {
|
||||||
t.Fatalf("bad: expected %d, got %d", serial, reader.State().Serial)
|
t.Fatalf("bad: expected %d, got %d", serial, reader.State().Serial)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that State() returns a copy
|
||||||
|
reader.State().Serial++
|
||||||
|
if reflect.DeepEqual(reader.State(), current) {
|
||||||
|
t.Fatal("State() should return a copy")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue