mirror of
https://github.com/grafana/grafana.git
synced 2024-12-25 16:31:28 -06:00
Live: Clean up redis after test run (#93806)
This commit is contained in:
parent
c602041f4a
commit
df9925f3bb
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user