-
Notifications
You must be signed in to change notification settings - Fork 8
/
memc_test.go
48 lines (37 loc) · 841 Bytes
/
memc_test.go
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
package tnt
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMem(t *testing.T) {
assert := assert.New(t)
primaryPort, tearDown := setUp(t)
if t.Skipped() {
return
}
defer tearDown()
conn, err := Connect(fmt.Sprintf("127.0.0.1:%d", primaryPort), nil)
if !assert.NoError(err) {
return
}
defer conn.Close()
key := fmt.Sprintf("key_%d", time.Now().Unix())
// get empty
data, err := conn.MemGet(key)
assert.NoError(err)
assert.Nil(data)
// set
err = conn.MemSet(key, []byte("hello"), uint32(time.Now().Add(time.Duration(time.Hour)).Unix()))
assert.NoError(err)
data, err = conn.MemGet(key)
assert.NoError(err)
assert.Equal([]byte("hello"), data)
// delete
err = conn.MemDelete(key)
assert.NoError(err)
data, err = conn.MemGet(key)
assert.NoError(err)
assert.Nil(data)
}