mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-06-06 23:23:42 +00:00
cedee416a8
* General improvements and bug fixes. * Improve tests coverage. * fixup! Improve tests coverage. * Update README.md with latest changes. * Fix the uint32 * Resolve issue with race condition for logging. * fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * Fix the test of the rate limiter * Add default ratelimit.json file * Update dependencies. * Significant refactor. * fixup! Significant refactor. * fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025 * fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package libpack_cache_redis
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/alicebob/miniredis/v2"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRedisClear(t *testing.T) {
|
|
// Create a mock Redis server
|
|
s, err := miniredis.Run()
|
|
if err != nil {
|
|
t.Fatalf("Failed to create mock redis server: %v", err)
|
|
}
|
|
defer s.Close()
|
|
|
|
// Create a Redis client
|
|
redisConfig, err := New(&RedisClientConfig{
|
|
RedisServer: s.Addr(),
|
|
RedisPassword: "",
|
|
RedisDB: 0,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("Failed to create Redis client: %v", err)
|
|
}
|
|
|
|
// Add some test data
|
|
ttl := time.Duration(60) * time.Second
|
|
err = redisConfig.Set("key1", []byte("value1"), ttl)
|
|
assert.NoError(t, err)
|
|
err = redisConfig.Set("key2", []byte("value2"), ttl)
|
|
assert.NoError(t, err)
|
|
err = redisConfig.Set("key3", []byte("value3"), ttl)
|
|
assert.NoError(t, err)
|
|
|
|
// Verify keys exist
|
|
count, err := redisConfig.CountQueries()
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(3), count, "Expected 3 keys before clearing cache")
|
|
|
|
// Clear the cache
|
|
err = redisConfig.Clear()
|
|
assert.NoError(t, err)
|
|
|
|
// Verify all keys are gone
|
|
count, err = redisConfig.CountQueries()
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(0), count, "Expected 0 keys after clearing cache")
|
|
|
|
// Verify individual keys are gone
|
|
_, found, err := redisConfig.Get("key1")
|
|
assert.NoError(t, err)
|
|
assert.False(t, found, "Key1 should be deleted after Clear")
|
|
_, found, err = redisConfig.Get("key2")
|
|
assert.NoError(t, err)
|
|
assert.False(t, found, "Key2 should be deleted after Clear")
|
|
_, found, err = redisConfig.Get("key3")
|
|
assert.NoError(t, err)
|
|
assert.False(t, found, "Key3 should be deleted after Clear")
|
|
}
|