forked from beanstalkd/go-beanstalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tube_test.go
117 lines (102 loc) · 2.23 KB
/
tube_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package beanstalk
import (
"testing"
"time"
)
func TestTubePut(t *testing.T) {
c := NewConn(mock("put 0 0 0 3\r\nfoo\r\n", "INSERTED 1\r\n"))
id, err := c.Put([]byte("foo"), 0, 0, 0)
if err != nil {
t.Fatal(err)
}
if id != "1" {
t.Fatal("expected 1, got", id)
}
if err = c.Close(); err != nil {
t.Fatal(err)
}
}
func TestTubePeekReady(t *testing.T) {
c := NewConn(mock("peek-ready\r\n", "FOUND 1 1\r\nx\r\n"))
id, body, err := c.PeekReady()
if err != nil {
t.Fatal(err)
}
if id != "1" {
t.Fatal("expected 1, got", id)
}
if len(body) != 1 || body[0] != 'x' {
t.Fatalf("bad body, expected %#v, got %#v", "x", string(body))
}
if err = c.Close(); err != nil {
t.Fatal(err)
}
}
func TestTubePeekDelayed(t *testing.T) {
c := NewConn(mock("peek-delayed\r\n", "FOUND 1 1\r\nx\r\n"))
id, body, err := c.PeekDelayed()
if err != nil {
t.Fatal(err)
}
if id != "1" {
t.Fatal("expected 1, got", id)
}
if len(body) != 1 || body[0] != 'x' {
t.Fatalf("bad body, expected %#v, got %#v", "x", string(body))
}
if err = c.Close(); err != nil {
t.Fatal(err)
}
}
func TestTubePeekBuried(t *testing.T) {
c := NewConn(mock("peek-buried\r\n", "FOUND 1 1\r\nx\r\n"))
id, body, err := c.PeekBuried()
if err != nil {
t.Fatal(err)
}
if id != "1" {
t.Fatal("expected 1, got", id)
}
if len(body) != 1 || body[0] != 'x' {
t.Fatalf("bad body, expected %#v, got %#v", "x", string(body))
}
if err = c.Close(); err != nil {
t.Fatal(err)
}
}
func TestTubeKick(t *testing.T) {
c := NewConn(mock("kick 2\r\n", "KICKED 1\r\n"))
n, err := c.Kick(2)
if err != nil {
t.Fatal(err)
}
if n != 1 {
t.Fatal("expected 1, got", n)
}
if err = c.Close(); err != nil {
t.Fatal(err)
}
}
func TestTubeStats(t *testing.T) {
c := NewConn(mock("stats-tube default\r\n", "OK 10\r\n---\na: ok\n\r\n"))
m, err := c.Tube.Stats()
if err != nil {
t.Fatal(err)
}
if len(m) != 1 || m["a"] != "ok" {
t.Fatalf("expected %#v, got %#v", map[string]string{"a": "ok"}, m)
}
if err = c.Close(); err != nil {
t.Fatal(err)
}
}
func TestTubePause(t *testing.T) {
c := NewConn(mock("pause-tube default 5\r\n", "PAUSED\r\n"))
err := c.Pause(5 * time.Second)
if err != nil {
t.Fatal(err)
}
if err = c.Close(); err != nil {
t.Fatal(err)
}
}