Merge "Add INFO.yaml"
[iec.git] / src / foundation / api / revel / cache / memcached_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
13 // These tests require memcached running on localhost:11211 (the default)
14 const testServer = "localhost:11211"
15
16 var newMemcachedCache = func(t *testing.T, defaultExpiration time.Duration) Cache {
17         c, err := net.Dial("tcp", testServer)
18         if err == nil {
19                 if _, err = c.Write([]byte("flush_all\r\n")); err != nil {
20                         t.Errorf("Write failed: %s", err)
21                 }
22                 _ = c.Close()
23                 return NewMemcachedCache([]string{testServer}, defaultExpiration)
24         }
25         t.Errorf("couldn't connect to memcached on %s", testServer)
26         t.FailNow()
27         panic("")
28 }
29
30 func TestMemcachedCache_TypicalGetSet(t *testing.T) {
31         typicalGetSet(t, newMemcachedCache)
32 }
33
34 func TestMemcachedCache_IncrDecr(t *testing.T) {
35         incrDecr(t, newMemcachedCache)
36 }
37
38 func TestMemcachedCache_Expiration(t *testing.T) {
39         expiration(t, newMemcachedCache)
40 }
41
42 func TestMemcachedCache_EmptyCache(t *testing.T) {
43         emptyCache(t, newMemcachedCache)
44 }
45
46 func TestMemcachedCache_Replace(t *testing.T) {
47         testReplace(t, newMemcachedCache)
48 }
49
50 func TestMemcachedCache_Add(t *testing.T) {
51         testAdd(t, newMemcachedCache)
52 }
53
54 func TestMemcachedCache_GetMulti(t *testing.T) {
55         testGetMulti(t, newMemcachedCache)
56 }