rhc 1.2.7 → 1.3.8

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.
Files changed (97) hide show
  1. data/bin/rhc +6 -8
  2. data/bin/rhc-chk +23 -10
  3. data/features/domain.feature +1 -1
  4. data/features/lib/rhc_helper.rb +3 -2
  5. data/features/lib/rhc_helper/api.rb +7 -0
  6. data/features/lib/rhc_helper/app.rb +8 -10
  7. data/features/lib/rhc_helper/domain.rb +2 -1
  8. data/features/lib/rhc_helper/runnable.rb +2 -24
  9. data/features/sshkey.feature +3 -3
  10. data/features/step_definitions/cartridge_steps.rb +6 -6
  11. data/features/step_definitions/client_steps.rb +0 -1
  12. data/features/step_definitions/sshkey_steps.rb +2 -2
  13. data/features/support/before_hooks.rb +0 -1
  14. data/features/support/env.rb +5 -3
  15. data/lib/rhc-common.rb +1 -1
  16. data/lib/rhc.rb +9 -8
  17. data/lib/rhc/auth.rb +3 -0
  18. data/lib/rhc/auth/basic.rb +54 -0
  19. data/lib/rhc/cartridge_helpers.rb +11 -5
  20. data/lib/rhc/cli.rb +4 -2
  21. data/lib/rhc/command_runner.rb +35 -30
  22. data/lib/rhc/commands.rb +127 -18
  23. data/lib/rhc/commands/account.rb +24 -0
  24. data/lib/rhc/commands/alias.rb +1 -1
  25. data/lib/rhc/commands/app.rb +210 -209
  26. data/lib/rhc/commands/apps.rb +22 -0
  27. data/lib/rhc/commands/base.rb +10 -77
  28. data/lib/rhc/commands/cartridge.rb +35 -35
  29. data/lib/rhc/commands/domain.rb +20 -13
  30. data/lib/rhc/commands/git_clone.rb +30 -0
  31. data/lib/rhc/commands/{port-forward.rb → port_forward.rb} +3 -3
  32. data/lib/rhc/commands/server.rb +28 -16
  33. data/lib/rhc/commands/setup.rb +18 -1
  34. data/lib/rhc/commands/snapshot.rb +4 -4
  35. data/lib/rhc/commands/sshkey.rb +4 -18
  36. data/lib/rhc/commands/tail.rb +32 -9
  37. data/lib/rhc/config.rb +168 -99
  38. data/lib/rhc/context_helper.rb +22 -9
  39. data/lib/rhc/core_ext.rb +41 -1
  40. data/lib/rhc/exceptions.rb +21 -5
  41. data/lib/rhc/git_helpers.rb +81 -0
  42. data/lib/rhc/help_formatter.rb +21 -1
  43. data/lib/rhc/helpers.rb +222 -87
  44. data/lib/rhc/output_helpers.rb +94 -110
  45. data/lib/rhc/rest.rb +15 -198
  46. data/lib/rhc/rest/api.rb +88 -0
  47. data/lib/rhc/rest/application.rb +29 -30
  48. data/lib/rhc/rest/attributes.rb +27 -0
  49. data/lib/rhc/rest/base.rb +29 -33
  50. data/lib/rhc/rest/cartridge.rb +42 -20
  51. data/lib/rhc/rest/client.rb +351 -89
  52. data/lib/rhc/rest/domain.rb +7 -13
  53. data/lib/rhc/rest/gear_group.rb +1 -1
  54. data/lib/rhc/rest/key.rb +7 -2
  55. data/lib/rhc/rest/mock.rb +609 -0
  56. data/lib/rhc/rest/user.rb +6 -2
  57. data/lib/rhc/{ssh_key_helpers.rb → ssh_helpers.rb} +58 -28
  58. data/lib/rhc/{targz.rb → tar_gz.rb} +0 -0
  59. data/lib/rhc/usage_templates/command_help.erb +4 -1
  60. data/lib/rhc/usage_templates/help.erb +24 -11
  61. data/lib/rhc/usage_templates/options_help.erb +14 -0
  62. data/lib/rhc/wizard.rb +283 -213
  63. data/spec/keys/example.pem +23 -0
  64. data/spec/keys/example_private.pem +27 -0
  65. data/spec/keys/server.pem +19 -0
  66. data/spec/rest_spec_helper.rb +3 -371
  67. data/spec/rhc/auth_spec.rb +226 -0
  68. data/spec/rhc/cli_spec.rb +41 -14
  69. data/spec/rhc/command_spec.rb +44 -15
  70. data/spec/rhc/commands/account_spec.rb +41 -0
  71. data/spec/rhc/commands/alias_spec.rb +16 -15
  72. data/spec/rhc/commands/app_spec.rb +115 -92
  73. data/spec/rhc/commands/apps_spec.rb +39 -0
  74. data/spec/rhc/commands/cartridge_spec.rb +134 -112
  75. data/spec/rhc/commands/domain_spec.rb +31 -86
  76. data/spec/rhc/commands/git_clone_spec.rb +56 -0
  77. data/spec/rhc/commands/{port-forward_spec.rb → port_forward_spec.rb} +27 -32
  78. data/spec/rhc/commands/server_spec.rb +28 -3
  79. data/spec/rhc/commands/setup_spec.rb +29 -11
  80. data/spec/rhc/commands/snapshot_spec.rb +4 -3
  81. data/spec/rhc/commands/sshkey_spec.rb +24 -56
  82. data/spec/rhc/commands/tail_spec.rb +26 -9
  83. data/spec/rhc/commands/threaddump_spec.rb +12 -11
  84. data/spec/rhc/config_spec.rb +211 -164
  85. data/spec/rhc/context_spec.rb +2 -0
  86. data/spec/rhc/helpers_spec.rb +242 -46
  87. data/spec/rhc/rest_application_spec.rb +42 -28
  88. data/spec/rhc/rest_client_spec.rb +110 -93
  89. data/spec/rhc/rest_spec.rb +220 -131
  90. data/spec/rhc/targz_spec.rb +1 -1
  91. data/spec/rhc/wizard_spec.rb +435 -624
  92. data/spec/spec.opts +1 -1
  93. data/spec/spec_helper.rb +140 -6
  94. data/spec/wizard_spec_helper.rb +326 -0
  95. metadata +163 -143
  96. data/lib/rhc/client.rb +0 -17
  97. data/lib/rhc/git_helper.rb +0 -59
@@ -1,21 +1,23 @@
1
1
  require 'spec_helper'
2
- require 'rhc/wizard'
3
- require 'rhc/config'
2
+ require 'rest_spec_helper'
4
3
  require 'rhc/commands/setup'
5
- require 'webmock/rspec'
6
4
 
7
5
  # just test the command runner as we already have extensive wizard tests
8
6
  describe RHC::Commands::Setup do
7
+ subject{ RHC::Commands::Setup }
8
+ let(:instance){ subject.new }
9
+ let!(:config){ base_config }
10
+ before{ described_class.send(:public, *described_class.protected_instance_methods) }
9
11
 
10
- before(:each) { RHC::Config.set_defaults }
12
+ describe '#run' do
13
+ it{ expects_running('setup').should call(:run).on(instance).with(no_args) }
11
14
 
12
- describe 'run' do
13
15
  let(:arguments) { ['setup', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
14
16
 
15
17
  before(:each) do
16
18
  @wizard = mock('wizard')
17
19
  @wizard.stub!(:run).and_return(true)
18
- RHC::RerunWizard.stub!(:new) { @wizard }
20
+ RHC::RerunWizard.stub!(:new){ @wizard }
19
21
  end
20
22
 
21
23
  context 'when no issues' do
@@ -32,12 +34,29 @@ describe RHC::Commands::Setup do
32
34
  end
33
35
  end
34
36
 
37
+ it{ expects_running('setup').should call(:run).on(instance).with(no_args) }
38
+ it{ command_for('setup', '--clean').options.clean.should be_true }
39
+
40
+ it{ command_for('setup').options.server.should == 'openshift.redhat.com' }
41
+ it{ command_for('setup', '--server', 'foo.com').options.server.should == 'foo.com' }
42
+ =begin context 'when libra_server is set' do
43
+ before{ ENV.should_receive(:[]).any_number_of_times.with('LIBRA_SERVER').and_return('bar.com') }
44
+ it{ command_for('setup').config['libra_server'].should == 'bar.com' }
45
+ it{ command_for('setup').options.server.should == 'bar.com' }
46
+ it{ command_for('setup', '--server', 'foo.com').options.server.should == 'foo.com' }
47
+ =end end
48
+
49
+ context 'when --clean is used' do
50
+ let!(:config){ base_config{ |config, defaults| defaults.add 'libra_server', 'test.com' } }
51
+
52
+ it("should ignore a config value"){ command_for('setup', '--clean').options.server.should == 'openshift.redhat.com' }
53
+ end
54
+
35
55
  context 'when -d is passed' do
36
56
  let(:arguments) { ['setup', '-d', '-l', 'test@test.foo'] }
37
57
  # 'y' for the password prompt
38
58
  let(:input) { ['', 'y', '', ''] }
39
-
40
- before(:each){ @rc = MockRestClient.new }
59
+ let!(:rest_client){ MockRestClient.new }
41
60
 
42
61
  it("succeeds"){ FakeFS{ expect { run input }.should exit_with_code 0 } }
43
62
  it("the output includes debug output") do
@@ -49,8 +68,7 @@ describe RHC::Commands::Setup do
49
68
  let(:arguments) { ['setup', '-l', 'test@test.foo'] }
50
69
  # 'y' for the password prompt
51
70
  let(:input) { ['', 'y', '', ''] }
52
-
53
- before(:each){ @rc = MockRestClient.new }
71
+ let!(:rest_client){ MockRestClient.new }
54
72
 
55
73
  it("succeeds"){ FakeFS{ expect { run input }.should exit_with_code 0 } }
56
74
  it("sets the user name to the value given by the command line") do
@@ -66,7 +84,7 @@ describe RHC::Commands::Setup do
66
84
  @wizard.stub!(:run).and_return(true)
67
85
  expect { run }.should exit_with_code(0)
68
86
  end
69
- it('should output usage') { run_output.should match("Easy to use wizard for getting started") }
87
+ it('should output usage') { run_output.should match("Connects to an OpenShift server to get you started. Will") }
70
88
  end
71
89
  end
72
90
  end
@@ -2,15 +2,16 @@ require 'spec_helper'
2
2
  require 'rest_spec_helper'
3
3
  require 'rhc/commands/snapshot'
4
4
  require 'rhc/config'
5
+ require 'rhc/tar_gz'
5
6
 
6
7
  describe RHC::Commands::Snapshot do
7
8
 
8
9
  APP_NAME = 'mockapp'
9
10
 
11
+ let!(:rest_client) { MockRestClient.new }
10
12
  before(:each) do
11
- RHC::Config.set_defaults
12
- @rc = MockRestClient.new
13
- @app = @rc.add_domain("mockdomain").add_application APP_NAME, 'mock-1.0'
13
+ user_config
14
+ @app = rest_client.add_domain("mockdomain").add_application APP_NAME, 'mock-1.0'
14
15
  @ssh_uri = URI.parse @app.ssh_url
15
16
  filename = APP_NAME + '.tar.gz'
16
17
  FileUtils.cp(File.expand_path('../../assets/targz_sample.tar.gz', __FILE__), filename)
@@ -4,57 +4,41 @@ require 'rhc/config'
4
4
 
5
5
 
6
6
  describe RHC::Commands::Sshkey do
7
- before(:each) do
8
- RHC::Config.set_defaults
9
- end
10
-
7
+ let!(:rest_client){ MockRestClient.new }
8
+ before{ user_config }
9
+
11
10
  describe 'list' do
12
-
11
+
13
12
  context "when run with list command" do
14
-
15
13
  let(:arguments) { %w[sshkey list --noprompt --config test.conf -l test@test.foo -p password --trace] }
16
14
 
17
- before(:each) do
18
- @rc = MockRestClient.new
19
- end
20
-
21
15
  it { expect { run }.should exit_with_code(0) }
22
- it { run_output.should match("Name: mockkey") }
16
+ it { run_output.should match(/mockkey1 \(type: ssh-rsa\)/) }
23
17
  end
24
18
  end
25
-
19
+
26
20
  describe 'show' do
27
-
28
21
  context "when run with show command" do
29
-
30
22
  let(:arguments) { %w[sshkey show mockkey1 --noprompt --config test.conf -l test@test.foo -p password --trace] }
31
23
 
32
- before(:each) do
33
- @rc = MockRestClient.new
34
- end
35
-
36
24
  it { expect { run }.should exit_with_code(0) }
37
- it { run_output.should match("Name: mockkey1") }
25
+ it { run_output.should match(/mockkey1 \(type: ssh-rsa\)/) }
38
26
  end
39
27
  end
40
-
28
+
41
29
  describe "add" do
42
30
  context "when adding a valid key" do
43
31
  let(:arguments) { %w[sshkey add --noprompt --config test.conf -l test@test.foo -p password foobar id_rsa.pub] }
44
-
45
- before :each do
46
- @rc = MockRestClient.new
47
- end
48
-
32
+
49
33
  it 'adds the key' do
50
34
  FakeFS do
51
- keys = @rc.sshkeys
35
+ keys = rest_client.sshkeys
52
36
  num_keys = keys.length
53
37
  File.open('id_rsa.pub', 'w') do |f|
54
38
  f << 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCnCOqK7/mmvZ9AtCAerxjAasJ1rSpfuWT4vNm1+O/Fh0Di3chTWjY9a0M2hEnqkqnVG589L9CqCUeT0kdc3Vgw3JEcacSUr1z7tLr9kO+p/D5lSdQYzDGGRFOZ0H6lc/y8iNxWV1VO/sJvKx6cr5zvKIn8Q6GvhVNOxlai0IOb9FJxLGK95GLpZ+elzh8Tc9giy7KfwheAwhV2JoF9uRltE5JP/CNs7w/E29i1Z+jlueuu8RVotLmhSVNJm91Ey7OCtoI1iBE0Wv/SucFe32Qi08RWTM/MaGGz93KQNOVRGjNkosJjPmP1qU6WGBfliDkJAZXB0b6sEcnx1fbVikwZ'
55
39
  end
56
40
  expect { run }.should exit_with_code(0)
57
- @rc.sshkeys.length.should == num_keys + 1
41
+ rest_client.sshkeys.length.should == num_keys + 1
58
42
  end
59
43
  end
60
44
  end
@@ -62,20 +46,16 @@ describe RHC::Commands::Sshkey do
62
46
  context "when adding an invalid key" do
63
47
  let(:arguments) { %w[sshkey add --noprompt --config test.conf -l test@test.foo -p password foobar id_rsa.pub] }
64
48
 
65
- before :each do
66
- @rc = MockRestClient.new
67
- end
68
-
69
49
  it "fails to add the key" do
70
50
  FakeFS do
71
- keys = @rc.sshkeys
51
+ keys = rest_client.sshkeys
72
52
  num_keys = keys.length
73
53
  File.open('id_rsa.pub', 'w') do |f|
74
54
  f << 'ssh-rsa AADAQABAAABAQCnCOqK7/mmvZ9AtCAerxjAasJ1rSpfuWT4vNm1+O/Fh0Di3chTWjY9a0M2hEnqkqnVG589L9CqCUeT0kdc3Vgw3JEcacSUr1z7tLr9kO+p/D5lSdQYzDGGRFOZ0H6lc/y8iNxWV1VO/sJvKx6cr5zvKIn8Q6GvhVNOxlai0IOb9FJxLGK95GLpZ+elzh8Tc9giy7KfwheAwhV2JoF9uRltE5JP/CNs7w/E29i1Z+jlueuu8RVotLmhSVNJm91Ey7OCtoI1iBE0Wv/SucFe32Qi08RWTM/MaGGz93KQNOVRGjNkosJjPmP1qU6WGBfliDkJAZXB0b6sEcnx1fbVikwZ'
75
55
  end
76
56
  expect { run }.should exit_with_code(128)
77
- expect { run_output.should match("Name: mockkey") }
78
- @rc.sshkeys.length.should == num_keys
57
+ expect { run_output.should match(/Name:.* mockkey/) }
58
+ rest_client.sshkeys.length.should == num_keys
79
59
  end
80
60
  end
81
61
  end
@@ -83,20 +63,16 @@ describe RHC::Commands::Sshkey do
83
63
  context "when adding an invalid key with --confirm" do
84
64
  let(:arguments) { %w[sshkey add --noprompt --confirm --config test.conf -l test@test.foo -p password foobar id_rsa.pub] }
85
65
 
86
- before :each do
87
- @rc = MockRestClient.new
88
- end
89
-
90
66
  it "warns and then adds the key" do
91
67
  FakeFS do
92
- keys = @rc.sshkeys
68
+ keys = rest_client.sshkeys
93
69
  num_keys = keys.length
94
70
  File.open('id_rsa.pub', 'w') do |f|
95
71
  f << 'ssh-rsa AADAQABAAABAQCnCOqK7/mmvZ9AtCAerxjAasJ1rSpfuWT4vNm1+O/Fh0Di3chTWjY9a0M2hEnqkqnVG589L9CqCUeT0kdc3Vgw3JEcacSUr1z7tLr9kO+p/D5lSdQYzDGGRFOZ0H6lc/y8iNxWV1VO/sJvKx6cr5zvKIn8Q6GvhVNOxlai0IOb9FJxLGK95GLpZ+elzh8Tc9giy7KfwheAwhV2JoF9uRltE5JP/CNs7w/E29i1Z+jlueuu8RVotLmhSVNJm91Ey7OCtoI1iBE0Wv/SucFe32Qi08RWTM/MaGGz93KQNOVRGjNkosJjPmP1qU6WGBfliDkJAZXB0b6sEcnx1fbVikwZ'
96
72
  end
97
73
  expect { run }.should exit_with_code(0)
98
74
  expect { run_output.should match("key you are uploading is not recognized") }
99
- @rc.sshkeys.length.should == num_keys + 1
75
+ rest_client.sshkeys.length.should == num_keys + 1
100
76
  end
101
77
  end
102
78
  end
@@ -126,38 +102,30 @@ describe RHC::Commands::Sshkey do
126
102
  File.should_receive(:open).and_raise(Errno::EACCES)
127
103
  expect { run }.should exit_with_code(128)
128
104
  end
129
-
105
+
130
106
  end
131
107
  end
132
-
108
+
133
109
  describe "remove" do
134
110
  context "when removing an existing key" do
135
111
  let (:arguments) { %w[sshkey remove --noprompt --config test.conf -l test@test.foo -p password mockkey2] }
136
-
137
- before :each do
138
- @rc = MockRestClient.new
139
- end
140
-
112
+
141
113
  it 'deletes the key' do
142
- keys = @rc.sshkeys
114
+ keys = rest_client.sshkeys
143
115
  num_keys = keys.length
144
116
  expect {run}.should exit_with_code(0)
145
- @rc.sshkeys.length.should == num_keys - 1
117
+ rest_client.sshkeys.length.should == num_keys - 1
146
118
  end
147
119
  end
148
120
 
149
121
  context "when removing a nonexistent key" do
150
122
  let (:arguments) { %w[sshkey remove --noprompt --config test.conf -l test@test.foo -p password no_match] }
151
-
152
- before :each do
153
- @rc = MockRestClient.new
154
- @keys = @rc.sshkeys
155
- end
156
-
123
+ before{ @keys = rest_client.sshkeys }
124
+
157
125
  it 'leaves keys untouched' do
158
126
  num_keys = @keys.length
159
127
  expect {run}.should exit_with_code(0)
160
- @rc.sshkeys.length.should == num_keys
128
+ rest_client.sshkeys.length.should == num_keys
161
129
  end
162
130
  end
163
131
  end
@@ -2,12 +2,14 @@ require 'spec_helper'
2
2
  require 'rest_spec_helper'
3
3
  require 'rhc/commands/tail'
4
4
  require 'rhc/config'
5
+
5
6
  describe RHC::Commands::Tail do
7
+ let!(:rest_client) { MockRestClient.new }
6
8
  before(:each) do
7
- RHC::Config.set_defaults
8
- @rc = MockRestClient.new
9
- domain = @rc.add_domain("mock-domain-0")
9
+ user_config
10
+ domain = rest_client.add_domain("mock-domain-0")
10
11
  @app = domain.add_application("mock-app-0", "ruby-1.8.7")
12
+ @app.stub(:ssh_url).and_return("ssh://user@test.domain.com")
11
13
  end
12
14
 
13
15
  describe 'help' do
@@ -22,13 +24,28 @@ describe RHC::Commands::Tail do
22
24
  end
23
25
 
24
26
  describe 'tail' do
25
- let(:arguments) { ['tail', 'mock-app-0', '--noprompt', '--trace', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
26
- context 'tail is run on an unreachable domain' do
27
- it { expect { run }.should raise_error(SocketError) }
28
- end
29
- context 'tail succeeds and exits on Interrupt' do
30
- before (:each) { @app.stub(:tail) { raise Interrupt.new } }
27
+ let(:arguments) { ['tail', 'mock-app-0'] }
28
+
29
+ context 'when ssh connects' do
30
+ before (:each) {Net::SSH.should_receive(:start).with('test.domain.com', 'user') }
31
31
  it { expect { run }.should exit_with_code(0) }
32
32
  end
33
+
34
+ context 'is run on an unreachable domain' do
35
+ before (:each) {Net::SSH.should_receive(:start).and_raise(SocketError) }
36
+ it { expect { run }.should exit_with_code(1) }
37
+ it { run_output.should =~ /The connection to test.domain.com failed: / }
38
+ end
39
+
40
+ context 'is refused' do
41
+ before (:each) {Net::SSH.should_receive(:start).and_raise(Errno::ECONNREFUSED) }
42
+ it { expect { run }.should exit_with_code(1) }
43
+ it { run_output.should =~ /The server test.domain.com refused a connection with user user/ }
44
+ end
45
+
46
+ context 'succeeds and exits on Interrupt' do
47
+ before (:each) { rest_client.stub(:find_domain) { raise Interrupt } }
48
+ it { expect { run }.should raise_error(Interrupt) }
49
+ end
33
50
  end
34
51
  end
@@ -7,11 +7,12 @@ describe RHC::Commands::Threaddump do
7
7
  let(:domain_0_links) { mock_response_links(mock_domain_links('mock_domain_0')) }
8
8
  let(:domain_1_links) { mock_response_links(mock_domain_links('mock_domain_1')) }
9
9
  let(:app_0_links) { mock_response_links(mock_app_links('mock_domain_0', 'mock_app_0')) }
10
+ let!(:rest_client){ MockRestClient.new }
11
+
10
12
  before(:each) do
11
- RHC::Config.set_defaults
12
- @rc = MockRestClient.new
13
- @rc.add_domain("mock_domain_0").add_application("mock_app_0", "ruby-1.8.7")
14
- stub_api_request(:any, client_links['LIST_DOMAINS']['relative']).with(:headers => {'Accept-Encoding'=>'gzip, deflate'}).
13
+ user_config
14
+ rest_client.add_domain("mock_domain_0").add_application("mock_app_0", "ruby-1.8.7")
15
+ stub_api_request(:any, client_links['LIST_DOMAINS']['relative']).
15
16
  to_return({ :body => {
16
17
  :type => 'domains',
17
18
  :data =>
@@ -24,7 +25,7 @@ describe RHC::Commands::Threaddump do
24
25
  }.to_json,
25
26
  :status => 200
26
27
  })
27
- stub_api_request(:any, domain_0_links['LIST_APPLICATIONS']['relative']).with(:headers => {'Accept-Encoding'=>'gzip, deflate'}).
28
+ stub_api_request(:any, domain_0_links['LIST_APPLICATIONS']['relative']).
28
29
  to_return({ :body => {
29
30
  :type => 'applications',
30
31
  :data =>
@@ -39,7 +40,7 @@ describe RHC::Commands::Threaddump do
39
40
  }.to_json,
40
41
  :status => 200
41
42
  })
42
- stub_api_request(:any, app_0_links['THREAD_DUMP']['relative']).with(:body => {:event => 'thread-dump'}, :headers => {'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'17', 'Content-Type'=>'application/x-www-form-urlencoded'}).
43
+ stub_api_request(:post, app_0_links['THREAD_DUMP']['relative'], false).
43
44
  to_return({ :body => {
44
45
  :type => 'application',
45
46
  :data =>
@@ -69,13 +70,13 @@ describe RHC::Commands::Threaddump do
69
70
  end
70
71
 
71
72
  describe 'threaddump' do
72
- let(:arguments) { ['threaddump', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password', 'mock_app_0'] }
73
- context 'with no issues' do
74
- it { expect { run }.should exit_with_code(0) }
75
- end
73
+ let(:arguments) { ['threaddump', 'mock_app_0'] }
74
+ it { expect { run }.should exit_with_code(0) }
75
+ it { run_output.should =~ /Application test thread dump complete/ }
76
76
  end
77
+
77
78
  describe 'threaddump no args' do
78
- let(:arguments) { ['threaddump', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
79
+ let(:arguments) { ['threaddump'] }
79
80
  context 'args not supplied' do
80
81
  it { expect { run }.should exit_with_code(1) }
81
82
  end
@@ -3,10 +3,12 @@ require 'rhc/config'
3
3
  require 'net/http'
4
4
 
5
5
  describe RHC::Config do
6
+ subject{ RHC::Config }
6
7
  before(:all) do
7
8
  ENV['LIBRA_SERVER'] = nil
8
9
  ENV['http_proxy'] = nil
9
10
  mock_terminal
11
+ RHC::Config.stub(:home_dir).and_return('/home/mock_user')
10
12
  FakeFS.activate!
11
13
  FakeFS::FileSystem.clear
12
14
  end
@@ -16,195 +18,240 @@ describe RHC::Config do
16
18
  end
17
19
 
18
20
  describe "class" do
19
- subject{ RHC::Config }
20
- it("should raise when foo is invoked") { expect{ RHC::Config.method_missing(:foo) }.to raise_error(NoMethodError) }
21
- it("should invoke a method on default") { RHC::Config.username.should be RHC::Config.default.username }
21
+ it("should raise when foo is invoked") { expect{ subject.method_missing(:foo) }.to raise_error(NoMethodError) }
22
+ it("should invoke a method on default") { subject.username.should be subject.default.username }
22
23
  end
23
24
 
24
- context "Config default values with no files" do
25
- before(:each) do
26
- RHC::Config.initialize
25
+ let(:values){ {} }
26
+
27
+ describe "#use_config" do
28
+ subject{ RHC::Config.new.tap{ |c| c.stub(:load_config_files) } }
29
+
30
+ context "when an exception is raised" do
31
+ before{ subject.should_receive(:set_opts_config).with(File.expand_path('foo')).and_raise(Errno::EISDIR.new('foo')) }
32
+ it("should wrap the error"){ expect{ subject.use_config('foo') }.to raise_error(ArgumentError, /Unable to read configuration file.*foo/) }
33
+ end
34
+ end
35
+
36
+ describe "#to_options" do
37
+ subject do
38
+ RHC::Config.new.tap do |c|
39
+ c.stub(:home_dir).and_return('/home/mock_user')
40
+ c.stub(:load_config_files)
41
+ c.instance_variable_set(:@opts, values)
42
+ c.instance_variable_set(:@defaults, nil)
43
+ end
44
+ end
45
+
46
+ context "with an non true value for insecure" do
47
+ let(:values){ {'insecure' => 'untruth'} }
48
+ its(:to_options){ should == {:insecure => 'untruth'} }
27
49
  end
28
50
 
29
- it "should not have any configs" do
30
- RHC::Config.has_global_config?.should be_false
31
- RHC::Config.has_local_config?.should be_false
32
- RHC::Config.has_opts_config?.should be_false
51
+ context "with an invalid timeout" do
52
+ let(:values){ {'timeout' => 'a'} }
53
+ its(:to_options){ should == {:timeout => 'a'} }
33
54
  end
34
55
 
56
+ context "with standard values" do
57
+ let(:values) do
58
+ {
59
+ 'insecure' => 'true',
60
+ 'default_rhlogin' => 'user',
61
+ 'libra_server' => 'test.com',
62
+ 'password' => 'pass',
63
+ 'ssl_client_cert_file' => 'file1',
64
+ 'ssl_ca_file' => 'file2',
65
+ 'timeout' => '1',
66
+ }
67
+ end
68
+ its(:to_options){ should == {:insecure => 'true', :timeout => '1', :ssl_ca_file => 'file2', :ssl_client_cert_file => 'file1', :rhlogin => 'user', :password => 'pass', :server => 'test.com'} }
69
+ end
70
+ end
71
+
72
+ context "Config default values with no files" do
73
+ before{ subject.initialize }
74
+
75
+ its(:has_global_config?){ should be_false }
76
+ its(:has_local_config?){ should be_false }
77
+ its(:has_opts_config?){ should be_false }
78
+
35
79
  it "should return openshift.redhat.com for the server" do
36
- RHC::Config['libra_server'].should == "openshift.redhat.com"
37
- RHC::Config.default_rhlogin.should be_nil
38
- RHC::Config.config_user("default@redhat.com")
39
- RHC::Config.default_rhlogin.should == "default@redhat.com"
80
+ subject['libra_server'].should == "openshift.redhat.com"
40
81
  end
41
82
  end
42
83
 
43
84
  context "Config values with /etc/openshift/express.conf" do
44
85
  it "should have only a global config" do
45
86
  ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com", "global@redhat.com")
46
- RHC::Config.initialize
47
- RHC::Config.has_global_config?.should be_true
48
- RHC::Config.has_local_config?.should be_false
49
- RHC::Config.has_opts_config?.should be_false
87
+ subject.initialize
88
+ subject.has_global_config?.should be_true
89
+ subject.has_local_config?.should be_false
90
+ subject.has_opts_config?.should be_false
50
91
  end
51
92
 
52
93
  it "should get values from the global config" do
53
94
  ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
54
95
  "global@redhat.com",
55
96
  {"random_value" => 12})
56
- RHC::Config.initialize
97
+ subject.initialize
57
98
 
58
- RHC::Config['libra_server'].should == "global.openshift.redhat.com"
59
- RHC::Config.default_rhlogin.should == "global@redhat.com"
60
- RHC::Config['random_value'].should == "12"
61
- RHC::Config['non_value'].should be_nil
99
+ subject['libra_server'].should == "global.openshift.redhat.com"
100
+ subject.default_rhlogin.should == "global@redhat.com"
101
+ subject['random_value'].should == "12"
102
+ subject['non_value'].should be_nil
62
103
 
63
104
  end
64
105
 
65
106
  it "should have libra_server fallback to the default if not set in config" do
66
107
  ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
67
108
  "global@redhat.com")
68
- RHC::Config.initialize
109
+ subject.initialize
69
110
 
70
- RHC::Config['libra_server'].should == "openshift.redhat.com"
71
- RHC::Config.default_rhlogin.should == "global@redhat.com"
111
+ subject['libra_server'].should == "openshift.redhat.com"
112
+ subject.default_rhlogin.should == "global@redhat.com"
72
113
  end
73
114
  end
74
115
 
75
- context "Config values with ~/.openshift/express.conf" do
76
- it "should have global and local config" do
77
- ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
78
- "global@redhat.com")
79
- ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
80
- "local.openshift.redhat.com","local@redhat.com")
81
- RHC::Config.initialize
82
- RHC::Config.home_dir = ConfigHelper.home_dir
83
-
84
- RHC::Config.home_conf_path.should == File.join(ConfigHelper.home_dir, '.openshift')
85
- RHC::Config.local_config_path.should == File.join(ConfigHelper.home_dir, '.openshift', 'express.conf')
86
- RHC::Config.has_global_config?.should be_true
87
- RHC::Config.has_local_config?.should be_true
88
- RHC::Config.has_opts_config?.should be_false
89
- end
116
+ context "With a mock home dir" do
90
117
 
91
- it "should get values from local config" do
92
- ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
93
- "global@redhat.com",
94
- {"random_value" => "12"})
95
- ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
96
- "local.openshift.redhat.com",
97
- "local@redhat.com",
98
- {"random_value" => 11})
99
- RHC::Config.initialize
100
- RHC::Config.home_dir = ConfigHelper.home_dir
101
-
102
- RHC::Config['libra_server'].should == "local.openshift.redhat.com"
103
- RHC::Config.default_rhlogin.should == "local@redhat.com"
104
- RHC::Config['random_value'].should == "11"
105
- RHC::Config['non_value'].should be_nil
118
+ def stub_config
119
+ config = RHC::Config.new
120
+ RHC::Config.instance_variable_set(:@default, config)
121
+ config.stub(:home_dir).and_return(ConfigHelper.home_dir)
122
+ RHC::Config.stub(:new).and_return(config)
123
+ RHC::Config.default.should == config
124
+ config.read_config_files
106
125
  end
107
126
 
108
- it "should fallback to the default or global if not set in config" do
109
- ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
110
- "global@redhat.com")
111
- ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
112
- nil,
113
- nil,
114
- {"random_value" => 11})
115
- RHC::Config.initialize
116
- RHC::Config.home_dir = ConfigHelper.home_dir
117
-
118
- RHC::Config['libra_server'].should == "openshift.redhat.com"
119
- RHC::Config.default_rhlogin.should == "global@redhat.com"
120
- RHC::Config['random_value'].should == "11"
121
- end
127
+ context "Config values with ~/.openshift/express.conf" do
128
+ it "should have global and local config" do
129
+ ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
130
+ "global@redhat.com")
131
+ ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
132
+ "local.openshift.redhat.com","local@redhat.com")
133
+ stub_config
134
+
135
+ subject.home_conf_path.should == File.join(ConfigHelper.home_dir, '.openshift')
136
+ subject.local_config_path.should == File.join(ConfigHelper.home_dir, '.openshift', 'express.conf')
137
+ subject.has_global_config?.should be_true
138
+ subject.has_local_config?.should be_true
139
+ subject.has_opts_config?.should be_false
140
+ end
122
141
 
123
- end
142
+ it "should get values from local config" do
143
+ ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
144
+ "global@redhat.com",
145
+ {"random_value" => "12"})
146
+ ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
147
+ "local.openshift.redhat.com",
148
+ "local@redhat.com",
149
+ {"random_value" => 11})
150
+ stub_config
151
+
152
+ subject['libra_server'].should == "local.openshift.redhat.com"
153
+ subject.default_rhlogin.should == "local@redhat.com"
154
+ subject['random_value'].should == "11"
155
+ subject['non_value'].should be_nil
156
+ end
124
157
 
125
- context "Config values with LIBRA_SERVER ENV set" do
126
- it "should get values from local config" do
127
- ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
128
- "global@redhat.com",
129
- {"random_value" => "12"})
130
- ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
131
- "local.openshift.redhat.com",
132
- "local@redhat.com",
133
- {"random_value" => 11})
134
- ENV['LIBRA_SERVER'] = "env.openshift.redhat.com"
135
- RHC::Config.initialize
136
- RHC::Config.set_local_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'))
137
-
138
- RHC::Config['libra_server'].should == "env.openshift.redhat.com"
139
- RHC::Config.default_rhlogin.should == "local@redhat.com"
140
- RHC::Config['random_value'].should == "11"
141
- RHC::Config['non_value'].should be_nil
158
+ it "should fallback to the default or global if not set in config" do
159
+ ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
160
+ "global@redhat.com")
161
+ ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
162
+ nil,
163
+ nil,
164
+ {"random_value" => 11})
165
+ stub_config
166
+
167
+ subject['libra_server'].should == "openshift.redhat.com"
168
+ subject.default_rhlogin.should == "global@redhat.com"
169
+ subject['random_value'].should == "11"
170
+ end
142
171
  end
143
- end
144
172
 
145
- context "Config values with options set" do
146
- it "should have global and local config" do
147
- ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
148
- "global@redhat.com")
149
- ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
150
- "local.openshift.redhat.com","local@redhat.com")
151
- ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
152
- "opts.openshift.redhat.com",
153
- "opts@redhat.com")
154
- RHC::Config.initialize
155
- RHC::Config.home_dir = ConfigHelper.home_dir
156
- RHC::Config.check_cpath({"config" => ConfigHelper.opts_config_path,
157
- "random_val" => "ok"})
158
-
159
- RHC::Config.has_global_config?.should be_true
160
- RHC::Config.has_local_config?.should be_true
161
- RHC::Config.has_opts_config?.should be_true
173
+ context "Config values with LIBRA_SERVER ENV set" do
174
+ it "should get values from local config" do
175
+ ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
176
+ "global@redhat.com",
177
+ {"random_value" => "12"})
178
+ ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
179
+ "local.openshift.redhat.com",
180
+ "local@redhat.com",
181
+ {"random_value" => 11})
182
+ ENV['LIBRA_SERVER'] = "env.openshift.redhat.com"
183
+
184
+ stub_config
185
+ subject.set_local_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'))
186
+
187
+ subject['libra_server'].should == "env.openshift.redhat.com"
188
+ subject.default_rhlogin.should == "local@redhat.com"
189
+ subject['random_value'].should == "11"
190
+ subject['non_value'].should be_nil
191
+ end
162
192
  end
163
193
 
164
- it "should get values from local config" do
165
- ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
166
- "global@redhat.com",
167
- {"random_value" => "12"})
168
- ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
169
- "local.openshift.redhat.com",
170
- "local@redhat.com",
171
- {"random_value" => 11})
172
- ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
173
- "opts.openshift.redhat.com",
174
- "opts@redhat.com",
175
- {"random_value" => 10})
176
- RHC::Config.initialize
177
- RHC::Config.home_dir = ConfigHelper.home_dir
178
- RHC::Config.check_cpath({"config" => ConfigHelper.opts_config_path,
179
- "random_val" => "ok"})
180
-
181
- RHC::Config['libra_server'].should == "opts.openshift.redhat.com"
182
- RHC::Config.default_rhlogin.should == "opts@redhat.com"
183
- RHC::Config['random_value'].should == "10"
184
- RHC::Config['non_value'].should be_nil
185
- end
194
+ context "Config values with options set" do
195
+ it "should have global and local config" do
196
+ ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
197
+ "global@redhat.com")
198
+ ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
199
+ "local.openshift.redhat.com","local@redhat.com")
200
+ ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
201
+ "opts.openshift.redhat.com",
202
+ "opts@redhat.com")
203
+ stub_config
204
+ subject.check_cpath({"config" => ConfigHelper.opts_config_path,
205
+ "random_val" => "ok"})
206
+
207
+ subject.has_global_config?.should be_true
208
+ subject.has_local_config?.should be_true
209
+ subject.has_opts_config?.should be_true
210
+ end
186
211
 
187
- it "should fallback to the default or global or local if not set in config" do
188
- ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
189
- "global@redhat.com")
190
- ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
191
- nil,
192
- nil,
193
- {"random_value" => 11,
194
- "local_value" => "local"})
195
- ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
196
- nil,
197
- nil,
198
- {"random_value" => 10})
199
- RHC::Config.initialize
200
- RHC::Config.home_dir = ConfigHelper.home_dir
201
- RHC::Config.check_cpath({"config" => ConfigHelper.opts_config_path,
202
- "random_val" => "ok"})
203
-
204
- RHC::Config['libra_server'].should == "openshift.redhat.com"
205
- RHC::Config.default_rhlogin.should == "global@redhat.com"
206
- RHC::Config['random_value'].should == "10"
207
- RHC::Config['local_value'].should == "local"
212
+ it "should get values from local config" do
213
+ ConfigHelper.write_out_config(ConfigHelper.global_config_path, "global.openshift.redhat.com",
214
+ "global@redhat.com",
215
+ {"random_value" => "12"})
216
+ ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
217
+ "local.openshift.redhat.com",
218
+ "local@redhat.com",
219
+ {"random_value" => 11})
220
+ ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
221
+ "opts.openshift.redhat.com",
222
+ "opts@redhat.com",
223
+ {"random_value" => 10})
224
+ stub_config
225
+ subject.check_cpath({"config" => ConfigHelper.opts_config_path,
226
+ "random_val" => "ok"})
227
+
228
+ subject['libra_server'].should == "opts.openshift.redhat.com"
229
+ subject.default_rhlogin.should == "opts@redhat.com"
230
+ subject['random_value'].should == "10"
231
+ subject['non_value'].should be_nil
232
+ end
233
+
234
+ it "should fallback to the default or global or local if not set in config" do
235
+ ConfigHelper.write_out_config(ConfigHelper.global_config_path, nil,
236
+ "global@redhat.com")
237
+ ConfigHelper.write_out_config(File.join(ConfigHelper.home_dir,'.openshift', 'express.conf'),
238
+ nil,
239
+ nil,
240
+ {"random_value" => 11,
241
+ "local_value" => "local"})
242
+ ConfigHelper.write_out_config(ConfigHelper.opts_config_path,
243
+ nil,
244
+ nil,
245
+ {"random_value" => 10})
246
+ stub_config
247
+ subject.check_cpath({"config" => ConfigHelper.opts_config_path,
248
+ "random_val" => "ok"})
249
+
250
+ subject['libra_server'].should == "openshift.redhat.com"
251
+ subject.default_rhlogin.should == "global@redhat.com"
252
+ subject['random_value'].should == "10"
253
+ subject['local_value'].should == "local"
254
+ end
208
255
  end
209
256
  end
210
257
 
@@ -222,7 +269,7 @@ describe RHC::Config do
222
269
  nil,
223
270
  nil,
224
271
  {"debug" => "true"})
225
- RHC::Config.initialize
272
+ subject.initialize
226
273
  ConfigHelper.check_legacy_debug({}).should == "true"
227
274
  end
228
275
 
@@ -231,7 +278,7 @@ describe RHC::Config do
231
278
  nil,
232
279
  nil,
233
280
  {"debug" => "false"})
234
- RHC::Config.initialize
281
+ subject.initialize
235
282
  ConfigHelper.check_legacy_debug({}).should be_false
236
283
  end
237
284
 
@@ -240,7 +287,7 @@ describe RHC::Config do
240
287
  nil,
241
288
  nil,
242
289
  {"debug" => "true"})
243
- RHC::Config.initialize
290
+ subject.initialize
244
291
  ConfigHelper.check_legacy_debug({"debug" => false}).should be_true
245
292
  end
246
293
 
@@ -249,21 +296,21 @@ describe RHC::Config do
249
296
  nil,
250
297
  nil,
251
298
  {"debug" => "false"})
252
- RHC::Config.initialize
299
+ subject.initialize
253
300
  ConfigHelper.check_legacy_debug({"debug" => true}).should be_true
254
301
  end
255
302
  end
256
303
 
257
304
  context "Proxy ENV variable parsing" do
258
305
  before do
259
- RHC::Config.initialize
306
+ subject.initialize
260
307
  ['http_proxy','HTTP_PROXY'].each do |var|
261
308
  ENV[var] = nil
262
309
  end
263
310
  end
264
311
 
265
312
  it "should return a direct http connection" do
266
- RHC::Config.using_proxy?.should_not == true
313
+ subject.using_proxy?.should_not == true
267
314
  end
268
315
 
269
316
  ['http_proxy','HTTP_PROXY'].each do |var|
@@ -272,12 +319,12 @@ describe RHC::Config do
272
319
  # returns a generic class so we check to make sure it is not a
273
320
  # Net::HTTP class and rely on simplecov to make sure the proxy
274
321
  # code path was run
275
- RHC::Config.using_proxy?.should == true
322
+ subject.using_proxy?.should == true
276
323
  end
277
324
  end
278
325
 
279
326
  context "it should have the correct values" do
280
- let(:vars){ RHC::Config.proxy_vars }
327
+ let(:vars){ subject.proxy_vars }
281
328
  before do
282
329
  ENV['http_proxy'] = "my_user:my_pass@fakeproxy.foo:8080"
283
330
  end
@@ -300,20 +347,20 @@ describe RHC::Config do
300
347
  ConfigHelper.write_out_config(ConfigHelper.global_config_path,
301
348
  "global.openshift.redhat.com",
302
349
  "global@redhat.com")
303
- RHC::Config.initialize
350
+ subject.initialize
304
351
  RHC::Vendor::ParseConfig.stub(:new) { raise Errno::EACCES.new("Fake can't read file") }
305
- RHC::Config.stub(:exit) { |code| code }
352
+ subject.stub(:exit) { |code| code }
306
353
 
307
- expect { RHC::Config.check_cpath({"config" => "fake.conf"}) }.to raise_error(Errno::EACCES)
354
+ expect { subject.check_cpath({"config" => "fake.conf"}) }.to raise_error(Errno::EACCES)
308
355
 
309
356
  # write out config file so it exists but is not readable
310
357
  ConfigHelper.write_out_config("fake.conf",
311
358
  "global.openshift.redhat.com",
312
359
  "global@redhat.com")
313
360
 
314
- expect { RHC::Config.read_config_files }.to raise_error(Errno::EACCES)
315
- expect { RHC::Config.set_local_config("fake.conf") }.to raise_error(Errno::EACCES)
316
- expect { RHC::Config.set_opts_config("fake.conf") }.to raise_error(Errno::EACCES)
361
+ expect { subject.read_config_files }.to raise_error(Errno::EACCES)
362
+ expect { subject.set_local_config("fake.conf") }.to raise_error(Errno::EACCES)
363
+ expect { subject.set_opts_config("fake.conf") }.to raise_error(Errno::EACCES)
317
364
  end
318
365
  end
319
366
  end
@@ -338,7 +385,7 @@ class ConfigHelper
338
385
  def self.check_legacy_debug(opts)
339
386
  # this simulates how the old rhc code checked for debug
340
387
  # in the future this should all be filtered through the Config module
341
- # and an app should just have to use RHC::Config.debug?
388
+ # and an app should just have to use subject.debug?
342
389
  debug = RHC::Config['debug'] == 'false' ? nil : RHC::Config['debug']
343
390
  debug = true if opts.has_key? 'debug'
344
391
  debug