mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-04 23:28:20 +00:00
Newer versions of the redis go libraries include built-in support for compression of values going to and from redis. Since the controller is extremely chatty and makes heavy use of redis for caching, this reduces the amount of bandwidth requires significantly. This change should be backwards compatible since the redis libraries detect whether or not compression was used and does not error in the no compression case. Fixes #4256
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package cache
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/alicebob/miniredis"
|
|
"github.com/go-redis/redis/v8"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRedisSetCache(t *testing.T) {
|
|
mr, err := miniredis.Run()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer mr.Close()
|
|
assert.NotNil(t, mr)
|
|
|
|
t.Run("Successful set", func(t *testing.T) {
|
|
client := NewRedisCache(redis.NewClient(&redis.Options{Addr: mr.Addr()}), 60*time.Second)
|
|
err = client.Set(&Item{Key: "foo", Object: "bar"})
|
|
assert.NoError(t, err)
|
|
})
|
|
|
|
t.Run("Successful get", func(t *testing.T) {
|
|
var res string
|
|
client := NewRedisCache(redis.NewClient(&redis.Options{Addr: mr.Addr()}), 10*time.Second)
|
|
err = client.Get("foo", &res)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, res, "bar")
|
|
})
|
|
|
|
t.Run("Successful delete", func(t *testing.T) {
|
|
client := NewRedisCache(redis.NewClient(&redis.Options{Addr: mr.Addr()}), 10*time.Second)
|
|
err = client.Delete("foo")
|
|
assert.NoError(t, err)
|
|
})
|
|
|
|
t.Run("Cache miss", func(t *testing.T) {
|
|
var res string
|
|
client := NewRedisCache(redis.NewClient(&redis.Options{Addr: mr.Addr()}), 10*time.Second)
|
|
err = client.Get("foo", &res)
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "cache: key is missing")
|
|
})
|
|
}
|