MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestLocker_Unlock_Failure

Function TestLocker_Unlock_Failure

internal/lock/lock_test.go:63–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestLocker_Unlock_Failure(t *testing.T) {
64 db, mock := redismock.NewClientMock()
65 locker := NewLocker(db, "test-key", "test-value")
66
67 // Simulate a failed unlock (either lock expired or not the lock holder)
68 script := "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"
69 mock.ExpectEval(script, []string{"test-key"}, "test-value").SetVal(int64(0))
70
71 err := locker.Unlock(context.Background())
72 assert.EqualError(t, err, "unlock failed, either lock expired or you're not the lock holder for key test-key")
73 assert.NoError(t, mock.ExpectationsWereMet())
74}
75
76func TestLocker_ExtendLock_Success(t *testing.T) {
77 db, mock := redismock.NewClientMock()

Callers

nothing calls this directly

Calls 2

UnlockMethod · 0.95
NewLockerFunction · 0.85

Tested by

no test coverage detected