-
Notifications
You must be signed in to change notification settings - Fork 46
/
declaration_test.go
107 lines (84 loc) · 1.92 KB
/
declaration_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
package cony
import (
"testing"
"github.com/streadway/amqp"
)
type testDeclarer struct {
_QueueDeclare func(string) (amqp.Queue, error)
_ExchangeDeclare func() error
_QueueBind func() error
}
func (td *testDeclarer) QueueDeclare(name string, durable, autoDelete,
exclusive, noWait bool, args amqp.Table) (amqp.Queue, error) {
return td._QueueDeclare(name)
}
func (td *testDeclarer) ExchangeDeclare(name, kind string, durable, autoDelete,
internal, noWait bool, args amqp.Table) error {
return td._ExchangeDeclare()
}
func (td *testDeclarer) QueueBind(name, key, exchange string, noWait bool,
args amqp.Table) error {
return td._QueueBind()
}
func TestDeclareQueue(t *testing.T) {
var (
callOK, nameOK bool
)
q := &Queue{
Name: "Q1",
}
td := &testDeclarer{
_QueueDeclare: func(name string) (amqp.Queue, error) {
callOK = true
if name == "Q1" {
nameOK = true
}
return amqp.Queue{Name: "Q1_REAL"}, nil
},
}
testDec := DeclareQueue(q)
testDec(td)
if !callOK {
t.Error("DeclareQueue() should call declarer.QueueDeclare()")
}
if q.Name != "Q1_REAL" {
t.Error("DeclareQueue() should update queue name from AMQP reply")
}
// call it another time (like reconnect event happened)
testDec(td)
if !nameOK {
t.Error("queue name should be preserved")
}
}
func TestDeclareExchange(t *testing.T) {
var ok bool
e := Exchange{Name: "ex1"}
td := &testDeclarer{
_ExchangeDeclare: func() error {
ok = true
return nil
},
}
DeclareExchange(e)(td)
if !ok {
t.Error("DeclareExchange() should call declarer.ExchangeDeclare()")
}
}
func TestDeclareBinding(t *testing.T) {
var ok bool
b := Binding{
Queue: &Queue{Name: "lol1"},
Exchange: Exchange{Name: "lol2"},
Key: "ololoev",
}
td := &testDeclarer{
_QueueBind: func() error {
ok = true
return nil
},
}
DeclareBinding(b)(td)
if !ok {
t.Error("DeclareBinding() should call declarer.QueueBind()")
}
}