-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathironmq_test.go
62 lines (54 loc) · 1.26 KB
/
ironmq_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
package ironmq
import (
"os"
"testing"
)
func TestFunctionality(t *testing.T) {
projectId := os.Getenv("IRONIO_PROJECT_ID")
if projectId == "" {
t.Fatalf("IRONIO_PROJECT_ID environment variable not set")
}
token := os.Getenv("IRONIO_TOKEN")
if token == "" {
t.Fatalf("IRONIO_TOKEN environment variable not set")
}
client := NewClient(projectId, token, IronAWSUSEast)
queue := client.Queue("test-queue")
// clear out the queue
var err error
for err == nil {
_, err = queue.Get()
}
if err != EmptyQueue {
t.Fatalf("queue.Get: expected empty queue error, got: %s", err)
}
const body = "Hello, IronMQ!"
id, err := queue.Push(body)
if err != nil {
t.Fatalf("queue.Push: error isn't nil: %s", err)
}
if len(id) == 0 {
t.Fatal("queue.Push: no ID returned")
}
qi, err := queue.Info()
if err != nil {
t.Fatalf("queue.Info: error isn't nil: %s", err)
}
if qi.Size != 1 {
t.Errorf("queue.Info: size isn't 1: %v", qi.Size)
}
msg, err := queue.Get()
if err != nil {
t.Fatalf("queue.Get: error isn't nil: %s", err)
}
if msg == nil {
t.Fatal("queue.Get: msg is nil")
}
if msg.Body != body {
t.Fatalf("queue.Get: msg has wrong contents: %+v", msg)
}
err = msg.Delete()
if err != nil {
t.Fatalf("msg.Delete: error isn't nil: %s", err)
}
}