| 61 | } |
| 62 | |
| 63 | func 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 | |
| 76 | func TestLocker_ExtendLock_Success(t *testing.T) { |
| 77 | db, mock := redismock.NewClientMock() |