@@ -7,46 +7,61 @@ import (
77)
88
99type testDeclarer struct {
10- _QueueDeclare func () (amqp.Queue , error )
10+ _QueueDeclare func (string ) (amqp.Queue , error )
1111 _ExchangeDeclare func () error
1212 _QueueBind func () error
1313}
1414
15- func (td * testDeclarer ) QueueDeclare (name string , durable , autoDelete , exclusive , noWait bool , args amqp.Table ) (amqp.Queue , error ) {
16- return td ._QueueDeclare ()
15+ func (td * testDeclarer ) QueueDeclare (name string , durable , autoDelete ,
16+ exclusive , noWait bool , args amqp.Table ) (amqp.Queue , error ) {
17+ return td ._QueueDeclare (name )
1718}
1819
19- func (td * testDeclarer ) ExchangeDeclare (name , kind string , durable , autoDelete , internal , noWait bool , args amqp.Table ) error {
20+ func (td * testDeclarer ) ExchangeDeclare (name , kind string , durable , autoDelete ,
21+ internal , noWait bool , args amqp.Table ) error {
2022 return td ._ExchangeDeclare ()
2123}
2224
23- func (td * testDeclarer ) QueueBind (name , key , exchange string , noWait bool , args amqp.Table ) error {
25+ func (td * testDeclarer ) QueueBind (name , key , exchange string , noWait bool ,
26+ args amqp.Table ) error {
2427 return td ._QueueBind ()
2528}
2629
2730func TestDeclareQueue (t * testing.T ) {
28- var ok bool
31+ var (
32+ callOK , nameOK bool
33+ )
2934
3035 q := & Queue {
3136 Name : "Q1" ,
3237 }
3338
3439 td := & testDeclarer {
35- _QueueDeclare : func () (amqp.Queue , error ) {
36- ok = true
40+ _QueueDeclare : func (name string ) (amqp.Queue , error ) {
41+ callOK = true
42+ if name == "Q1" {
43+ nameOK = true
44+ }
3745 return amqp.Queue {Name : "Q1_REAL" }, nil
3846 },
3947 }
4048
41- DeclareQueue (q )(td )
49+ testDec := DeclareQueue (q )
50+ testDec (td )
4251
43- if ! ok {
52+ if ! callOK {
4453 t .Error ("DeclareQueue() should call declarer.QueueDeclare()" )
4554 }
4655
4756 if q .Name != "Q1_REAL" {
4857 t .Error ("DeclareQueue() should update queue name from AMQP reply" )
4958 }
59+
60+ // call it another time (like reconnect event happened)
61+ testDec (td )
62+ if ! nameOK {
63+ t .Error ("queue name should be preserved" )
64+ }
5065}
5166
5267func TestDeclareExchange (t * testing.T ) {
0 commit comments