func TestLockStale(t *testing.T) { for i, test := range staleLockTests { lock := restic.Lock{ Time: test.timestamp, PID: test.pid, } Assert(t, lock.Stale() == test.stale, "TestStaleLock: test %d failed: expected stale: %v, got %v", i, test.stale, !test.stale) } }
func unlockRepo(lock *restic.Lock) error { if err := lock.Unlock(); err != nil { return err } for i := 0; i < len(globalLocks); i++ { if lock == globalLocks[i] { globalLocks = append(globalLocks[:i], globalLocks[i+1:]...) return nil } } return nil }
func unlockRepo(lock *restic.Lock) error { globalLocks.Lock() defer globalLocks.Unlock() debug.Log("unlockRepo", "unlocking repository") if err := lock.Unlock(); err != nil { debug.Log("unlockRepo", "error while unlocking: %v", err) return err } for i := 0; i < len(globalLocks.locks); i++ { if lock == globalLocks.locks[i] { globalLocks.locks = append(globalLocks.locks[:i], globalLocks.locks[i+1:]...) return nil } } return nil }
func TestLockStale(t *testing.T) { hostname, err := os.Hostname() OK(t, err) otherHostname := "other-" + hostname for i, test := range staleLockTests { lock := restic.Lock{ Time: test.timestamp, PID: test.pid, Hostname: hostname, } Assert(t, lock.Stale() == test.stale, "TestStaleLock: test %d failed: expected stale: %v, got %v", i, test.stale, !test.stale) lock.Hostname = otherHostname Assert(t, lock.Stale() == test.staleOnOtherHost, "TestStaleLock: test %d failed: expected staleOnOtherHost: %v, got %v", i, test.staleOnOtherHost, !test.staleOnOtherHost) } }