(t *testing.T)
| 273 | } |
| 274 | |
| 275 | func TestMultiLocker_SingleKey(t *testing.T) { |
| 276 | db, mock := redismock.NewClientMock() |
| 277 | |
| 278 | // Single key scenario |
| 279 | multiLocker := NewMultiLocker(db, []string{"single-key"}, "test-value") |
| 280 | |
| 281 | assert.Equal(t, []string{"single-key"}, multiLocker.Keys()) |
| 282 | assert.Len(t, multiLocker.lockers, 1) |
| 283 | |
| 284 | // Lock |
| 285 | mock.ExpectSetNX("single-key", "test-value", 5*time.Second).SetVal(true) |
| 286 | |
| 287 | err := multiLocker.Lock(context.Background(), 5*time.Second) |
| 288 | assert.NoError(t, err) |
| 289 | |
| 290 | // Unlock |
| 291 | unlockScript := "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end" |
| 292 | mock.ExpectEval(unlockScript, []string{"single-key"}, "test-value").SetVal(int64(1)) |
| 293 | |
| 294 | err = multiLocker.Unlock(context.Background()) |
| 295 | assert.NoError(t, err) |
| 296 | assert.NoError(t, mock.ExpectationsWereMet()) |
| 297 | } |
nothing calls this directly
no test coverage detected