File: channel_spec.rb

package info (click to toggle)
ruby-amq-protocol 2.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 572 kB
  • sloc: ruby: 5,975; python: 248; makefile: 4
file content (127 lines) | stat: -rw-r--r-- 3,929 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# encoding: binary

module AMQ
  module Protocol
    class Channel
      RSpec.describe Open do
        describe '.encode' do
          it 'encodes the parameters into a MethodFrame' do
            channel = 1
            out_of_band = ''
            method_frame = Open.encode(channel, out_of_band)
            expect(method_frame.payload).to eq("\x00\x14\x00\n\x00")
            expect(method_frame.channel).to eq(1)
          end
        end
      end

      RSpec.describe OpenOk do
        describe '.decode' do
          subject do
            OpenOk.decode("\x00\x00\x00\x03foo")
          end

          its(:channel_id) { should eq('foo') }
        end
      end

      RSpec.describe Flow do
        describe '.decode' do
          subject do
            Flow.decode("\x01")
          end

          its(:active) { should be_truthy }
        end

        describe '.encode' do
          it 'encodes the parameters as a MethodFrame' do
            channel = 1
            active = true
            method_frame = Flow.encode(channel, active)
            expect(method_frame.payload).to eq("\x00\x14\x00\x14\x01")
            expect(method_frame.channel).to eq(1)
          end
        end
      end

      RSpec.describe FlowOk do
        describe '.decode' do
          subject do
            FlowOk.decode("\x00")
          end

          its(:active) { should be_falsey }
        end

        describe '.encode' do
          it 'encodes the parameters as a MethodFrame' do
            channel = 1
            active = true
            method_frame = FlowOk.encode(channel, active)
            expect(method_frame.payload).to eq("\x00\x14\x00\x15\x01")
            expect(method_frame.channel).to eq(1)
          end
        end
      end

      RSpec.describe Close do
        describe '.decode' do
          context 'with code 200' do
            subject do
              Close.decode("\x00\xc8\x07KTHXBAI\x00\x05\x00\x06")
            end

            its(:reply_code) { should eq(200) }
            its(:reply_text) { should eq('KTHXBAI') }
            its(:class_id) { should eq(5) }
            its(:method_id) { should eq(6) }
          end


          context 'with code 404 and reply_text length > 127 characters' do
            subject do
              raw = "\x01\x94\x80NOT_FOUND - no binding 123456789012345678901234567890123 between exchange 'amq.topic' in vhost '/' and queue 'test' in vhost '/'\x002\x002"
              Close.decode(raw)
            end

            its(:reply_code) { should eq(404) }
            its(:reply_text) { should eq(%q{NOT_FOUND - no binding 123456789012345678901234567890123 between exchange 'amq.topic' in vhost '/' and queue 'test' in vhost '/'}) }
            its(:class_id) { should eq(50) }
            its(:method_id) { should eq(50) }
          end

          context 'with an error code' do
            it 'returns frame and lets calling code handle the issue' do
              Close.decode("\x01\x38\x08NO_ROUTE\x00\x00")
            end
          end
        end

        describe '.encode' do
          it 'encodes the parameters into a MethodFrame' do
            channel = 1
            reply_code = 540
            reply_text = 'NOT_IMPLEMENTED'
            class_id = 0
            method_id = 0
            method_frame = Close.encode(channel, reply_code, reply_text, class_id, method_id)
            expect(method_frame.payload).to eq("\x00\x14\x00(\x02\x1c\x0fNOT_IMPLEMENTED\x00\x00\x00\x00")
            expect(method_frame.channel).to eq(1)
          end
        end
      end

      RSpec.describe CloseOk do
        describe '.encode' do
          it 'encodes the parameters into a MethodFrame' do
            channel = 1
            method_frame = CloseOk.encode(channel)
            expect(method_frame.payload).to eq("\x00\x14\x00\x29")
            expect(method_frame.channel).to eq(channel)
          end
        end
      end
    end
  end
end