command: Fix TestRefresh_backup

The local filesystem state manager no longer creates backup files eagerly,
instead creating them only if on first write there is already a snapshot
present in the target file.

Therefore for this test to exercise the codepaths it intends to we must
create an initial state snapshot for it to overwrite, creating the backup
in the process.

There are several other tests for this behavior elsewhere, so this test
is primarily to verify that the refresh command is configuring the backend
appropriately to get the backups written in the desired location.
This commit is contained in:
Martin Atkins 2018-11-16 16:37:02 -08:00
parent 762a173c7f
commit 53b5b95ef5
1 changed files with 8 additions and 2 deletions

View File

@ -511,8 +511,14 @@ func TestRefresh_backup(t *testing.T) {
t.Fatalf("err: %s", err)
}
outPath := outf.Name()
outf.Close()
os.Remove(outPath)
defer outf.Close()
// Need to put some state content in the output file so that there's
// something to back up.
err = statefile.Write(statefile.New(state, "baz", 0), outf)
if err != nil {
t.Fatalf("error writing initial output state file %s", err)
}
// Backup path
backupf, err := ioutil.TempFile(testingDir, "tf")