rhc 1.2.7 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rhc +6 -8
- data/bin/rhc-chk +23 -10
- data/features/domain.feature +1 -1
- data/features/lib/rhc_helper.rb +3 -2
- data/features/lib/rhc_helper/api.rb +7 -0
- data/features/lib/rhc_helper/app.rb +8 -10
- data/features/lib/rhc_helper/domain.rb +2 -1
- data/features/lib/rhc_helper/runnable.rb +2 -24
- data/features/sshkey.feature +3 -3
- data/features/step_definitions/cartridge_steps.rb +6 -6
- data/features/step_definitions/client_steps.rb +0 -1
- data/features/step_definitions/sshkey_steps.rb +2 -2
- data/features/support/before_hooks.rb +0 -1
- data/features/support/env.rb +5 -3
- data/lib/rhc-common.rb +1 -1
- data/lib/rhc.rb +9 -8
- data/lib/rhc/auth.rb +3 -0
- data/lib/rhc/auth/basic.rb +54 -0
- data/lib/rhc/cartridge_helpers.rb +11 -5
- data/lib/rhc/cli.rb +4 -2
- data/lib/rhc/command_runner.rb +35 -30
- data/lib/rhc/commands.rb +127 -18
- data/lib/rhc/commands/account.rb +24 -0
- data/lib/rhc/commands/alias.rb +1 -1
- data/lib/rhc/commands/app.rb +210 -209
- data/lib/rhc/commands/apps.rb +22 -0
- data/lib/rhc/commands/base.rb +10 -77
- data/lib/rhc/commands/cartridge.rb +35 -35
- data/lib/rhc/commands/domain.rb +20 -13
- data/lib/rhc/commands/git_clone.rb +30 -0
- data/lib/rhc/commands/{port-forward.rb → port_forward.rb} +3 -3
- data/lib/rhc/commands/server.rb +28 -16
- data/lib/rhc/commands/setup.rb +18 -1
- data/lib/rhc/commands/snapshot.rb +4 -4
- data/lib/rhc/commands/sshkey.rb +4 -18
- data/lib/rhc/commands/tail.rb +32 -9
- data/lib/rhc/config.rb +168 -99
- data/lib/rhc/context_helper.rb +22 -9
- data/lib/rhc/core_ext.rb +41 -1
- data/lib/rhc/exceptions.rb +21 -5
- data/lib/rhc/git_helpers.rb +81 -0
- data/lib/rhc/help_formatter.rb +21 -1
- data/lib/rhc/helpers.rb +222 -87
- data/lib/rhc/output_helpers.rb +94 -110
- data/lib/rhc/rest.rb +15 -198
- data/lib/rhc/rest/api.rb +88 -0
- data/lib/rhc/rest/application.rb +29 -30
- data/lib/rhc/rest/attributes.rb +27 -0
- data/lib/rhc/rest/base.rb +29 -33
- data/lib/rhc/rest/cartridge.rb +42 -20
- data/lib/rhc/rest/client.rb +351 -89
- data/lib/rhc/rest/domain.rb +7 -13
- data/lib/rhc/rest/gear_group.rb +1 -1
- data/lib/rhc/rest/key.rb +7 -2
- data/lib/rhc/rest/mock.rb +609 -0
- data/lib/rhc/rest/user.rb +6 -2
- data/lib/rhc/{ssh_key_helpers.rb → ssh_helpers.rb} +58 -28
- data/lib/rhc/{targz.rb → tar_gz.rb} +0 -0
- data/lib/rhc/usage_templates/command_help.erb +4 -1
- data/lib/rhc/usage_templates/help.erb +24 -11
- data/lib/rhc/usage_templates/options_help.erb +14 -0
- data/lib/rhc/wizard.rb +283 -213
- data/spec/keys/example.pem +23 -0
- data/spec/keys/example_private.pem +27 -0
- data/spec/keys/server.pem +19 -0
- data/spec/rest_spec_helper.rb +3 -371
- data/spec/rhc/auth_spec.rb +226 -0
- data/spec/rhc/cli_spec.rb +41 -14
- data/spec/rhc/command_spec.rb +44 -15
- data/spec/rhc/commands/account_spec.rb +41 -0
- data/spec/rhc/commands/alias_spec.rb +16 -15
- data/spec/rhc/commands/app_spec.rb +115 -92
- data/spec/rhc/commands/apps_spec.rb +39 -0
- data/spec/rhc/commands/cartridge_spec.rb +134 -112
- data/spec/rhc/commands/domain_spec.rb +31 -86
- data/spec/rhc/commands/git_clone_spec.rb +56 -0
- data/spec/rhc/commands/{port-forward_spec.rb → port_forward_spec.rb} +27 -32
- data/spec/rhc/commands/server_spec.rb +28 -3
- data/spec/rhc/commands/setup_spec.rb +29 -11
- data/spec/rhc/commands/snapshot_spec.rb +4 -3
- data/spec/rhc/commands/sshkey_spec.rb +24 -56
- data/spec/rhc/commands/tail_spec.rb +26 -9
- data/spec/rhc/commands/threaddump_spec.rb +12 -11
- data/spec/rhc/config_spec.rb +211 -164
- data/spec/rhc/context_spec.rb +2 -0
- data/spec/rhc/helpers_spec.rb +242 -46
- data/spec/rhc/rest_application_spec.rb +42 -28
- data/spec/rhc/rest_client_spec.rb +110 -93
- data/spec/rhc/rest_spec.rb +220 -131
- data/spec/rhc/targz_spec.rb +1 -1
- data/spec/rhc/wizard_spec.rb +435 -624
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +140 -6
- data/spec/wizard_spec_helper.rb +326 -0
- metadata +163 -143
- data/lib/rhc/client.rb +0 -17
- data/lib/rhc/git_helper.rb +0 -59
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhc/commands'
|
3
|
+
|
4
|
+
describe RHC::Auth::Basic do
|
5
|
+
let(:user){ 'test_user' }
|
6
|
+
let(:password){ 'test pass' }
|
7
|
+
let(:auth_hash){ {:user => user, :password => password} }
|
8
|
+
let(:options){ (o = Commander::Command::Options.new).default(default_options); o }
|
9
|
+
let(:default_options){ {} }
|
10
|
+
|
11
|
+
its(:username){ should be_nil }
|
12
|
+
its(:username?){ should be_false }
|
13
|
+
its(:password){ should be_nil }
|
14
|
+
its(:options){ should be_nil }
|
15
|
+
its(:openshift_server){ should == 'openshift.redhat.com' }
|
16
|
+
|
17
|
+
context "with user options" do
|
18
|
+
subject{ described_class.new(options) }
|
19
|
+
|
20
|
+
its(:username){ should be_nil }
|
21
|
+
its(:username?){ should be_false }
|
22
|
+
its(:password){ should be_nil }
|
23
|
+
its(:options){ should equal(options) }
|
24
|
+
|
25
|
+
context "that include user info" do
|
26
|
+
let(:default_options){ {:rhlogin => user, :password => password} }
|
27
|
+
|
28
|
+
its(:username){ should == user }
|
29
|
+
its(:username?){ should be_true }
|
30
|
+
its(:password){ should == password }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "that includes server" do
|
34
|
+
let(:default_options){ {:server => 'test.com'} }
|
35
|
+
|
36
|
+
its(:openshift_server){ should == 'test.com' }
|
37
|
+
it do
|
38
|
+
subject.should_receive(:ask).with("Login to test.com: ").and_return(user)
|
39
|
+
subject.send(:ask_username).should == user
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with --noprompt" do
|
44
|
+
let(:default_options){ {:noprompt => true} }
|
45
|
+
|
46
|
+
its(:ask_username){ should be_false }
|
47
|
+
its(:ask_password){ should be_false }
|
48
|
+
its(:username?){ should be_false }
|
49
|
+
it("should not retry") do
|
50
|
+
subject.should_not_receive(:ask_username)
|
51
|
+
subject.retry_auth?(mock(:status => 401)).should be_false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when initialized with a hash" do
|
57
|
+
subject{ described_class.new({:rhlogin => user, :password => password}) }
|
58
|
+
its(:username){ should == user }
|
59
|
+
its(:password){ should == password }
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
describe "#ask_username" do
|
64
|
+
before{ subject.should_receive(:openshift_server).and_return('test.com') }
|
65
|
+
before{ subject.should_receive(:ask).with("Login to test.com: ").and_return(user) }
|
66
|
+
|
67
|
+
it do
|
68
|
+
subject.send(:ask_username).should == user
|
69
|
+
subject.send(:username).should == user
|
70
|
+
end
|
71
|
+
|
72
|
+
context "with a different user" do
|
73
|
+
subject{ described_class.new('other', nil) }
|
74
|
+
it do
|
75
|
+
subject.send(:ask_username).should == user
|
76
|
+
subject.send(:username).should == user
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#ask_password" do
|
82
|
+
before{ subject.should_receive(:ask).with("Password: ").and_return(password) }
|
83
|
+
it do
|
84
|
+
subject.send(:ask_password).should == password
|
85
|
+
subject.send(:password).should == password
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with a different password" do
|
89
|
+
subject{ described_class.new(user, 'other') }
|
90
|
+
it do
|
91
|
+
subject.send(:ask_password).should == password
|
92
|
+
subject.send(:password).should == password
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#to_request" do
|
98
|
+
let(:request){ {} }
|
99
|
+
|
100
|
+
context "when the request is lazy" do
|
101
|
+
let(:request){ {:lazy_auth => true} }
|
102
|
+
before{ subject.should_receive(:ask_username).never }
|
103
|
+
before{ subject.should_receive(:ask_password).never }
|
104
|
+
|
105
|
+
it { subject.to_request(request).should == request }
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when password and user are provided" do
|
109
|
+
subject{ described_class.new(user, password) }
|
110
|
+
|
111
|
+
it { subject.to_request(request).should equal(request) }
|
112
|
+
it { subject.to_request(request).should == auth_hash }
|
113
|
+
|
114
|
+
context "it should remember cookies" do
|
115
|
+
let(:response){ mock(:cookies => [mock(:name => 'rh_sso', :value => '1')], :status => 200) }
|
116
|
+
it{ subject.retry_auth?(response); subject.to_request(request)[:cookies].should == {:rh_sso => '1'} }
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when the request is lazy" do
|
120
|
+
let(:request){ {:lazy_auth => true} }
|
121
|
+
|
122
|
+
it { subject.to_request(request).should == auth_hash.merge(request) }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "when password is not provided" do
|
127
|
+
subject{ described_class.new(user, nil) }
|
128
|
+
|
129
|
+
its(:password){ should be_nil }
|
130
|
+
it "should ask for the password" do
|
131
|
+
subject.should_receive(:ask_password).and_return(password)
|
132
|
+
subject.to_request(request).should == auth_hash
|
133
|
+
end
|
134
|
+
it "should remember the password" do
|
135
|
+
subject.should_receive(:ask_password).and_return(password)
|
136
|
+
subject.to_request(request)
|
137
|
+
subject.to_request(request).should == auth_hash
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when the request is lazy" do
|
141
|
+
let(:request){ {:lazy_auth => true} }
|
142
|
+
before{ subject.should_receive(:ask_password).never }
|
143
|
+
|
144
|
+
it { subject.to_request(request).should == auth_hash.merge(request) }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when user is not provided" do
|
149
|
+
subject{ described_class.new(nil, password) }
|
150
|
+
|
151
|
+
its(:username){ should be_nil }
|
152
|
+
it "should ask for the username" do
|
153
|
+
subject.should_receive(:ask_username).and_return(user)
|
154
|
+
subject.to_request(request).should == auth_hash
|
155
|
+
end
|
156
|
+
it "should remember the username" do
|
157
|
+
subject.should_receive(:ask_username).and_return(user)
|
158
|
+
subject.to_request(request)
|
159
|
+
subject.to_request(request).should == auth_hash
|
160
|
+
end
|
161
|
+
|
162
|
+
context "when the request is lazy" do
|
163
|
+
let(:request){ {:lazy_auth => true} }
|
164
|
+
before{ subject.should_receive(:ask_username).never }
|
165
|
+
|
166
|
+
it { subject.to_request(request).should == auth_hash.merge(request) }
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "#retry_auth?" do
|
172
|
+
context "when the response succeeds" do
|
173
|
+
let(:response){ mock(:cookies => {}, :status => 200) }
|
174
|
+
|
175
|
+
it{ subject.retry_auth?(response).should be_false }
|
176
|
+
after{ subject.cookie.should be_nil }
|
177
|
+
end
|
178
|
+
context "when the response succeeds with a cookie" do
|
179
|
+
let(:response){ mock(:cookies => [mock(:name => 'rh_sso', :value => '1')], :status => 200) }
|
180
|
+
it{ subject.retry_auth?(response).should be_false }
|
181
|
+
after{ subject.cookie.should == '1' }
|
182
|
+
end
|
183
|
+
context "when the response requires authentication" do
|
184
|
+
let(:response){ mock(:status => 401) }
|
185
|
+
after{ subject.cookie.should be_nil }
|
186
|
+
|
187
|
+
context "with no user and no password" do
|
188
|
+
subject{ described_class.new(nil, nil) }
|
189
|
+
it("should ask for user and password") do
|
190
|
+
subject.should_receive(:ask_username).and_return(user)
|
191
|
+
subject.should_receive(:ask_password).and_return(password)
|
192
|
+
subject.retry_auth?(response).should be_true
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "with user and no password" do
|
197
|
+
subject{ described_class.new(user, nil) }
|
198
|
+
it("should ask for password only") do
|
199
|
+
subject.should_receive(:ask_password).and_return(password)
|
200
|
+
subject.retry_auth?(response).should be_true
|
201
|
+
end
|
202
|
+
it("should ask for password twice") do
|
203
|
+
subject.should_receive(:ask_password).twice.and_return(password)
|
204
|
+
subject.retry_auth?(response).should be_true
|
205
|
+
subject.retry_auth?(response).should be_true
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "with user and password" do
|
210
|
+
subject{ described_class.new(user, password) }
|
211
|
+
it("should not prompt for reauthentication") do
|
212
|
+
subject.should_not_receive(:ask_password)
|
213
|
+
subject.should_receive(:error).with("Username or password is not correct")
|
214
|
+
subject.retry_auth?(response).should be_false
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should forget a saved cookie" do
|
218
|
+
subject.instance_variable_set(:@cookie, '1')
|
219
|
+
subject.should_not_receive(:ask_password)
|
220
|
+
subject.should_receive(:error).with("Username or password is not correct")
|
221
|
+
subject.retry_auth?(response).should be_false
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
data/spec/rhc/cli_spec.rb
CHANGED
@@ -2,6 +2,15 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe RHC::CLI do
|
4
4
|
|
5
|
+
shared_examples_for 'a global help page' do
|
6
|
+
let(:arguments) { @arguments or raise "no arguments" }
|
7
|
+
it('should contain the program description') { run_output.should =~ /Command line interface for OpenShift/ }
|
8
|
+
it('should describe getting started') { run_output.should =~ /Getting started:/ }
|
9
|
+
it('should describe basic command') { run_output.should =~ /Working with apps:/ }
|
10
|
+
it('should mention the help command') { run_output.should =~ /See 'rhc help <command>'/ }
|
11
|
+
it('should mention the help options command') { run_output.should =~ /rhc help options/ }
|
12
|
+
end
|
13
|
+
|
5
14
|
shared_examples_for 'a help page' do
|
6
15
|
let(:arguments) { @arguments or raise "no arguments" }
|
7
16
|
it('should contain the program description') { run_output.should =~ /Command line interface for OpenShift/ }
|
@@ -9,20 +18,30 @@ describe RHC::CLI do
|
|
9
18
|
it('should provide a --config switch') { run_output.should =~ /\-\-config FILE/ }
|
10
19
|
end
|
11
20
|
|
21
|
+
shared_examples_for 'a command-line options help page' do
|
22
|
+
let(:arguments) { @arguments or raise "no arguments" }
|
23
|
+
it('should contain an introduction') { run_output.should =~ /The following options can be passed to any/ }
|
24
|
+
it('should reference the configuration') { run_output.should match(".openshift/express.conf") }
|
25
|
+
it('should describe the --config switch') { run_output.should =~ /\-\-config FILE/ }
|
26
|
+
it('should describe the --ssl-version switch') { run_output.should =~ /\-\-ssl\-version VERSION/ }
|
27
|
+
end
|
28
|
+
|
12
29
|
shared_examples_for 'an invalid command' do
|
13
30
|
let(:arguments) { @arguments }
|
14
31
|
it('should contain the invalid command message') { run_output.should =~ /is not recognized/ }
|
15
32
|
it('should contain the arguments') { run_output.should include(@arguments[0]) }
|
16
33
|
it('should reference --help') { run_output.should =~ / help\b/ }
|
17
34
|
end
|
18
|
-
|
35
|
+
|
19
36
|
shared_examples_for 'version output' do
|
20
37
|
let(:arguments) { @arguments }
|
21
38
|
it 'should contain version output' do
|
22
39
|
run_output.should =~ /rhc \d+\.\d+(:?\.d+)?/
|
23
40
|
end
|
24
41
|
end
|
25
|
-
|
42
|
+
|
43
|
+
before{ base_config }
|
44
|
+
|
26
45
|
describe "--version" do
|
27
46
|
context "by itself" do
|
28
47
|
before :each do
|
@@ -30,19 +49,17 @@ describe RHC::CLI do
|
|
30
49
|
end
|
31
50
|
it_should_behave_like 'version output'
|
32
51
|
end
|
33
|
-
|
34
|
-
context 'given as "-v"' do
|
35
|
-
before :each do
|
36
|
-
@arguments = ['-v']
|
37
|
-
end
|
38
|
-
it_should_behave_like 'version output'
|
39
|
-
end
|
40
52
|
end
|
41
53
|
|
42
54
|
describe '#start' do
|
43
55
|
context 'with no arguments' do
|
44
56
|
before(:each) { @arguments = [] }
|
45
|
-
it_should_behave_like 'a help page'
|
57
|
+
it_should_behave_like 'a global help page'
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with an ambiguous option' do
|
61
|
+
let(:arguments){ ['help', '-s'] }
|
62
|
+
it('should describe an ambiguous error'){ run_output.should match("The option -s is ambiguous. You will need to specify the entire option.") }
|
46
63
|
end
|
47
64
|
|
48
65
|
context 'with an invalid command' do
|
@@ -62,27 +79,37 @@ describe RHC::CLI do
|
|
62
79
|
|
63
80
|
context 'with --help' do
|
64
81
|
before(:each){ @arguments = ['--help'] }
|
65
|
-
it_should_behave_like 'a help page'
|
82
|
+
it_should_behave_like 'a global help page'
|
66
83
|
end
|
67
84
|
|
68
85
|
context 'with -h' do
|
69
86
|
before(:each){ @arguments = ['-h'] }
|
70
|
-
it_should_behave_like 'a help page'
|
87
|
+
it_should_behave_like 'a global help page'
|
71
88
|
end
|
72
89
|
|
73
90
|
context 'with help' do
|
74
91
|
before(:each){ @arguments = ['help'] }
|
75
|
-
it_should_behave_like 'a help page'
|
92
|
+
it_should_behave_like 'a global help page'
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'with help options' do
|
96
|
+
before(:each){ @arguments = ['help', 'options'] }
|
97
|
+
it_should_behave_like 'a command-line options help page'
|
76
98
|
end
|
77
99
|
end
|
78
100
|
|
79
101
|
describe '#set_terminal' do
|
80
102
|
before(:each) { mock_terminal }
|
81
103
|
it('should update $terminal.wrap_at') do
|
82
|
-
$stdin.should_receive(:tty?).and_return(true)
|
104
|
+
$stdin.should_receive(:tty?).twice.and_return(true)
|
83
105
|
HighLine::SystemExtensions.should_receive(:terminal_size).and_return([5])
|
84
106
|
expect { RHC::CLI.set_terminal }.to change($terminal, :wrap_at)
|
85
107
|
end
|
108
|
+
it('should update $terminal.page_at') do
|
109
|
+
$stdin.should_receive(:tty?).twice.and_return(true)
|
110
|
+
$stdout.should_receive(:tty?).twice.and_return(true)
|
111
|
+
expect { RHC::CLI.set_terminal }.to change($terminal, :page_at)
|
112
|
+
end
|
86
113
|
end
|
87
114
|
|
88
115
|
end
|
data/spec/rhc/command_spec.rb
CHANGED
@@ -3,6 +3,9 @@ require 'rhc/commands/base'
|
|
3
3
|
require 'rhc/exceptions'
|
4
4
|
|
5
5
|
describe RHC::Commands::Base do
|
6
|
+
|
7
|
+
before{ base_config }
|
8
|
+
|
6
9
|
describe '#object_name' do
|
7
10
|
subject { described_class }
|
8
11
|
its(:object_name) { should == 'base' }
|
@@ -45,7 +48,6 @@ describe RHC::Commands::Base do
|
|
45
48
|
it("should have an object name") { subject.object_name.should == 'test' }
|
46
49
|
it("should run with wizard") do
|
47
50
|
FakeFS do
|
48
|
-
RHC::Config.set_defaults
|
49
51
|
wizard_run = false
|
50
52
|
RHC::Wizard.stub!(:new) do |config|
|
51
53
|
RHC::Wizard.unstub!(:new)
|
@@ -80,6 +82,22 @@ describe RHC::Commands::Base do
|
|
80
82
|
it("invokes the right method") { expects_running('static').should call(:run).on(instance).with(no_args) }
|
81
83
|
end
|
82
84
|
|
85
|
+
context 'when a command calls exit' do
|
86
|
+
subject do
|
87
|
+
Kernel.module_eval do
|
88
|
+
class Failing < RHC::Commands::Base
|
89
|
+
def run
|
90
|
+
exit 2
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
Failing
|
95
|
+
end
|
96
|
+
|
97
|
+
it("invokes the right method") { expects_running('failing').should call(:run).on(instance).with(no_args) }
|
98
|
+
it{ expects_running('failing').should exit_with_code(2) }
|
99
|
+
end
|
100
|
+
|
83
101
|
context 'when statically defined with no default method' do
|
84
102
|
subject do
|
85
103
|
Kernel.module_eval do
|
@@ -93,7 +111,7 @@ describe RHC::Commands::Base do
|
|
93
111
|
alias_action :exe, :deprecated => true
|
94
112
|
def execute(testarg); 1; end
|
95
113
|
|
96
|
-
argument :args, "Test arg list", [], :arg_type => :list
|
114
|
+
argument :args, "Test arg list", ['--tests'], :arg_type => :list
|
97
115
|
summary "Test command execute-list"
|
98
116
|
def execute_list(args); 1; end
|
99
117
|
|
@@ -125,6 +143,10 @@ describe RHC::Commands::Base do
|
|
125
143
|
it { expects_running('statis', 'execute', 'duparg', '--testarg', 'duparg2').should exit_with_code(1) }
|
126
144
|
end
|
127
145
|
|
146
|
+
context 'and when the provided option is ambiguous' do
|
147
|
+
it { expects_running('static', 'execute', '-t', '--trace').should raise_error(OptionParser::AmbiguousOption) }
|
148
|
+
end
|
149
|
+
|
128
150
|
context 'and when execute is called with too many arguments' do
|
129
151
|
it { expects_running('static', 'execute', 'arg1', 'arg2').should exit_with_code(1) }
|
130
152
|
end
|
@@ -136,6 +158,8 @@ describe RHC::Commands::Base do
|
|
136
158
|
context 'and when execute_list is called' do
|
137
159
|
it { expects_running('static', 'execute-list', '--trace').should call(:execute_list).on(instance).with([]) }
|
138
160
|
it { expects_running('static', 'execute-list', '1', '2', '3').should call(:execute_list).on(instance).with(['1', '2', '3']) }
|
161
|
+
it { expects_running('static', 'execute-list', '1', '2', '3').should call(:execute_list).on(instance).with(['1', '2', '3']) }
|
162
|
+
it('should make the option available') { command_for('static', 'execute-list', '1', '2', '3').send(:options).tests.should == ['1','2','3'] }
|
139
163
|
end
|
140
164
|
|
141
165
|
context 'and when an error is raised in a call' do
|
@@ -166,20 +190,25 @@ describe RHC::Commands::Base do
|
|
166
190
|
end
|
167
191
|
|
168
192
|
describe "rest_client" do
|
169
|
-
|
170
|
-
|
171
|
-
RHC::Rest::Client.stub!(:new) { |openshift_rest_node, username, password, debug| @username = username; @password = password; true}
|
172
|
-
end
|
193
|
+
let(:auth){ mock }
|
194
|
+
before{ RHC::Auth::Basic.should_receive(:new).once.with(subject.send(:options)).and_return(auth) }
|
173
195
|
|
174
|
-
it
|
175
|
-
|
176
|
-
|
177
|
-
$terminal.write_line("password")
|
178
|
-
subject.send(:rest_client).should be_true
|
179
|
-
@username.should == "testuser@foo.bar"
|
180
|
-
subject.send(:config)["default_rhlogin"].should == @username
|
181
|
-
@password.should == "password"
|
182
|
-
end
|
196
|
+
it do
|
197
|
+
subject.should_receive(:client_from_options).with(:auth => auth)
|
198
|
+
subject.send(:rest_client)
|
183
199
|
end
|
200
|
+
it { subject.send(:rest_client).should be_a(RHC::Rest::Client) }
|
201
|
+
it { subject.send(:rest_client).should equal subject.send(:rest_client) }
|
184
202
|
end
|
185
203
|
end
|
204
|
+
|
205
|
+
describe Commander::Command::Options do
|
206
|
+
it{ subject.foo = 'bar'; subject.foo.should == 'bar' }
|
207
|
+
it{ subject.foo = lambda{ 'bar' }; subject.foo.should == 'bar' }
|
208
|
+
it{ subject.foo = lambda{ 'bar' }; subject[:foo].should == 'bar' }
|
209
|
+
it{ subject.foo = lambda{ 'bar' }; subject['foo'].should == 'bar' }
|
210
|
+
it{ subject.foo = lambda{ 'bar' }; subject.__hash__[:foo].should be_a Proc }
|
211
|
+
it{ subject[:foo] = lambda{ 'bar' }; subject.foo.should == 'bar' }
|
212
|
+
it{ subject['foo'] = lambda{ 'bar' }; subject.foo.should == 'bar' }
|
213
|
+
it{ Commander::Command::Options.new(:foo => 1).foo.should == 1 }
|
214
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rest_spec_helper'
|
3
|
+
require 'rhc'
|
4
|
+
require 'rhc/commands/account'
|
5
|
+
|
6
|
+
describe RHC::Commands::Account do
|
7
|
+
|
8
|
+
describe 'run' do
|
9
|
+
let(:arguments) { ['account'] }
|
10
|
+
let(:username) { 'foo' }
|
11
|
+
let(:password) { 'pass' }
|
12
|
+
let(:server) { mock_uri }
|
13
|
+
before{ user_config }
|
14
|
+
before do
|
15
|
+
stub_api(true)
|
16
|
+
stub_user
|
17
|
+
end
|
18
|
+
|
19
|
+
it('should display the correct user') { run_output.should =~ /Login:\s*#{username}/ }
|
20
|
+
it('should not show') { run_output.should_not =~ /Plan:/ }
|
21
|
+
it('should show the gear capabilities') { run_output.should =~ /Allowed Gear Sizes:\s*small/ }
|
22
|
+
it('should show the consumed gears') { run_output.should =~ /Gears Used:\s*0/ }
|
23
|
+
it('should show the maximum gears') { run_output.should =~ /Gears Allowed:\s*3/ }
|
24
|
+
it { expect { run }.should exit_with_code(0) }
|
25
|
+
|
26
|
+
context 'with a freeshift plan' do
|
27
|
+
let(:user_plan_id){ 'freeshift' }
|
28
|
+
it('should show') { run_output.should =~ /Plan:\s*FreeShift/ }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with a megashift plan' do
|
32
|
+
let(:user_plan_id){ 'megashift' }
|
33
|
+
it('should show') { run_output.should =~ /Plan:\s*MegaShift/ }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with a arbitrary plan' do
|
37
|
+
let(:user_plan_id){ 'other' }
|
38
|
+
it('should show') { run_output.should =~ /Plan:\s*Other/ }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|