mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
add failing test for windows state locks
Refreshing a locked state on windows could return nil if the read path was locked, no state was yet written, and the read path is the same as the write path. Add a test that locks then refreshes a newly initialized state struct.
This commit is contained in:
parent
60bc16305a
commit
e10a7917e6
@ -166,3 +166,42 @@ func testLocalState(t *testing.T) *LocalState {
|
||||
|
||||
return ls
|
||||
}
|
||||
|
||||
// Make sure we can refresh while the state is locked
|
||||
func TestLocalState_refreshWhileLocked(t *testing.T) {
|
||||
f, err := ioutil.TempFile("", "tf")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
err = terraform.WriteState(TestStateInitial(), f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
s := &LocalState{Path: f.Name()}
|
||||
defer os.Remove(s.Path)
|
||||
|
||||
// lock first
|
||||
info := NewLockInfo()
|
||||
info.Operation = "test"
|
||||
lockID, err := s.Lock(info)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := s.Unlock(lockID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := s.RefreshState(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
readState := s.State()
|
||||
if readState == nil || readState.Lineage == "" {
|
||||
t.Fatal("missing state")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user