File: queue_bind_spec.rb

package info (click to toggle)
ruby-bunny 2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: ruby: 10,256; sh: 70; makefile: 8
file content (109 lines) | stat: -rw-r--r-- 2,495 bytes parent folder | download | duplicates (5)
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
require "spec_helper"

describe "A client-named", Bunny::Queue do
  let(:connection) do
    c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
    c.start
    c
  end

  it "can be bound to a pre-declared exchange" do
    ch = connection.create_channel
    q  = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
    expect(q).not_to be_server_named

    expect(q.bind("amq.fanout")).to eq q

    ch.close
  end

  it "can be unbound from a pre-declared exchange" do
    ch = connection.create_channel
    q  = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
    expect(q).not_to be_server_named

    q.bind("amq.fanout")
    expect(q.unbind("amq.fanout")).to eq q

    ch.close
  end

  it "can be bound to a custom exchange" do
    ch = connection.create_channel
    q  = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)

    x  = ch.fanout("bunny.tests.exchanges.fanout#{rand}")
    expect(q.bind(x)).to eq q

    x.delete
    ch.close
  end

  it "can be unbound from a custom exchange" do
    ch = connection.create_channel
    q  = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
    expect(q).not_to be_server_named

    x  = ch.fanout("bunny.tests.fanout", auto_delete: true, durable: false)

    q.bind(x)
    expect(q.unbind(x)).to eq q

    ch.close
  end
end



describe "A server-named", Bunny::Queue do
  let(:connection) do
    c = Bunny.new
    c.start
    c
  end

  it "can be bound to a pre-declared exchange" do
    ch = connection.create_channel
    q  = ch.queue("", exclusive: true)
    expect(q).to be_server_named

    expect(q.bind("amq.fanout")).to eq q

    ch.close
  end

  it "can be unbound from a pre-declared exchange" do
    ch = connection.create_channel
    q  = ch.queue("", exclusive: true)
    expect(q).to be_server_named

    q.bind("amq.fanout")
    expect(q.unbind("amq.fanout")).to eq q

    ch.close
  end

  it "can be bound to a custom exchange" do
    ch = connection.create_channel
    q  = ch.queue("", exclusive: true)

    x  = ch.fanout("bunny.tests.exchanges.fanout#{rand}")
    expect(q.bind(x)).to eq q

    x.delete
    ch.close
  end

  it "can be bound from a custom exchange" do
    ch   = connection.create_channel
    q    = ch.queue("", exclusive: true)

    name = "bunny.tests.exchanges.fanout#{rand}"
    x    = ch.fanout(name)
    q.bind(x)
    expect(q.unbind(name)).to eq q

    x.delete
    ch.close
  end
end