state/remote: increment serial properly

This commit is contained in:
Mitchell Hashimoto 2015-02-23 21:30:59 -08:00
parent c2bf600603
commit ed6128aa6e
2 changed files with 9 additions and 3 deletions

View File

@ -13,7 +13,7 @@ import (
type State struct { type State struct {
Client Client Client Client
state *terraform.State state, readState *terraform.State
} }
// StateReader impl. // StateReader impl.
@ -43,11 +43,14 @@ func (s *State) RefreshState() error {
} }
s.state = state s.state = state
s.readState = state
return nil return nil
} }
// StatePersister impl. // StatePersister impl.
func (s *State) PersistState() error { func (s *State) PersistState() error {
s.state.IncrementSerialMaybe(s.readState)
var buf bytes.Buffer var buf bytes.Buffer
if err := terraform.WriteState(s.state, &buf); err != nil { if err := terraform.WriteState(s.state, &buf); err != nil {
return err return err

View File

@ -7,8 +7,11 @@ import (
) )
func TestState(t *testing.T) { func TestState(t *testing.T) {
s := &State{Client: new(InmemClient)} s := &State{
s.WriteState(state.TestStateInitial()) Client: new(InmemClient),
state: state.TestStateInitial(),
readState: state.TestStateInitial(),
}
if err := s.PersistState(); err != nil { if err := s.PersistState(); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }