rabbitmq_http_api_client 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b469accc29e88cb31b6a758bd41b8e5a4b23cdf
4
- data.tar.gz: 0e937bf63faeb30172bee3008fe5ca3b7f05a776
3
+ metadata.gz: f70ef3ff3ec25ec720de49aeacc8b8f6761deaa5
4
+ data.tar.gz: 540c588e21de5cd1a791cd88c263488c12a145c2
5
5
  SHA512:
6
- metadata.gz: 9049c26798c6aa7484216425676782e97f212ccb8ee2002867e0726aabe1b7f3c4ae0d14b737194b94b38263100376406f2107e68fa659a05f743b07205d1df0
7
- data.tar.gz: d7aae20c64bbb343abe1beeb43e75840cac74318238fb3905ea9a624ee16b6bebdf46d7de772fcc2056d0dd509bdddc5c48fc86813955d5469942e961e657514
6
+ metadata.gz: 8e03485b55f0171a8e8af165f81d5ec6832d6b9e9f35875b649ba14965f21fea7b8e7e223c974923122b0566ae52c5817ac7d31ccfb1df1c389ac279cc78e625
7
+ data.tar.gz: df3022102e969d7e47460f63afa847ed2b57e4309dac55116b59731744c8c768d14ee4eed539b026d6a880c40feb08cff1fcb305482d2ab3ccc0a43efd3fc61a
data/.gitignore CHANGED
@@ -15,4 +15,8 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- bin/*
18
+ bin/autospec
19
+ bin/bundler
20
+ bin/rspec
21
+ bin/ldiff
22
+ bin/htmldiff
data/.rspec CHANGED
@@ -1,2 +1 @@
1
- --color
2
- --format documentation
1
+ -cfd
data/.travis.yml CHANGED
@@ -1,13 +1,9 @@
1
1
  bundler_args: --without development
2
- script: "bundle exec rspec --color --format documentation spec"
2
+ before_script: ./bin/before_build.sh
3
+ script: "bundle exec rspec"
3
4
  rvm:
4
- - "2.1"
5
- - "2.0"
6
- - "1.9.3"
7
- - "jruby-19mode"
8
- - "1.9.2"
9
- - "rbx-19mode"
10
- - "1.8.7"
5
+ - "2.3.3"
6
+ - "2.2"
11
7
  notifications:
12
8
  email: michael@rabbitmq.com
13
9
  services:
@@ -15,7 +11,3 @@ services:
15
11
  branches:
16
12
  only:
17
13
  - master
18
- matrix:
19
- allow_failures:
20
- - rvm: rbx-19mode
21
- - rvm: 1.8.7
data/ChangeLog.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## Changes Between 1.6.0 and 1.7.0
2
+
3
+ ### Blank Tags by Default
4
+
5
+ The `:tags` attribute is no longer required by `Client#update_user`. If not provided,
6
+ a blank list of tags will be used.
7
+
8
+
1
9
  ## Changes Between 1.5.0 and 1.6.0
2
10
 
3
11
  ### Definition Upload Support
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  group :development, :test do
4
4
  gem "rspec", ">= 3.2.0"
5
5
  gem "json", :platform => :ruby_18
6
- gem "bunny", ">= 1.7.0"
6
+ gem "bunny", ">= 2.5.1"
7
7
 
8
8
  gem "rantly"
9
9
  end
data/README.md CHANGED
@@ -33,7 +33,7 @@ All versions require [RabbitMQ Management UI plugin](http://www.rabbitmq.com/man
33
33
 
34
34
  Add this line to your application's Gemfile:
35
35
 
36
- gem 'rabbitmq_http_api_client', '>= 1.5.0'
36
+ gem 'rabbitmq_http_api_client', '>= 1.6.0'
37
37
 
38
38
  And then execute:
39
39
 
@@ -219,6 +219,9 @@ puts q.backing_queue_status
219
219
  puts q.active_consumers
220
220
 
221
221
 
222
+ # Get information about a queue
223
+ client.queue_info("/", "collector1.megacorp.local")
224
+
222
225
  # Declare a queue
223
226
  client.declare_queue("/", "collector1.megacorp.local", :durable => false, :auto_delete => true)
224
227
 
@@ -342,21 +345,27 @@ ps = client.update_permissions_of("/", "guest", :write => ".*", :read => ".*", :
342
345
  ps = client.clear_permissions_of("/", "guest")
343
346
  ```
344
347
 
348
+ ## Running Tests
349
+
350
+ bundle install
351
+ bundle exec rspec -cfd spec
352
+
353
+ The test suite assumes that RabbitMQ is running locally with stock settings
354
+ and rabbitmq-management plugin enabled.
355
+
356
+
345
357
  ## Contributing
346
358
 
347
359
  1. Fork it
348
360
  2. Create your feature branch (`git checkout -b my-new-feature`)
349
361
  3. Commit your changes (`git commit -am 'Add some feature'`)
350
362
  4. Push to the branch (`git push origin my-new-feature`)
351
- 5. Create new Pull Request
363
+ 5. Create a new pull request
352
364
 
353
365
 
354
366
  ## License & Copyright
355
367
 
356
368
  Double-licensed under the MIT and Mozilla Public License (same as RabbitMQ).
357
369
 
358
- (c) Michael S. Klishin, 2012-2014.
359
-
360
-
361
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ruby-amqp/rabbitmq_http_api_client/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
370
+ (c) Michael S. Klishin, 2012-2016.
362
371
 
@@ -0,0 +1,13 @@
1
+ #!/bin/sh
2
+
3
+ ${RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL:="sudo rabbitmqctl"}
4
+
5
+ # guest:guest has full access to /
6
+
7
+ $RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL add_vhost /
8
+ $RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL add_user guest guest
9
+ $RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL set_permissions -p / guest ".*" ".*" ".*"
10
+
11
+ # Reduce retention policy for faster publishing of stats
12
+ $RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL eval 'supervisor2:terminate_child(rabbit_mgmt_sup_sup, rabbit_mgmt_sup), application:set_env(rabbitmq_management, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_sup_sup:start_child().'
13
+ $RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL eval 'supervisor2:terminate_child(rabbit_mgmt_agent_sup_sup, rabbit_mgmt_agent_sup), application:set_env(rabbitmq_management_agent, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_agent_sup_sup:start_child().'
@@ -129,8 +129,11 @@ module RabbitMQ
129
129
  decode_resource(response)
130
130
  end
131
131
 
132
- def delete_exchange(vhost, name)
133
- decode_resource(@connection.delete("exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}"))
132
+ def delete_exchange(vhost, name, if_unused = false)
133
+ response = @connection.delete("exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req|
134
+ req.params["if-unused"] = true if if_unused
135
+ end
136
+ decode_resource(response)
134
137
  end
135
138
 
136
139
  def exchange_info(vhost, name)
@@ -219,6 +222,27 @@ module RabbitMQ
219
222
  resp.success?
220
223
  end
221
224
 
225
+ def list_bindings_between_exchanges(vhost, destination_exchange, source_exchange)
226
+ decode_resource_collection(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}"))
227
+ end
228
+
229
+ def exchange_binding_info(vhost, destination_exchange, source_exchange, properties_key)
230
+ decode_resource(@connection.get("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}/#{uri_encode(properties_key)}"))
231
+ end
232
+
233
+
234
+ def bind_exchange(vhost, destination_exchange, source_exchange, routing_key, arguments = [])
235
+ resp = @connection.post("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}") do |req|
236
+ req.headers['Content-Type'] = 'application/json'
237
+ req.body = MultiJson.dump({:routing_key => routing_key, :arguments => arguments})
238
+ end
239
+ resp.headers['location']
240
+ end
241
+
242
+ def delete_exchange_binding(vhost, destination_exchange, source_exchange, properties_key)
243
+ resp = @connection.delete("bindings/#{uri_encode(vhost)}/e/#{uri_encode(source_exchange)}/e/#{uri_encode(destination_exchange)}/#{uri_encode(properties_key)}")
244
+ resp.success?
245
+ end
222
246
 
223
247
 
224
248
  def list_vhosts
@@ -279,6 +303,8 @@ module RabbitMQ
279
303
  end
280
304
 
281
305
  def update_user(name, attributes)
306
+ attributes[:tags] ||= ""
307
+
282
308
  response = @connection.put("users/#{uri_encode(name)}") do |req|
283
309
  req.headers['Content-Type'] = "application/json"
284
310
  req.body = MultiJson.dump(attributes)
@@ -1,7 +1,7 @@
1
1
  module RabbitMQ
2
2
  module HTTP
3
3
  class Client
4
- VERSION = "1.6.0"
4
+ VERSION = "1.7.0"
5
5
  end
6
6
  end
7
7
  end
@@ -8,13 +8,25 @@ describe RabbitMQ::HTTP::Client do
8
8
  described_class.connect(endpoint, :username => "guest", :password => "guest")
9
9
  end
10
10
 
11
- before :all do
12
- @connection = Bunny.new
13
- @connection.start
11
+ before :each do
12
+ @conn = Bunny.new
13
+ @conn.start
14
14
  end
15
15
 
16
- after :all do
17
- @connection.close
16
+ after :each do
17
+ @conn.close
18
+ end
19
+
20
+ #
21
+ # Helpers
22
+ #
23
+
24
+ # Statistics tables in the server are updated asynchronously,
25
+ # in particular starting with rabbitmq/rabbitmq-management#236,
26
+ # so in some cases we need to wait before GET'ing e.g. a newly opened connection.
27
+ def await_event_propagation
28
+ # same number as used in rabbit-hole test suite. Works OK.
29
+ sleep 1
18
30
  end
19
31
 
20
32
  #
@@ -139,12 +151,14 @@ describe RabbitMQ::HTTP::Client do
139
151
  end
140
152
 
141
153
  describe "POST /api/definitions" do
154
+ let(:queue_name) { 'my-definition-queue' }
155
+
142
156
  let(:definition) do
143
157
  {
144
158
  :queues => [{
145
- :name => 'my-definition-queue',
159
+ :name => queue_name,
146
160
  :vhost => '/',
147
- :durable => true,
161
+ durable: true,
148
162
  :auto_delete => false,
149
163
  :arguments => {
150
164
  "x-dead-letter-exchange" => 'dead'
@@ -156,13 +170,17 @@ describe RabbitMQ::HTTP::Client do
156
170
  it "returns true when successful" do
157
171
  r = subject.upload_definitions(definition)
158
172
  expect(r).to eq(true)
173
+
174
+ subject.delete_queue("/", queue_name)
159
175
  end
160
176
 
161
177
  it "stores the uploaded definitions" do
162
178
  subject.upload_definitions(definition)
163
179
  xs = subject.list_definitions
164
- uploaded_queue = xs.queues.detect { |q| q.name = 'my-definition-queue' }
180
+ uploaded_queue = xs.queues.detect { |q| q.name == queue_name }
165
181
  expect(uploaded_queue).not_to eq(nil)
182
+
183
+ subject.delete_queue("/", queue_name)
166
184
  end
167
185
  end
168
186
 
@@ -171,12 +189,13 @@ describe RabbitMQ::HTTP::Client do
171
189
  #
172
190
 
173
191
  describe "GET /api/connections" do
174
- before :all do
175
- @connection = Bunny.new
176
- @connection.start
192
+ before :each do
193
+ @conn = Bunny.new
194
+ @conn.start
177
195
  end
178
196
 
179
197
  it "returns a list of all active connections" do
198
+ await_event_propagation
180
199
  xs = subject.list_connections
181
200
  f = xs.first
182
201
 
@@ -187,6 +206,7 @@ describe RabbitMQ::HTTP::Client do
187
206
 
188
207
  describe "GET /api/connections/:name" do
189
208
  it "returns information about the connection" do
209
+ await_event_propagation
190
210
  xs = subject.list_connections
191
211
  c = subject.connection_info(xs.first.name)
192
212
 
@@ -195,51 +215,41 @@ describe RabbitMQ::HTTP::Client do
195
215
  end
196
216
  end
197
217
 
198
- unless ENV["CI"]
199
- describe "DELETE /api/connections/:name" do
200
- it "closes the connection" do
201
- pending "Needs investigation, DELETE does not seem to close the connection"
202
- xs = subject.list_connections
203
- c = subject.close_connection(xs.first.name)
204
-
205
- expect(c.name).to match(/127.0.0.1/)
206
- expect(c.client_properties.product).to eq("Bunny")
207
-
208
- expect(@connection).to_not be_open
209
- end
210
- end
211
- end
212
-
213
218
 
214
219
  #
215
220
  # Channels
216
221
  #
217
222
 
218
223
  describe "GET /api/channels" do
219
- before :all do
220
- @channel = @connection.create_channel
221
- end
222
-
223
224
  it "returns a list of all active channels" do
224
- xs = subject.list_channels
225
- f = xs.first
225
+ conn = Bunny.new; conn.start
226
+ ch = conn.create_channel
227
+ await_event_propagation
228
+ xs = subject.list_channels
229
+ f = xs.first
226
230
 
227
231
  expect(f.number).to be >= 1
228
232
  expect(f.prefetch_count).to be >= 0
233
+
234
+ ch.close
235
+ conn.close
229
236
  end
230
237
  end
231
238
 
232
239
  describe "GET /api/channels/:name" do
233
- before :all do
234
- @channel = @connection.create_channel
235
- end
236
-
237
240
  it "returns information about the channel" do
238
- xs = subject.list_channels
239
- c = subject.channel_info(xs.first.name)
241
+ conn = Bunny.new; conn.start
242
+ ch = conn.create_channel
243
+
244
+ await_event_propagation
245
+ xs = subject.list_channels
246
+ c = subject.channel_info(xs.first.name)
240
247
 
241
248
  expect(c.number).to be >= 1
242
249
  expect(c.prefetch_count).to be >= 0
250
+
251
+ ch.close
252
+ conn.close
243
253
  end
244
254
  end
245
255
 
@@ -281,54 +291,63 @@ describe RabbitMQ::HTTP::Client do
281
291
  end
282
292
 
283
293
  describe "PUT /api/exchanges/:vhost/:name" do
284
- before :all do
285
- @channel = @connection.create_channel
294
+ before :each do
295
+ @channel = @conn.create_channel
286
296
  end
287
297
 
288
- after :all do
298
+ after :each do
289
299
  @channel.close
290
300
  end
291
301
 
292
302
  let(:exchange_name) { "httpdeclared" }
293
303
 
294
304
  it "declares an exchange" do
295
- subject.declare_exchange("/", exchange_name, :durable => false, :type => "fanout")
305
+ subject.declare_exchange("/", exchange_name, durable: false, type: "fanout")
296
306
 
297
- x = @channel.fanout(exchange_name, :durable => false, :auto_delete => false)
307
+ x = @channel.fanout(exchange_name, durable: false, auto_delete: false)
298
308
  x.delete
299
309
  end
300
310
  end
301
311
 
302
312
  describe "DELETE /api/exchanges/:vhost/:name" do
303
- before :all do
304
- @channel = @connection.create_channel
313
+ before :each do
314
+ @channel = @conn.create_channel
305
315
  end
306
316
 
307
- after :all do
317
+ after :each do
308
318
  @channel.close
309
319
  end
310
320
 
311
321
  let(:exchange_name) { "httpdeclared" }
312
322
 
313
323
  it "deletes an exchange" do
314
- x = @channel.fanout(exchange_name, :durable => false)
324
+ x = @channel.fanout(exchange_name, durable: false)
315
325
  subject.delete_exchange("/", exchange_name)
316
326
  end
327
+
328
+ # HTTP client tries to uncompress an empty response :( MK
329
+ it "doesn't delete used exchange" do
330
+ q = @channel.queue("")
331
+ e = @channel.fanout(exchange_name, durable: false)
332
+ q.bind(e)
333
+ expect do
334
+ subject.delete_exchange("/", exchange_name, true)
335
+ end.to raise_error(Faraday::ClientError)
336
+ end
317
337
  end
318
338
 
319
339
 
320
340
  describe "GET /api/exchanges/:vhost/:name/bindings/source" do
321
- before :all do
322
- @channel = @connection.create_channel
341
+ before :each do
342
+ @channel = @conn.create_channel
323
343
  end
324
-
325
- after :all do
344
+ after :each do
326
345
  @channel.close
327
346
  end
328
347
 
329
348
  it "returns a list of all bindings in which the given exchange is the source" do
330
- e = @channel.fanout("http.api.tests.fanout", :durable => true)
331
- q = @channel.queue("http.api.tests.queue1", :durable => true)
349
+ e = @channel.fanout("http.api.tests.fanout", durable: true)
350
+ q = @channel.queue("http.api.tests.queue1", durable: true)
332
351
  q.bind(e)
333
352
 
334
353
  xs = subject.list_bindings_by_source("/", "http.api.tests.fanout")
@@ -347,13 +366,16 @@ describe RabbitMQ::HTTP::Client do
347
366
 
348
367
 
349
368
  describe "GET /api/exchanges/:vhost/:name/bindings/destination" do
350
- before :all do
351
- @channel = @connection.create_channel
369
+ before :each do
370
+ @channel = @conn.create_channel
371
+ end
372
+ after :each do
373
+ @channel.close
352
374
  end
353
375
 
354
- it "returns a list of all bindings in which the given exchange is the source" do
355
- e1 = @channel.fanout("http.api.tests.fanout1", :durable => true)
356
- e2 = @channel.fanout("http.api.tests.fanout2", :durable => true)
376
+ it "returns a list of all bindings in which the given exchange is the destination" do
377
+ e1 = @channel.fanout("http.api.tests.fanout1", durable: true)
378
+ e2 = @channel.fanout("http.api.tests.fanout2", durable: true)
357
379
  e1.bind(e2)
358
380
 
359
381
  xs = subject.list_bindings_by_destination("/", "http.api.tests.fanout1")
@@ -382,39 +404,53 @@ describe RabbitMQ::HTTP::Client do
382
404
  #
383
405
 
384
406
  describe "GET /api/queues" do
385
- before :all do
386
- @channel = @connection.create_channel
407
+ before :each do
408
+ @channel = @conn.create_channel
409
+ end
410
+ after :each do
411
+ @channel.close
387
412
  end
388
413
 
389
414
  it "returns a list of all queues" do
390
- q = @channel.queue("", :exclusive => true)
415
+ q = @channel.queue("", durable: false)
391
416
 
392
417
  xs = subject.list_queues
393
418
  expect(xs.detect { |x| x.name == q.name }).to_not be_empty
419
+
420
+ subject.delete_queue("/", q.name)
394
421
  end
395
422
  end
396
423
 
397
424
  describe "GET /api/queues/:vhost" do
398
- before :all do
399
- @channel = @connection.create_channel
425
+ before :each do
426
+ @channel = @conn.create_channel
427
+ end
428
+ after :each do
429
+ @channel.close
400
430
  end
401
431
 
402
432
  it "returns a list of all queues" do
403
- q = @channel.queue("", :exclusive => true)
433
+ q = @channel.queue("", durable: false)
404
434
 
405
435
  xs = subject.list_queues("/")
406
436
  expect(xs.detect { |x| x.name == q.name }).to_not be_empty
437
+
438
+ subject.delete_queue("/", q.name)
407
439
  end
408
440
  end
409
441
 
410
442
  describe "GET /api/queues/:vhost/:name" do
411
443
  context "when queue exists" do
412
- before :all do
413
- @channel = @connection.create_channel
444
+ before :each do
445
+ @channel = @conn.create_channel
446
+ end
447
+ after :each do
448
+ @channel.close
414
449
  end
415
450
 
416
451
  it "returns information about a queue" do
417
- q = @channel.queue("", :exclusive => true, :durable => false)
452
+ q = @channel.queue("", durable: false)
453
+ await_event_propagation
418
454
  i = subject.queue_info("/", q.name)
419
455
 
420
456
  expect(i.durable).to eq(false)
@@ -424,6 +460,8 @@ describe RabbitMQ::HTTP::Client do
424
460
  expect(i.auto_delete).to eq(q.auto_delete?)
425
461
  expect(i.active_consumers).to be_nil
426
462
  expect(i.backing_queue_status.avg_ack_egress_rate).to eq(0.0)
463
+
464
+ subject.delete_queue("/", q.name)
427
465
  end
428
466
  end
429
467
 
@@ -437,36 +475,36 @@ describe RabbitMQ::HTTP::Client do
437
475
  end
438
476
 
439
477
  describe "PUT /api/queues/:vhost/:name" do
440
- before :all do
441
- @channel = @connection.create_channel
478
+ before :each do
479
+ @channel = @conn.create_channel
442
480
  end
443
481
 
444
482
  let(:queue_name) { "httpdeclared" }
445
483
 
446
484
  it "declares a queue" do
447
- subject.declare_queue("/", queue_name, :durable => false, :auto_delete => true)
485
+ subject.declare_queue("/", queue_name, durable: false, auto_delete: true)
448
486
 
449
- q = @channel.queue(queue_name, :durable => false, :auto_delete => true)
487
+ q = @channel.queue(queue_name, durable: false, auto_delete: true)
450
488
  q.delete
451
489
  end
452
490
  end
453
491
 
454
492
  describe "DELETE /api/queues/:vhost/:name" do
455
- before :all do
456
- @channel = @connection.create_channel
493
+ before :each do
494
+ @channel = @conn.create_channel
457
495
  end
458
496
 
459
497
  let(:queue_name) { "httpdeclared" }
460
498
 
461
499
  it "deletes a queue" do
462
- q = @channel.queue(queue_name, :durable => false)
500
+ q = @channel.queue(queue_name, durable: false)
463
501
  subject.delete_queue("/", queue_name)
464
502
  end
465
503
  end
466
504
 
467
505
  describe "GET /api/queues/:vhost/:name/bindings" do
468
- before :all do
469
- @channel = @connection.create_channel
506
+ before :each do
507
+ @channel = @conn.create_channel
470
508
  end
471
509
 
472
510
  it "returns a list of bindings for a queue" do
@@ -478,17 +516,22 @@ describe RabbitMQ::HTTP::Client do
478
516
 
479
517
  expect(x.destination).to eq(q.name)
480
518
  expect(x.destination_type).to eq("queue")
519
+
520
+ q.delete
481
521
  end
482
522
  end
483
523
 
484
524
  describe "DELETE /api/queues/:vhost/:name/contents" do
485
- before :all do
486
- @channel = @connection.create_channel
525
+ before :each do
526
+ @channel = @conn.create_channel
527
+ end
528
+ after :each do
529
+ @channel.close
487
530
  end
488
531
 
489
532
  it "purges a queue" do
490
533
  q = @channel.queue("")
491
- x = @channel.fanout("amq.fanout", :durable => true, :auto_delete => false)
534
+ x = @channel.fanout("amq.fanout", durable: true, auto_delete: false)
492
535
  q.bind(x)
493
536
 
494
537
  10.times do
@@ -506,13 +549,16 @@ describe RabbitMQ::HTTP::Client do
506
549
 
507
550
  # yes, POST, because it potentially modifies the state (ordering) of the queue
508
551
  describe "POST /api/queues/:vhost/:name/get" do
509
- before :all do
510
- @channel = @connection.create_channel
552
+ before :each do
553
+ @channel = @conn.create_channel
554
+ end
555
+ after :each do
556
+ @channel.close
511
557
  end
512
558
 
513
559
  it "fetches a message from a queue, a la basic.get" do
514
560
  q = @channel.queue("")
515
- x = @channel.fanout("amq.fanout", :durable => true, :auto_delete => false)
561
+ x = @channel.fanout("amq.fanout", durable: true, auto_delete: false)
516
562
  q.bind(x)
517
563
 
518
564
  10.times do |i|
@@ -521,7 +567,10 @@ describe RabbitMQ::HTTP::Client do
521
567
  sleep 0.7
522
568
 
523
569
  expect(q.message_count).to eq(10)
524
- xs = subject.get_messages("/", q.name, :count => 10, :requeue => false, :encoding => "auto")
570
+ # the requeueing arguments differ between RabbitMQ 3.7.0 and earlier versions,
571
+ # so pass both
572
+ xs = subject.get_messages("/", q.name, count: 10,
573
+ requeue: false, ackmode: "ack_requeue_false", encoding: "auto")
525
574
  m = xs.first
526
575
 
527
576
  expect(m.properties.content_type).to eq("application/xyz")
@@ -533,7 +582,18 @@ describe RabbitMQ::HTTP::Client do
533
582
  end
534
583
 
535
584
  describe "GET /api/bindings" do
585
+ before :each do
586
+ @channel = @conn.create_channel
587
+ end
588
+ after :each do
589
+ @channel.close
590
+ end
591
+
536
592
  it "returns a list of all bindings" do
593
+ q = @channel.queue("")
594
+ x = @channel.fanout("amq.fanout", durable: true, auto_delete: false)
595
+ q.bind(x)
596
+ await_event_propagation
537
597
  xs = subject.list_bindings
538
598
  b = xs.first
539
599
 
@@ -542,11 +602,24 @@ describe RabbitMQ::HTTP::Client do
542
602
  expect(b.source).to_not be_nil
543
603
  expect(b.routing_key).to_not be_nil
544
604
  expect(b.vhost).to_not be_nil
605
+
606
+ q.delete
545
607
  end
546
608
  end
547
609
 
548
610
  describe "GET /api/bindings/:vhost" do
611
+ before :each do
612
+ @channel = @conn.create_channel
613
+ end
614
+ after :each do
615
+ @channel.close
616
+ end
617
+
549
618
  it "returns a list of all bindings in a vhost" do
619
+ q = @channel.queue("")
620
+ x = @channel.fanout("amq.fanout", durable: true, auto_delete: false)
621
+ q.bind(x)
622
+ await_event_propagation
550
623
  xs = subject.list_bindings("/")
551
624
  b = xs.first
552
625
 
@@ -555,12 +628,17 @@ describe RabbitMQ::HTTP::Client do
555
628
  expect(b.source).to_not be_nil
556
629
  expect(b.routing_key).to_not be_nil
557
630
  expect(b.vhost).to_not be_nil
631
+
632
+ q.delete
558
633
  end
559
634
  end
560
635
 
561
636
  describe "GET /api/bindings/:vhost/e/:exchange/q/:queue" do
562
- before :all do
563
- @channel = @connection.create_channel
637
+ before :each do
638
+ @channel = @conn.create_channel
639
+ end
640
+ after :each do
641
+ @channel.close
564
642
  end
565
643
 
566
644
  it "returns a list of all bindings between an exchange and a queue" do
@@ -568,6 +646,8 @@ describe RabbitMQ::HTTP::Client do
568
646
  x = @channel.fanout("http.client.fanout")
569
647
  q.bind(x)
570
648
 
649
+ await_event_propagation
650
+
571
651
  xs = subject.list_bindings_between_queue_and_exchange("/", q.name, x.name)
572
652
  b = xs.first
573
653
  expect(b.destination).to eq(q.name)
@@ -583,8 +663,11 @@ describe RabbitMQ::HTTP::Client do
583
663
  end
584
664
 
585
665
  describe "POST /api/bindings/:vhost/e/:exchange/q/:queue" do
586
- before :all do
587
- @channel = @connection.create_channel
666
+ before :each do
667
+ @channel = @conn.create_channel
668
+ end
669
+ after :each do
670
+ @channel.close
588
671
  end
589
672
 
590
673
  it "creates a binding between an exchange and a queue" do
@@ -603,8 +686,11 @@ describe RabbitMQ::HTTP::Client do
603
686
  end
604
687
 
605
688
  describe "GET /api/bindings/:vhost/e/:exchange/q/:queue/props" do
606
- before :all do
607
- @channel = @connection.create_channel
689
+ before :each do
690
+ @channel = @conn.create_channel
691
+ end
692
+ after :each do
693
+ @channel.close
608
694
  end
609
695
 
610
696
  it "returns an individual binding between an exchange and a queue" do
@@ -619,13 +705,16 @@ describe RabbitMQ::HTTP::Client do
619
705
  b2 = subject.queue_binding_info("/", q.name, x.name, b1.properties_key)
620
706
 
621
707
  expect(b1).to eq(b2)
622
-
708
+ q.delete
623
709
  end
624
710
  end
625
711
 
626
712
  describe "DELETE /api/bindings/:vhost/e/:exchange/q/:queue/props" do
627
- before :all do
628
- @channel = @connection.create_channel
713
+ before :each do
714
+ @channel = @conn.create_channel
715
+ end
716
+ after :each do
717
+ @channel.close
629
718
  end
630
719
 
631
720
  it "deletes an individual binding between an exchange and a queue" do
@@ -648,6 +737,85 @@ describe RabbitMQ::HTTP::Client do
648
737
  end
649
738
  end
650
739
 
740
+ describe "POST /api/bindings/:vhost/e/:source_exchange/e/:destination_exchange" do
741
+ before :each do
742
+ @channel = @conn.create_channel
743
+ end
744
+ after :each do
745
+ @channel.close
746
+ end
747
+
748
+ it "creates a binding between two exchanges" do
749
+ routing_key = 'test.key'
750
+ sx = @channel.fanout("http.client.fanout_source")
751
+ dx = @channel.fanout("http.client.fanout_destination")
752
+
753
+ xs = subject.list_bindings_between_exchanges("/", dx.name, sx.name)
754
+ expect(xs).to be_empty
755
+
756
+ dx.bind(sx)
757
+
758
+ b = subject.bind_exchange("/", dx.name, sx.name, routing_key)
759
+ xs = subject.list_bindings_between_exchanges("/", dx.name, sx.name)
760
+ expect(xs).to_not be_empty
761
+
762
+ dx.delete
763
+ sx.delete
764
+ end
765
+ end
766
+
767
+ describe "GET /api/bindings/:vhost/e/:exchange/q/:queue/props" do
768
+ before :each do
769
+ @channel = @conn.create_channel
770
+ end
771
+ after :each do
772
+ @channel.close
773
+ end
774
+
775
+ it "returns an individual binding between two exchanges" do
776
+ routing_key = 'test.key'
777
+ sx = @channel.fanout("http.client.fanout_source")
778
+ dx = @channel.fanout("http.client.fanout_destination")
779
+ dx.bind(sx)
780
+
781
+ xs = subject.list_bindings_between_exchanges("/", dx.name, sx.name)
782
+ b1 = xs.first
783
+
784
+ b2 = subject.exchange_binding_info("/", dx.name, sx.name, b1.properties_key)
785
+
786
+ expect(b1).to eq(b2)
787
+
788
+ end
789
+ end
790
+
791
+ describe "DELETE /api/bindings/:vhost/e/:exchange/q/:queue/props" do
792
+ before :each do
793
+ @channel = @conn.create_channel
794
+ end
795
+ after :each do
796
+ @channel.close
797
+ end
798
+
799
+ it "deletes an individual binding between two exchanges" do
800
+ routing_key = 'test.key'
801
+ sx = @channel.fanout("http.client.fanout_source")
802
+ dx = @channel.fanout("http.client.fanout_destination")
803
+ dx.bind(sx)
804
+
805
+ xs = subject.list_bindings_between_exchanges("/", dx.name, sx.name)
806
+ b = xs.first
807
+
808
+ expect(subject.delete_exchange_binding("/", dx.name, sx.name, b.properties_key)).to eq(true)
809
+
810
+ xs = subject.list_bindings_between_exchanges("/", dx.name, sx.name)
811
+
812
+ expect(xs.size).to eq(0)
813
+
814
+ dx.delete
815
+ sx.delete
816
+ end
817
+ end
818
+
651
819
  describe "GET /api/vhosts" do
652
820
  it "returns a list of vhosts" do
653
821
  xs = subject.list_vhosts
@@ -765,11 +933,22 @@ describe RabbitMQ::HTTP::Client do
765
933
  end
766
934
 
767
935
  describe "PUT /api/users/:name" do
768
- it "updates information about a user" do
769
- subject.update_user("alt", :tags => "http, policymaker, management", :password => "alt")
936
+ context "with tags provided explicitly" do
937
+ it "updates information about a user" do
938
+ subject.update_user("alt", :tags => "http, policymaker, management", :password => "alt")
770
939
 
771
- u = subject.user_info("alt")
772
- expect(u.tags).to eq("http,policymaker,management")
940
+ u = subject.user_info("alt")
941
+ expect(u.tags).to eq("http,policymaker,management")
942
+ end
943
+ end
944
+
945
+ context "without tags provided" do
946
+ it "uses blank tag list" do
947
+ subject.update_user("alt", :password => "alt")
948
+
949
+ u = subject.user_info("alt")
950
+ expect(u.tags).to eq("")
951
+ end
773
952
  end
774
953
  end
775
954
 
@@ -815,7 +994,7 @@ describe RabbitMQ::HTTP::Client do
815
994
 
816
995
  describe "PUT /api/permissions/:vhost/:user" do
817
996
  it "updates permissions of a user in a vhost" do
818
- subject.update_permissions_of("/", "guest", :write => ".*", :read => ".*", :configure => ".*")
997
+ subject.update_permissions_of("/", "guest", {write: ".*", read: ".*", configure: ".*"})
819
998
 
820
999
  p = subject.list_permissions_of("/", "guest")
821
1000
 
@@ -827,14 +1006,13 @@ describe RabbitMQ::HTTP::Client do
827
1006
 
828
1007
  describe "DELETE /api/permissions/:vhost/:user" do
829
1008
  it "clears permissions of a user in a vhost" do
830
- pending
831
- subject.create_user("/", "alt3")
832
- subject.update_permissions_of("/", "alt3", :write => ".*", :read => ".*", :configure => ".*")
1009
+ subject.create_user("alt3", {password: "s3cRE7"})
1010
+ subject.update_permissions_of("/", "alt3", {write: ".*", read: ".*", configure: ".*"}).inspect
833
1011
  subject.clear_permissions_of("/", "alt3")
834
1012
 
835
- p = subject.list_permissions_of("/", "alt3")
836
-
837
- puts p.inspect
1013
+ expect do
1014
+ subject.list_permissions_of("/", "alt3")
1015
+ end.to raise_error(Faraday::Error::ResourceNotFound)
838
1016
  end
839
1017
  end
840
1018
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabbitmq_http_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klishin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -83,7 +83,8 @@ dependencies:
83
83
  description: RabbitMQ HTTP API client for Ruby
84
84
  email:
85
85
  - michael@defprotocol.org
86
- executables: []
86
+ executables:
87
+ - before_build.sh
87
88
  extensions: []
88
89
  extra_rdoc_files: []
89
90
  files:
@@ -95,6 +96,7 @@ files:
95
96
  - LICENSE.txt
96
97
  - README.md
97
98
  - Rakefile
99
+ - bin/before_build.sh
98
100
  - lib/rabbitmq/http/client.rb
99
101
  - lib/rabbitmq/http/client/version.rb
100
102
  - rabbitmq_http_api_client.gemspec
@@ -122,11 +124,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
124
  version: '0'
123
125
  requirements: []
124
126
  rubyforge_project:
125
- rubygems_version: 2.4.5
127
+ rubygems_version: 2.5.1
126
128
  signing_key:
127
129
  specification_version: 4
128
130
  summary: RabbitMQ HTTP API client for Ruby
129
131
  test_files:
130
132
  - spec/integration/client_spec.rb
131
133
  - spec/spec_helper.rb
132
- has_rdoc: