| 1 |
package redis |
| 2 |
|
| 3 |
import ( |
| 4 |
"flag" |
| 5 |
"os" |
| 6 |
"testing" |
| 7 |
"time" |
| 8 |
|
| 9 |
"github.com/docker/distribution/registry/storage/cache/cachecheck" |
| 10 |
"github.com/garyburd/redigo/redis" |
| 11 |
) |
| 12 |
|
| 13 |
var redisAddr string |
| 14 |
|
| 15 |
func init() { |
| 16 |
flag.StringVar(&redisAddr, "test.registry.storage.cache.redis.addr", "", "configure the address of a test instance of redis") |
| 17 |
} |
| 18 |
|
| 19 |
// TestRedisLayerInfoCache exercises a live redis instance using the cache |
| 20 |
// implementation. |
| 21 |
func TestRedisBlobDescriptorCacheProvider(t *testing.T) { |
| 22 |
if redisAddr == "" { |
| 23 |
// fallback to an environement variable |
| 24 |
redisAddr = os.Getenv("TEST_REGISTRY_STORAGE_CACHE_REDIS_ADDR") |
| 25 |
} |
| 26 |
|
| 27 |
if redisAddr == "" { |
| 28 |
// skip if still not set |
| 29 |
t.Skip("please set -test.registry.storage.cache.redis.addr to test layer info cache against redis") |
| 30 |
} |
| 31 |
|
| 32 |
pool := &redis.Pool{ |
| 33 |
Dial: func() (redis.Conn, error) { |
| 34 |
return redis.Dial("tcp", redisAddr) |
| 35 |
}, |
| 36 |
MaxIdle: 1, |
| 37 |
MaxActive: 2, |
| 38 |
TestOnBorrow: func(c redis.Conn, t time.Time) error { |
| 39 |
_, err := c.Do("PING") |
| 40 |
return err |
| 41 |
}, |
| 42 |
Wait: false, // if a connection is not available, proceed without cache. |
| 43 |
} |
| 44 |
|
| 45 |
// Clear the database |
| 46 |
conn := pool.Get() |
| 47 |
if _, err := conn.Do("FLUSHDB"); err != nil { |
| 48 |
t.Fatalf("unexpected error flushing redis db: %v", err) |
| 49 |
} |
| 50 |
conn.Close() |
| 51 |
|
| 52 |
cachecheck.CheckBlobDescriptorCache(t, NewRedisBlobDescriptorCacheProvider(pool)) |
| 53 |
} |