command: Fix TestMetaBackend_configureNewWithState

This test was initially failing because its fixture had a state which our
new state models consider to be "empty", and thus it was not migrated.

After fixing that (by adding an output to the fixture), this revealed a
bug that the lineage was not being persisted through the migration. This
is fixed by using the statemgr.Migrate method instead of writing via the
normal Writer interface, which allows two cooperating state managers to
properly transfer the lineage and serial along with the state snapshot.
This commit is contained in:
Martin Atkins 2018-11-12 18:30:01 -08:00
parent 24046ab833
commit aacbe1d14b
3 changed files with 15 additions and 9 deletions

View File

@ -382,8 +382,10 @@ func (m *Meta) backendMigrateState_s_s(opts *backendMigrateOpts) error {
}
}
// Confirmed! Write.
if err := stateTwo.WriteState(one); err != nil {
// Confirmed! We'll have the statemgr package handle the migration, which
// includes preserving any lineage/serial information where possible, if
// both managers support such metadata.
if err := statemgr.Migrate(stateTwo, stateOne); err != nil {
return fmt.Errorf(strings.TrimSpace(errBackendStateCopy),
opts.OneType, opts.TwoType, err)
}

View File

@ -326,24 +326,23 @@ func TestMetaBackend_configureNewWithState(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if err := s.RefreshState(); err != nil {
state, err := statemgr.RefreshAndRead(s)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
state := s.State()
if state == nil {
t.Fatal("state is nil")
}
if testStateMgrCurrentLineage(s) != "backend-new-migrate" {
t.Fatalf("bad: %#v", state)
if got, want := testStateMgrCurrentLineage(s), "backend-new-migrate"; got != want {
t.Fatalf("lineage changed during migration\nnow: %s\nwas: %s", got, want)
}
// Write some state
state = states.NewState()
mark := markStateForMatching(state, "changing")
s.WriteState(state)
if err := s.PersistState(); err != nil {
if err := statemgr.WriteAndPersist(s, state); err != nil {
t.Fatalf("unexpected error: %s", err)
}

View File

@ -8,7 +8,12 @@
"path": [
"root"
],
"outputs": {},
"outputs": {
"foo": {
"type": "string",
"value": "bar"
}
},
"resources": {},
"depends_on": []
}