Add API Framework Revel Source Files
[iec.git] / src / foundation / api / revel / cache / redis_test.go
1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
4
5 package cache
6
7 import (
8         "net"
9         "testing"
10         "time"
11
12         "github.com/revel/config"
13         "github.com/revel/revel"
14 )
15
16 // These tests require redis server running on localhost:6379 (the default)
17 const redisTestServer = "localhost:6379"
18
19 var newRedisCache = func(t *testing.T, defaultExpiration time.Duration) Cache {
20         revel.Config = config.NewContext()
21
22         c, err := net.Dial("tcp", redisTestServer)
23         if err == nil {
24                 if _, err = c.Write([]byte("flush_all\r\n")); err != nil {
25                         t.Errorf("Write failed: %s", err)
26                 }
27                 _ = c.Close()
28
29                 redisCache := NewRedisCache(redisTestServer, "", defaultExpiration)
30                 if err = redisCache.Flush(); err != nil {
31                         t.Errorf("Flush failed: %s", err)
32                 }
33                 return redisCache
34         }
35         t.Errorf("couldn't connect to redis on %s", redisTestServer)
36         t.FailNow()
37         panic("")
38 }
39
40 func TestRedisCache_TypicalGetSet(t *testing.T) {
41         typicalGetSet(t, newRedisCache)
42 }
43
44 func TestRedisCache_IncrDecr(t *testing.T) {
45         incrDecr(t, newRedisCache)
46 }
47
48 func TestRedisCache_Expiration(t *testing.T) {
49         expiration(t, newRedisCache)
50 }
51
52 func TestRedisCache_EmptyCache(t *testing.T) {
53         emptyCache(t, newRedisCache)
54 }
55
56 func TestRedisCache_Replace(t *testing.T) {
57         testReplace(t, newRedisCache)
58 }
59
60 func TestRedisCache_Add(t *testing.T) {
61         testAdd(t, newRedisCache)
62 }
63
64 func TestRedisCache_GetMulti(t *testing.T) {
65         testGetMulti(t, newRedisCache)
66 }