MCPcopy
hub / github.com/redis/go-redis / TestDigestHelperWithDelExArgs

Function TestDigestHelperWithDelExArgs

digest_test.go:441–498  ·  view source on GitHub ↗

TestDigestHelperWithDelExArgs validates conditional delete using client-side digest calculation

(t *testing.T)

Source from the content-addressed store, hash-verified

439// TestDigestHelperWithDelExArgs validates conditional delete using
440// client-side digest calculation
441func TestDigestHelperWithDelExArgs(t *testing.T) {
442 skipIfRedisBelow84(t)
443
444 ctx := context.Background()
445 client := redis.NewClient(&redis.Options{
446 Addr: "localhost:6379",
447 })
448 defer client.Close()
449
450 if err := client.Ping(ctx).Err(); err != nil {
451 t.Skipf("Redis not available: %v", err)
452 }
453
454 key := "helper-delexargs-test"
455 client.Del(ctx, key)
456
457 // Set value
458 value := "delete-me-please"
459 err := client.Set(ctx, key, value, 0).Err()
460 if err != nil {
461 t.Fatalf("Failed to set value: %v", err)
462 }
463
464 // Calculate digest client-side
465 clientDigest := helper.DigestString(value)
466 t.Logf("Client-calculated digest: 0x%016x", clientDigest)
467
468 // Try to delete with wrong digest (should fail)
469 wrongDigest := helper.DigestString("wrong")
470 deleted := client.DelExArgs(ctx, key, redis.DelExArgs{
471 Mode: "IFDEQ",
472 MatchDigest: wrongDigest,
473 }).Val()
474
475 if deleted != 0 {
476 t.Errorf("Delete with wrong client digest should fail")
477 } else {
478 t.Logf("✓ DelExArgs with wrong client digest correctly refused")
479 }
480
481 // Delete with correct client-calculated digest (should succeed)
482 deleted = client.DelExArgs(ctx, key, redis.DelExArgs{
483 Mode: "IFDEQ",
484 MatchDigest: clientDigest,
485 }).Val()
486
487 if deleted != 1 {
488 t.Errorf("Delete with correct client digest should succeed")
489 } else {
490 t.Logf("✓ DelExArgs with client-calculated digest succeeded")
491 }
492
493 // Verify deletion
494 exists := client.Exists(ctx, key).Val()
495 if exists != 0 {
496 t.Errorf("Key should be deleted")
497 }
498}

Callers

nothing calls this directly

Calls 10

DigestStringFunction · 0.92
skipIfRedisBelow84Function · 0.85
CloseMethod · 0.65
ErrMethod · 0.65
PingMethod · 0.65
DelMethod · 0.65
SetMethod · 0.65
DelExArgsMethod · 0.65
ExistsMethod · 0.65
ValMethod · 0.45

Tested by

no test coverage detected