Skip to content

Commit 6af5087

Browse files
committed
test only for 8.4
1 parent 9131fcb commit 6af5087

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

digest_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ import (
77
"github.com/redis/go-redis/v9"
88
)
99

10+
// skipIfRedisBelow84 checks if Redis version is below 8.4 and skips the test if so
11+
func skipIfRedisBelow84(t *testing.T, client *redis.Client, ctx context.Context) {
12+
// Try to execute DIGEST command to check if it's supported
13+
// If it fails with "unknown command", Redis version is < 8.4
14+
err := client.Digest(ctx, "version-check-key").Err()
15+
if err != nil {
16+
errMsg := err.Error()
17+
// Check for "unknown command" error (Redis < 8.4)
18+
// The error message can vary slightly depending on Redis version
19+
if len(errMsg) >= 20 && errMsg[:20] == "ERR unknown command " {
20+
t.Skip("Skipping test: Redis version < 8.4 (DIGEST command not available)")
21+
}
22+
}
23+
}
24+
1025
// TestDigestBasic validates that the Digest command returns a uint64 value
1126
func TestDigestBasic(t *testing.T) {
1227
ctx := context.Background()
@@ -19,6 +34,8 @@ func TestDigestBasic(t *testing.T) {
1934
t.Skipf("Redis not available: %v", err)
2035
}
2136

37+
skipIfRedisBelow84(t, client, ctx)
38+
2239
client.Del(ctx, "digest-test-key")
2340

2441
// Set a value
@@ -61,6 +78,8 @@ func TestSetIFDEQWithDigest(t *testing.T) {
6178
t.Skipf("Redis not available: %v", err)
6279
}
6380

81+
skipIfRedisBelow84(t, client, ctx)
82+
6483
client.Del(ctx, "cas-test-key")
6584

6685
// Set initial value
@@ -123,6 +142,8 @@ func TestSetIFDNEWithDigest(t *testing.T) {
123142
t.Skipf("Redis not available: %v", err)
124143
}
125144

145+
skipIfRedisBelow84(t, client, ctx)
146+
126147
client.Del(ctx, "cad-test-key")
127148

128149
// Set initial value
@@ -185,6 +206,8 @@ func TestDelExArgsWithDigest(t *testing.T) {
185206
t.Skipf("Redis not available: %v", err)
186207
}
187208

209+
skipIfRedisBelow84(t, client, ctx)
210+
188211
client.Del(ctx, "del-test-key")
189212

190213
// Set a value

0 commit comments

Comments
 (0)