-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
69 lines (59 loc) · 1.36 KB
/
client_test.go
File metadata and controls
69 lines (59 loc) · 1.36 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
64
65
66
67
68
69
package httpsqs
import (
"context"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
var (
_client = NewClient(&Config{
Addr: "127.0.0.1:1218",
Timeout: 0,
Password: "",
})
name = "queue_test"
ctx = context.Background()
)
func TestClient_Put(t *testing.T) {
bs, _ := json.Marshal(struct {
Name string
Title string
Age int
Money int
}{
"张三", "无产阶级", 30, 10000,
})
pos, err := _client.Put(ctx, name, string(bs))
assert.Nil(t, err)
assert.Less(t, int64(0), pos)
}
func TestClient_Get(t *testing.T) {
body, pos, err := _client.Get(ctx, name)
assert.Nil(t, err)
assert.Less(t, int64(0), pos)
assert.Less(t, 0, len(body))
t.Logf("queue pos: %d, data: %s", pos, body)
}
func TestClient_Status(t *testing.T) {
status, err := _client.Status(ctx, name)
assert.Nil(t, err)
t.Logf("queue status: %#v", status)
t.Logf("queue status: %s", status)
}
func TestClient_View(t *testing.T) {
body, err := _client.View(ctx, name, 1)
assert.Nil(t, err)
t.Logf("queue view data: %s", body)
}
func TestClient_SetMaxQueue(t *testing.T) {
maxLen := 100000000
err := _client.SetMaxQueue(ctx, name, maxLen)
assert.Nil(t, err)
status, err := _client.Status(ctx, name)
assert.Nil(t, err)
assert.Equal(t, int64(maxLen), status.MaxQueue)
}
func TestClient_Reset(t *testing.T) {
err := _client.Reset(ctx, name)
assert.Nil(t, err)
}