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