diff --git a/state/local_test.go b/state/local_test.go index cfd327f8d..2210aa949 100644 --- a/state/local_test.go +++ b/state/local_test.go @@ -20,14 +20,17 @@ func TestLocalStateLocks(t *testing.T) { defer os.Remove(s.Path) // lock first - if err := s.Lock("test"); err != nil { + info := &LockInfo{ + Operation: "test", + } + lockID, err := s.Lock(info) + if err != nil { t.Fatal(err) } out, err := exec.Command("go", "run", "testdata/lockstate.go", s.Path).CombinedOutput() - if err != nil { - t.Fatal("unexpected lock failure", err) + t.Fatal("unexpected lock failure", err, string(out)) } if string(out) != "lock failed" { @@ -40,25 +43,26 @@ func TestLocalStateLocks(t *testing.T) { t.Fatal(err) } - if lockInfo.Info != "test" { + if lockInfo.Operation != "test" { t.Fatalf("invalid lock info %#v\n", lockInfo) } // a noop, since we unlock on exit - if err := s.Unlock(); err != nil { + if err := s.Unlock(lockID); err != nil { t.Fatal(err) } // local locks can re-lock - if err := s.Lock("test"); err != nil { + lockID, err = s.Lock(info) + if err != nil { t.Fatal(err) } // Unlock should be repeatable - if err := s.Unlock(); err != nil { + if err := s.Unlock(lockID); err != nil { t.Fatal(err) } - if err := s.Unlock(); err != nil { + if err := s.Unlock(lockID); err != nil { t.Fatal(err) } @@ -67,7 +71,6 @@ func TestLocalStateLocks(t *testing.T) { if _, err := os.Stat(lockInfoPath); !os.IsNotExist(err) { t.Fatal("lock info not removed") } - } func TestLocalState_pathOut(t *testing.T) { diff --git a/state/testdata/lockstate.go b/state/testdata/lockstate.go index ca8ff5af5..a23b758ef 100644 --- a/state/testdata/lockstate.go +++ b/state/testdata/lockstate.go @@ -19,10 +19,11 @@ func main() { Path: os.Args[1], } - err := s.Lock("test") + _, err := s.Lock(&state.LockInfo{Operation: "test", Info: "state locker"}) if err != nil { io.WriteString(os.Stderr, "lock failed") } + return }