Live: Clean up redis after test run (#93806)

This commit is contained in:
Todd Treece 2024-09-26 08:41:47 -04:00 committed by GitHub
parent c602041f4a
commit df9925f3bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@ import (
"testing"
"github.com/go-redis/redis/v8"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)
@ -31,7 +32,11 @@ func TestIntegrationRedisCacheStorage(t *testing.T) {
Addr: addr,
DB: db,
})
c := NewRedisFrameCache(redisClient, "A")
prefix := uuid.New().String()
t.Cleanup(redisCleanup(t, redisClient, prefix))
c := NewRedisFrameCache(redisClient, prefix)
require.NotNil(t, c)
testFrameCache(t, c)
@ -43,7 +48,20 @@ func TestIntegrationRedisCacheStorage(t *testing.T) {
require.NotZero(t, len(keys))
for _, key := range keys {
require.Equal(t, "A", key[:1])
require.True(t, strings.HasPrefix(key, "A"), "key", key)
require.True(t, strings.HasPrefix(key, prefix))
}
}
func redisCleanup(t *testing.T, redisClient *redis.Client, prefix string) func() {
return func() {
keys, err := redisClient.Keys(redisClient.Context(), prefix+"*").Result()
if err != nil {
require.NoError(t, err)
}
for _, key := range keys {
_, err := redisClient.Del(redisClient.Context(), key).Result()
require.NoError(t, err)
}
}
}