github.com/mika/distribution@v2.2.2-0.20160108133430-a75790e3d8e0+incompatible/registry/storage/cache/redis/redis_test.go (about) 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 -registry.storage.cache.redis 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 avialable, proceed without cache. 43 } 44 45 // Clear the database 46 if _, err := pool.Get().Do("FLUSHDB"); err != nil { 47 t.Fatalf("unexpected error flushing redis db: %v", err) 48 } 49 50 cachecheck.CheckBlobDescriptorCache(t, NewRedisBlobDescriptorCacheProvider(pool)) 51 }