X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ffoundation%2Fapi%2Frevel%2Fcache%2Fredis_test.go;fp=src%2Ffoundation%2Fapi%2Frevel%2Fcache%2Fredis_test.go;h=ad0b006303b81ff41d03bd89858766093344cb2a;hb=1d1ee6961c93781e1187d8c7faa868da6b2f01f4;hp=0000000000000000000000000000000000000000;hpb=56dd5e0f2164b37b40ac1daa188ccc618b4cbd19;p=iec.git diff --git a/src/foundation/api/revel/cache/redis_test.go b/src/foundation/api/revel/cache/redis_test.go new file mode 100644 index 0000000..ad0b006 --- /dev/null +++ b/src/foundation/api/revel/cache/redis_test.go @@ -0,0 +1,66 @@ +// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved. +// Revel Framework source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package cache + +import ( + "net" + "testing" + "time" + + "github.com/revel/config" + "github.com/revel/revel" +) + +// These tests require redis server running on localhost:6379 (the default) +const redisTestServer = "localhost:6379" + +var newRedisCache = func(t *testing.T, defaultExpiration time.Duration) Cache { + revel.Config = config.NewContext() + + c, err := net.Dial("tcp", redisTestServer) + if err == nil { + if _, err = c.Write([]byte("flush_all\r\n")); err != nil { + t.Errorf("Write failed: %s", err) + } + _ = c.Close() + + redisCache := NewRedisCache(redisTestServer, "", defaultExpiration) + if err = redisCache.Flush(); err != nil { + t.Errorf("Flush failed: %s", err) + } + return redisCache + } + t.Errorf("couldn't connect to redis on %s", redisTestServer) + t.FailNow() + panic("") +} + +func TestRedisCache_TypicalGetSet(t *testing.T) { + typicalGetSet(t, newRedisCache) +} + +func TestRedisCache_IncrDecr(t *testing.T) { + incrDecr(t, newRedisCache) +} + +func TestRedisCache_Expiration(t *testing.T) { + expiration(t, newRedisCache) +} + +func TestRedisCache_EmptyCache(t *testing.T) { + emptyCache(t, newRedisCache) +} + +func TestRedisCache_Replace(t *testing.T) { + testReplace(t, newRedisCache) +} + +func TestRedisCache_Add(t *testing.T) { + testAdd(t, newRedisCache) +} + +func TestRedisCache_GetMulti(t *testing.T) { + testGetMulti(t, newRedisCache) +}