forked from iwanbk/gobeanstalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gobeanstalk_test.go
96 lines (85 loc) · 1.78 KB
/
gobeanstalk_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
package gobeanstalk
import (
"testing"
"time"
)
const (
testtube = "testtube"
testjob = "testjob"
)
func dial(t *testing.T) *Conn {
conn, err := Dial("localhost:11300")
if err != nil {
t.Fatal("Dial failed.err = :", err.Error())
}
return conn
}
func TestDial(t *testing.T) {
if _, err := Dial("localhost:11300"); err != nil {
t.Fatal("Dial failed.err = :", err.Error())
}
}
func TestUse(t *testing.T) {
conn := dial(t)
err := conn.Use(testtube)
if err != nil {
t.Fatal("use failed.Err = ", err.Error())
}
}
func put(t *testing.T, tubename string, jobBody string) {
conn := dial(t)
err := conn.Use(tubename)
if err != nil {
t.Fatal("use failed.Err = ", err.Error())
}
_, err = conn.Put([]byte(jobBody), 0, 2*time.Second, 30*time.Second)
if err != nil {
t.Fatal("Put failed. Err = ", err.Error())
}
}
func TestPut(t *testing.T) {
put(t, testtube, testjob)
}
func watch(t *testing.T, tubename string) *Conn {
conn := dial(t)
_, err := conn.Watch(tubename)
if err != nil {
t.Fatal(err)
}
return conn
}
func TestWatch(t *testing.T) {
watch(t, testtube)
}
func reserve(t *testing.T, tubename string) (*Conn, *Job) {
conn := watch(t, tubename)
j, err := conn.Reserve()
if err != nil {
t.Fatal(err)
}
if string(j.Body) != testjob {
t.Fatal("job body check failed")
}
return conn, j
}
func TestReserve(t *testing.T) {
reserve(t, testtube)
}
func statsJob(t *testing.T, tubename string) {
conn, j := reserve(t, testtube)
yaml, err := conn.StatsJob(j.ID)
if err != nil {
t.Fatal("StatsJob failed.Err = ", err.Error())
}
t.Log(string(yaml))
}
func TestStatsJob(t *testing.T) {
statsJob(t, testtube)
}
func TestDelete(t *testing.T) {
conn, j := reserve(t, testtube)
err := conn.Delete(j.ID)
if err != nil {
t.Error("delete failed. Err = ", err.Error())
}
}