Merge pull request #24313 from hashicorp/alisdair/fix-coverage-blips-in-statemgr-filesystem

states: Fix coverage blips in statemgr/filesystem
This commit is contained in:
Alisdair McDiarmid 2020-03-09 09:27:45 -04:00 committed by GitHub
commit 94d7236cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

View File

@ -298,6 +298,41 @@ func TestFilesystem_nonExist(t *testing.T) {
}
}
func TestFilesystem_lockUnlockWithoutWrite(t *testing.T) {
info := NewLockInfo()
info.Operation = "test"
ls := testFilesystem(t)
// Delete the just-created tempfile so that Lock recreates it
os.Remove(ls.path)
// Lock the state, and in doing so recreate the tempfile
lockID, err := ls.Lock(info)
if err != nil {
t.Fatal(err)
}
if !ls.created {
t.Fatal("should have marked state as created")
}
if err := ls.Unlock(lockID); err != nil {
t.Fatal(err)
}
_, err = os.Stat(ls.path)
if os.IsNotExist(err) {
// Success! Unlocking the state successfully deleted the tempfile
return
} else if err != nil {
t.Fatalf("unexpected error from os.Stat: %s", err)
} else {
os.Remove(ls.readPath)
t.Fatal("should have removed path, but exists")
}
}
func TestFilesystem_impl(t *testing.T) {
defer testOverrideVersion(t, "1.2.3")()
var _ Reader = new(Filesystem)