rhc 1.0.4 → 1.1.11
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.
- data/bin/rhc-chk +7 -2
- data/bin/rhc-user-info +0 -2
- data/features/cartridge.feature +10 -0
- data/features/lib/rhc_helper/cartridge.rb +9 -2
- data/features/lib/rhc_helper/commandify.rb +2 -3
- data/features/step_definitions/cartridge_steps.rb +10 -0
- data/lib/rhc-common.rb +1 -3
- data/lib/rhc/{cartridge_helper.rb → cartridge_helpers.rb} +1 -0
- data/lib/rhc/command_runner.rb +9 -15
- data/lib/rhc/commands.rb +4 -1
- data/lib/rhc/commands/app.rb +62 -30
- data/lib/rhc/commands/base.rb +1 -1
- data/lib/rhc/commands/cartridge.rb +29 -12
- data/lib/rhc/commands/sshkey.rb +3 -2
- data/lib/rhc/help_formatter.rb +3 -0
- data/lib/rhc/helpers.rb +34 -5
- data/lib/rhc/output_helpers.rb +2 -0
- data/lib/rhc/rest.rb +36 -13
- data/lib/rhc/rest/cartridge.rb +1 -1
- data/lib/rhc/rest/client.rb +9 -9
- data/lib/rhc/usage_templates/command_help.erb +1 -1
- data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
- data/lib/rhc/version.rb +2 -2
- data/lib/rhc/wizard.rb +1 -1
- data/spec/rest_spec_helper.rb +7 -3
- data/spec/rhc/cli_spec.rb +5 -1
- data/spec/rhc/command_spec.rb +4 -5
- data/spec/rhc/commands/app_spec.rb +25 -16
- data/spec/rhc/commands/cartridge_spec.rb +13 -6
- data/spec/rhc/commands/setup_spec.rb +13 -0
- data/spec/rhc/commands/sshkey_spec.rb +9 -8
- data/spec/rhc/helpers_spec.rb +31 -0
- data/spec/rhc/rest_application_spec.rb +0 -4
- data/spec/rhc/rest_client_spec.rb +3 -8
- data/spec/rhc/rest_spec.rb +138 -72
- data/spec/spec_helper.rb +6 -0
- metadata +26 -9
data/spec/rhc/helpers_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'rhc/helpers'
|
3
3
|
require 'rhc/ssh_key_helpers'
|
4
|
+
require 'rhc/cartridge_helpers'
|
4
5
|
require 'rhc/core_ext'
|
5
6
|
require 'highline/import'
|
6
7
|
require 'rhc/config'
|
@@ -294,3 +295,33 @@ describe HighLine do
|
|
294
295
|
output.should match "Ant\nidi\nses\ntab\nlis\nhme\nnta\nria\nnis\nm"
|
295
296
|
end
|
296
297
|
end
|
298
|
+
|
299
|
+
describe RHC::CartridgeHelpers do
|
300
|
+
before(:each) do
|
301
|
+
mock_terminal
|
302
|
+
@tests = HelperTests.new
|
303
|
+
end
|
304
|
+
|
305
|
+
subject do
|
306
|
+
Class.new(Object) do
|
307
|
+
include RHC::CartridgeHelpers
|
308
|
+
|
309
|
+
def config
|
310
|
+
@config ||= RHC::Config.new
|
311
|
+
end
|
312
|
+
end.new
|
313
|
+
end
|
314
|
+
|
315
|
+
describe '#find_cartridge' do
|
316
|
+
let(:cartridges){ [] }
|
317
|
+
let(:find_cartridges){ [] }
|
318
|
+
let(:rest_obj) do
|
319
|
+
Object.new.tap do |o|
|
320
|
+
o.stub(:find_cartridges).and_return(find_cartridges)
|
321
|
+
o.stub(:cartridges).and_return(cartridges)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
it { expect{ subject.find_cartridge(rest_obj, 'foo') }.should raise_error(RHC::CartridgeNotFoundException, 'Invalid cartridge specified: \'foo\'. No cartridges have been added to this app.') }
|
326
|
+
end
|
327
|
+
end
|
@@ -4,10 +4,6 @@ require 'stringio'
|
|
4
4
|
require 'rest_spec_helper'
|
5
5
|
require 'rhc/rest/client'
|
6
6
|
|
7
|
-
Spec::Runner.configure do |configuration|
|
8
|
-
include(RestSpecHelper)
|
9
|
-
end
|
10
|
-
|
11
7
|
# This object is used in a few cases where we need to inspect
|
12
8
|
# the logged output.
|
13
9
|
class MockClient < RHC::Rest::Client
|
@@ -445,8 +441,8 @@ module RHC
|
|
445
441
|
capture do
|
446
442
|
@client = MockClient.new(mock_href, mock_user, mock_pass, true)
|
447
443
|
@client.send logout_method.to_sym
|
448
|
-
|
449
|
-
|
444
|
+
|
445
|
+
stderr.should match(/Logout\/Close client$/)
|
450
446
|
end
|
451
447
|
end
|
452
448
|
end
|
@@ -455,8 +451,7 @@ module RHC
|
|
455
451
|
capture do
|
456
452
|
@client = MockClient.new(mock_href, mock_user, mock_pass, false)
|
457
453
|
@client.send logout_method.to_sym
|
458
|
-
|
459
|
-
$stderr.read.should == ''
|
454
|
+
stderr.should be_empty
|
460
455
|
end
|
461
456
|
end
|
462
457
|
end
|
data/spec/rhc/rest_spec.rb
CHANGED
@@ -2,26 +2,16 @@ require 'spec_helper'
|
|
2
2
|
require 'rest_spec_helper'
|
3
3
|
require 'rhc/rest'
|
4
4
|
|
5
|
-
Spec::Runner.configure do |configuration|
|
6
|
-
include(RestSpecHelper)
|
7
|
-
end
|
8
|
-
|
9
5
|
# We have to make an object to test the RHC::Rest module
|
10
6
|
class RHCRest
|
11
7
|
include RHC::Rest
|
12
8
|
end
|
13
9
|
|
14
10
|
module MockRestResponse
|
15
|
-
|
16
|
-
@error_code = error_code
|
17
|
-
end
|
18
|
-
def code
|
19
|
-
@error_code
|
20
|
-
end
|
11
|
+
attr_accessor :code, :read
|
21
12
|
end
|
22
13
|
|
23
14
|
module RHC
|
24
|
-
include RestSpecHelper
|
25
15
|
|
26
16
|
describe Rest do
|
27
17
|
subject{ RHCRest.new }
|
@@ -313,6 +303,17 @@ module RHC
|
|
313
303
|
end
|
314
304
|
end
|
315
305
|
|
306
|
+
context "with a socket errort" do
|
307
|
+
before{ stub_request(:get, mock_href).to_raise(SocketError) }
|
308
|
+
it "raises a resource access exception error" do
|
309
|
+
request = RestClient::Request.new(:url => mock_href,
|
310
|
+
:method => 'get',
|
311
|
+
:headers => {:accept => :json}
|
312
|
+
)
|
313
|
+
lambda { subject.request(request) }.should raise_error(RHC::Rest::ConnectionException, /unable to connect to the server/i)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
316
317
|
context "with a generic exception error" do
|
317
318
|
before do
|
318
319
|
stub_request(:get, mock_href).to_raise(Exception.new('Generic Error'))
|
@@ -349,104 +350,169 @@ module RHC
|
|
349
350
|
|
350
351
|
# process_error_response function
|
351
352
|
describe "#process_error_response" do
|
353
|
+
let(:json){ nil }
|
354
|
+
let(:body){ "<html><body>Something failed</body></html>" }
|
355
|
+
let(:code){ nil }
|
356
|
+
def response
|
357
|
+
(response = {}).extend(MockRestResponse)
|
358
|
+
response.code = code
|
359
|
+
response.read = json ? RHC::Json.encode(json) : body
|
360
|
+
response
|
361
|
+
end
|
362
|
+
|
352
363
|
context "with a 400 response" do
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
364
|
+
let(:code){ 400 }
|
365
|
+
|
366
|
+
it "raises a generic server error" do
|
367
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServerErrorException)
|
368
|
+
end
|
369
|
+
|
370
|
+
context "with a formatted JSON response" do
|
371
|
+
let(:json){ {:messages => [{ :severity => 'error', :text => 'mock error message' }] } }
|
372
|
+
it "raises a client error" do
|
373
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ClientErrorException, 'mock error message')
|
374
|
+
end
|
359
375
|
end
|
360
376
|
end
|
361
377
|
|
362
378
|
context "with a 401 response" do
|
379
|
+
let(:code){ 401 }
|
380
|
+
let(:json){ {} }
|
363
381
|
it "raises an 'unauthorized exception' error" do
|
364
|
-
|
365
|
-
json_data.extend(MockRestResponse)
|
366
|
-
json_data.set_code(401)
|
367
|
-
|
368
|
-
lambda { subject.process_error_response(json_data) }.should raise_error(RHC::Rest::UnAuthorizedException, 'Not authenticated')
|
382
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::UnAuthorizedException, 'Not authenticated')
|
369
383
|
end
|
370
384
|
end
|
371
385
|
|
372
386
|
context "with a 403 response" do
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
387
|
+
let(:code){ 403 }
|
388
|
+
|
389
|
+
it "raises a request denied error" do
|
390
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::RequestDeniedException)
|
391
|
+
end
|
392
|
+
|
393
|
+
context "with a formatted JSON response" do
|
394
|
+
let(:json){ { :messages => [{ :severity => 'error', :text => 'mock error message' }] } }
|
395
|
+
it "raises a 'request denied' error" do
|
396
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::RequestDeniedException, 'mock error message')
|
397
|
+
end
|
379
398
|
end
|
380
399
|
end
|
381
400
|
|
382
401
|
context "with a 404 response" do
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
402
|
+
let(:code){ 404 }
|
403
|
+
|
404
|
+
it "raises a Not Found error" do
|
405
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ResourceNotFoundException)
|
406
|
+
end
|
407
|
+
|
408
|
+
context "with a formatted JSON response" do
|
409
|
+
let(:json){ { :messages => [{ :severity => 'error', :text => 'mock error message' }] } }
|
410
|
+
it "raises a 'resource not found' error" do
|
411
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ResourceNotFoundException, 'mock error message')
|
412
|
+
end
|
389
413
|
end
|
390
414
|
end
|
391
415
|
|
392
416
|
context "with a 409 response" do
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
417
|
+
let(:code){ 409 }
|
418
|
+
|
419
|
+
it "raises a generic server error" do
|
420
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServerErrorException)
|
421
|
+
end
|
422
|
+
|
423
|
+
context "with a formatted JSON response" do
|
424
|
+
let(:json){ { :messages => [{ :severity => 'error', :text => 'mock error message' }] } }
|
425
|
+
it "raises a validation error" do
|
426
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ValidationException, 'mock error message')
|
427
|
+
end
|
399
428
|
end
|
400
429
|
end
|
401
430
|
|
402
431
|
context "with a 422 response" do
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
json_data.set_code(422)
|
408
|
-
lambda { subject.process_error_response(json_data) }.should raise_error(RHC::Rest::ValidationException, 'mock error message')
|
432
|
+
let(:code){ 422 }
|
433
|
+
|
434
|
+
it "raises a generic server error" do
|
435
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServerErrorException)
|
409
436
|
end
|
410
|
-
end
|
411
437
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
438
|
+
context "with a single JSON message" do
|
439
|
+
let(:json){ { :messages => [{ :severity => 'error', :text => 'mock error message' }] } }
|
440
|
+
it "raises a validation error" do
|
441
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ValidationException, 'mock error message')
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
context "with an empty JSON response" do
|
446
|
+
let(:json){ {} }
|
447
|
+
it "raises a validation error" do
|
448
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ValidationException, 'Not valid')
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
context "with multiple JSON messages" do
|
453
|
+
let(:json){ { :messages => [{ :field => 'error', :text => 'mock error message 1' },
|
454
|
+
{ :field => 'error', :text => 'mock error message 2' }] } }
|
455
|
+
it "raises a validation error with concatenated messages" do
|
456
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ValidationException, 'mock error message 1 mock error message 2')
|
457
|
+
end
|
420
458
|
end
|
421
459
|
end
|
422
460
|
|
423
461
|
context "with a 500 response" do
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
462
|
+
let(:code){ 500 }
|
463
|
+
|
464
|
+
it "raises a generic server error" do
|
465
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServerErrorException, /server did not respond correctly.*verify that you can access the OpenShift server/i)
|
466
|
+
end
|
467
|
+
|
468
|
+
context "when proxy is set" do
|
469
|
+
before{ RestClient.should_receive(:proxy).twice.and_return('http://foo.com') }
|
470
|
+
it "raises a generic server error with the proxy URL" do
|
471
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServerErrorException, /foo\.com/i)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
context "when request url is present" do
|
476
|
+
it "raises a generic server error with the request URL" do
|
477
|
+
lambda { subject.process_error_response(response, 'foo.bar') }.should raise_error(RHC::Rest::ServerErrorException, /foo\.bar/i)
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
context "with a formatted JSON response" do
|
482
|
+
let(:json){ { :messages => [{ :severity => 'error', :text => 'mock error message' }] } }
|
483
|
+
it "raises a server error" do
|
484
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServerErrorException, 'mock error message')
|
485
|
+
end
|
430
486
|
end
|
431
487
|
end
|
432
488
|
|
433
489
|
context "with a 503 response" do
|
490
|
+
let(:code){ 503 }
|
491
|
+
|
434
492
|
it "raises a 'service unavailable' error" do
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
493
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServiceUnavailableException)
|
494
|
+
end
|
495
|
+
|
496
|
+
context "with a formatted JSON response" do
|
497
|
+
let(:json){ { :messages => [{ :severity => 'error', :text => 'mock error message' }] } }
|
498
|
+
it "raises a 'service unavailable' error" do
|
499
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServiceUnavailableException, 'mock error message')
|
500
|
+
end
|
440
501
|
end
|
441
502
|
end
|
442
503
|
|
443
504
|
context "with an unhandled response code" do
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
505
|
+
let(:code){ 999 }
|
506
|
+
|
507
|
+
it "raises a generic server error" do
|
508
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServerErrorException)
|
509
|
+
end
|
510
|
+
|
511
|
+
context "with a formatted JSON response" do
|
512
|
+
let(:json){ { :messages => [{ :severity => 'error', :text => 'mock error message' }] } }
|
513
|
+
it "raises a resource access error" do
|
514
|
+
lambda { subject.process_error_response(response) }.should raise_error(RHC::Rest::ServerErrorException, 'Server returned an unexpected error code: 999')
|
515
|
+
end
|
450
516
|
end
|
451
517
|
end
|
452
518
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -25,6 +25,12 @@ require 'rhc/cli'
|
|
25
25
|
|
26
26
|
include WebMock::API
|
27
27
|
|
28
|
+
def stderr
|
29
|
+
$stderr.rewind
|
30
|
+
# some systems might redirect warnings to stderr
|
31
|
+
[$stderr,$terminal].map(&:read).delete_if{|x| x.strip.empty?}.join(' ')
|
32
|
+
end
|
33
|
+
|
28
34
|
module Commander::UI
|
29
35
|
alias :enable_paging_old :enable_paging
|
30
36
|
def enable_paging
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 1
|
9
|
+
- 11
|
10
|
+
version: 1.1.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Red Hat
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-11-
|
18
|
+
date: 2012-11-26 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -130,10 +130,21 @@ dependencies:
|
|
130
130
|
requirements:
|
131
131
|
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
hash:
|
133
|
+
hash: 49
|
134
134
|
segments:
|
135
135
|
- 0
|
136
|
-
|
136
|
+
- 8
|
137
|
+
- 7
|
138
|
+
version: 0.8.7
|
139
|
+
- - <=
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 11
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
- 9
|
145
|
+
- 2
|
146
|
+
- 2
|
147
|
+
version: 0.9.2.2
|
137
148
|
type: :development
|
138
149
|
version_requirements: *id008
|
139
150
|
- !ruby/object:Gem::Dependency
|
@@ -287,6 +298,7 @@ files:
|
|
287
298
|
- lib/rhc/vendor/parseconfig.rb
|
288
299
|
- lib/rhc/vendor/sshkey.rb
|
289
300
|
- lib/rhc/vendor/okjson.rb
|
301
|
+
- lib/rhc/cartridge_helpers.rb
|
290
302
|
- lib/rhc/command_runner.rb
|
291
303
|
- lib/rhc/context_helper.rb
|
292
304
|
- lib/rhc/rest.rb
|
@@ -305,8 +317,8 @@ files:
|
|
305
317
|
- lib/rhc/helpers.rb
|
306
318
|
- lib/rhc/config.rb
|
307
319
|
- lib/rhc/coverage_helper.rb
|
308
|
-
- lib/rhc/cartridge_helper.rb
|
309
320
|
- lib/rhc-common.rb
|
321
|
+
- lib/rhc/usage_templates/command_syntax_help.erb
|
310
322
|
- lib/rhc/usage_templates/missing_help.erb
|
311
323
|
- lib/rhc/usage_templates/command_help.erb
|
312
324
|
- lib/rhc/usage_templates/help.erb
|
@@ -396,7 +408,12 @@ has_rdoc: true
|
|
396
408
|
homepage: https://github.com/openshift/rhc
|
397
409
|
licenses: []
|
398
410
|
|
399
|
-
post_install_message:
|
411
|
+
post_install_message: |-
|
412
|
+
===========================================================================
|
413
|
+
|
414
|
+
If this is your first time installing the RHC tools, please run 'rhc setup'
|
415
|
+
|
416
|
+
===========================================================================
|
400
417
|
rdoc_options: []
|
401
418
|
|
402
419
|
require_paths:
|