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

Function TestDigestHelperMatchesRedis

digest_test.go:269–324  ·  digest_test.go::TestDigestHelperMatchesRedis

TestDigestHelperMatchesRedis validates that helper.DigestString produces the same digest as Redis DIGEST command

(t *testing.T)

Source from the content-addressed store, hash-verified

267// TestDigestHelperMatchesRedis validates that helper.DigestString produces
268// the same digest as Redis DIGEST command
269func TestDigestHelperMatchesRedis(t *testing.T) {
270 skipIfRedisBelow84(t)
271
272 ctx := context.Background()
273 client := redis.NewClient(&redis.Options{
274 Addr: "localhost:6379",
275 })
276 defer client.Close()
277
278 if err := client.Ping(ctx).Err(); err != nil {
279 t.Skipf("Redis not available: %v", err)
280 }
281
282 testCases := []struct {
283 name string
284 value string
285 }{
286 {"simple_string", "hello world"},
287 {"empty_string", ""},
288 {"single_char", "a"},
289 {"numeric_string", "12345"},
290 {"special_chars", "!@#$%^&*()"},
291 {"unicode", "こんにちは世界"},
292 {"json_like", `{"key": "value", "number": 123}`},
293 {"long_string", strings.Repeat("abcdefghij", 100)}, // 1000 chars
294 }
295
296 for _, tc := range testCases {
297 t.Run(tc.name, func(t *testing.T) {
298 key := "helper-test-" + tc.name
299
300 // Set value in Redis
301 err := client.Set(ctx, key, tc.value, 0).Err()
302 if err != nil {
303 t.Fatalf("Failed to set value: %v", err)
304 }
305
306 // Get digest from Redis
307 redisDigest := client.Digest(ctx, key).Val()
308
309 // Calculate digest using helper
310 helperDigest := helper.DigestString(tc.value)
311
312 // Compare
313 if redisDigest != helperDigest {
314 t.Errorf("Digest mismatch for %q:\n Redis: 0x%016x\n Helper: 0x%016x",
315 tc.value, redisDigest, helperDigest)
316 } else {
317 t.Logf("✓ %s: Redis and helper digests match (0x%016x)", tc.name, redisDigest)
318 }
319
320 // Cleanup
321 client.Del(ctx, key)
322 })
323 }
324}
325
326// TestDigestBytesHelperMatchesRedis validates that helper.DigestBytes produces

Callers

nothing calls this directly

Calls 10

DigestStringFunction · 0.92
skipIfRedisBelow84Function · 0.85
CloseMethod · 0.65
ErrMethod · 0.65
PingMethod · 0.65
SetMethod · 0.65
DigestMethod · 0.65
DelMethod · 0.65
RunMethod · 0.45
ValMethod · 0.45

Tested by

no test coverage detected