File: exchange_delete_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 (105 lines) | stat: -rw-r--r-- 2,665 bytes parent folder | download | duplicates (2)
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
require "spec_helper"

describe Bunny::Exchange, "#delete" do
  let(:connection) do
    c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
    c.start
    c
  end

  after :each do
    connection.close if connection.open?
  end


  context "with a name of an existing exchange" do
    it "deletes that exchange" do
      ch = connection.create_channel
      x  = ch.fanout("bunny.tests.exchanges.fanout#{rand}")

      x.delete
      # no exception as of RabbitMQ 3.2. MK.
      x.delete

      expect(ch.exchanges.size).to eq 0
    end
  end


  context "with a name of a non-existent exchange" do
    it "DOES NOT rais an exception" do
      ch = connection.create_channel

      # no exception as of RabbitMQ 3.2. MK.
      ch.exchange_delete("sdkhflsdjflskdjflsd#{rand}")
      ch.exchange_delete("sdkhflsdjflskdjflsd#{rand}")
      ch.exchange_delete("sdkhflsdjflskdjflsd#{rand}")
      ch.exchange_delete("sdkhflsdjflskdjflsd#{rand}")
    end
  end

  context "with a name of 'amq.direct'" do
    it "does not delete the exchange" do
      ch = connection.create_channel
      x  = ch.direct('amq.direct')

      expect(x.delete).to eq nil
    end
  end

  context "with a name of 'amq.fanout'" do
    it "does not delete the exchange" do
      ch = connection.create_channel
      x  = ch.fanout('amq.fanout')

      expect(x.delete).to eq nil
    end
  end

  context "with a name of 'amq.topic'" do
    it "does not delete the exchange" do
      ch = connection.create_channel
      x  = ch.topic('amq.topic')

      expect(x.delete).to eq nil
    end
  end

  context "with a name of 'amq.headers'" do
    it "does not delete the exchange" do
      ch = connection.create_channel
      x  = ch.headers('amq.headers')

      expect(x.delete).to eq nil
    end
  end

  context "with a name of 'amq.match'" do
    it "does not delete the exchange" do
      ch = connection.create_channel
      x  = ch.headers('amq.match')

      expect(x.delete).to eq nil
    end
  end


  describe "#exchange_exists?" do
    context "when a exchange exists" do
      it "returns true" do
        ch = connection.create_channel

        expect(connection.exchange_exists?("amq.fanout")).to eq true
        expect(connection.exchange_exists?("amq.direct")).to eq true
        expect(connection.exchange_exists?("amq.topic")).to eq true
        expect(connection.exchange_exists?("amq.match")).to eq true
      end
    end

    context "when a exchange DOES NOT exist" do
      it "returns false" do
        expect(connection.exchange_exists?("suf89u9a4jo3ndnakls##{Bunny::Timestamp.now.to_i}")).to eq false
      end
    end
  end
end