This repository was archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmemcached_test.go
More file actions
63 lines (52 loc) · 1.53 KB
/
memcached_test.go
File metadata and controls
63 lines (52 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cache
import (
"fmt"
"net"
"os"
"strings"
"testing"
"github.com/Shopify/go-encoding"
"github.com/bradfitz/gomemcache/memcache"
"github.com/stretchr/testify/require"
)
func ExampleNewMemcacheClient() {
memcacheClient := memcache.New("localhost:11211")
NewMemcacheClient(memcacheClient, encoding.NewValueEncoding(encoding.GobEncoding))
}
const defaultMemcachedPort = 11211
func testMemcached(t *testing.T) *memcache.Client {
if testing.Short() {
t.Skip("skipping in short mode")
}
serversStr := os.Getenv("MEMCACHED_SERVERS")
if len(serversStr) == 0 {
t.Skip("memcache client not configured")
return nil
}
servers := strings.Split(serversStr, ",")
for i, server := range servers {
if !strings.ContainsRune(server, ':') {
servers[i] = fmt.Sprintf("%s:%d", server, defaultMemcachedPort)
}
}
return memcache.New(servers...)
}
func Test_memcacheClient(t *testing.T) {
client := testMemcached(t)
for name, enc := range encodings {
t.Run(name, func(t *testing.T) {
testClient(t, NewMemcacheClient(client, enc), enc)
})
}
}
func Test_coalesceTimeoutError(t *testing.T) {
require.Nil(t, coalesceTimeoutError(nil))
timeoutError := memcache.ConnectTimeoutError{Addr: &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 1234}}
if err, ok := coalesceTimeoutError(&timeoutError).(net.Error); ok {
require.Equal(t, "connect tcp 127.0.0.1:1234: memcache: connect timeout", err.Error())
require.Equal(t, true, err.Timeout())
require.Equal(t, true, err.Temporary())
} else {
require.Fail(t, "should be a net.Error")
}
}