rhc 1.12.4 → 1.13.6
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/autocomplete/rhc_bash +161 -9
- data/bin/rhc +2 -2
- data/features/env.feature +0 -0
- data/features/step_definitions/env_steps.rb +1 -0
- data/features/support/platform_support.rb +5 -5
- data/lib/rhc/cartridge_helpers.rb +19 -3
- data/lib/rhc/command_runner.rb +1 -1
- data/lib/rhc/commands/app.rb +32 -17
- data/lib/rhc/commands/base.rb +15 -19
- data/lib/rhc/commands/cartridge.rb +14 -9
- data/lib/rhc/commands/env.rb +146 -0
- data/lib/rhc/commands.rb +19 -7
- data/lib/rhc/exceptions.rb +25 -1
- data/lib/rhc/help_formatter.rb +2 -2
- data/lib/rhc/helpers.rb +29 -2
- data/lib/rhc/output_helpers.rb +19 -2
- data/lib/rhc/rest/application.rb +49 -3
- data/lib/rhc/rest/cartridge.rb +4 -4
- data/lib/rhc/rest/client.rb +41 -6
- data/lib/rhc/rest/environment_variable.rb +15 -0
- data/lib/rhc/rest/mock.rb +52 -20
- data/lib/rhc/rest.rb +24 -23
- data/lib/rhc/usage_templates/help.erb +4 -4
- data/spec/rhc/assets/env_vars.txt +7 -0
- data/spec/rhc/assets/env_vars_2.txt +1 -0
- data/spec/rhc/commands/app_spec.rb +51 -10
- data/spec/rhc/commands/cartridge_spec.rb +61 -9
- data/spec/rhc/commands/env_spec.rb +493 -0
- data/spec/rhc/helpers_spec.rb +25 -5
- data/spec/rhc/rest_spec.rb +4 -3
- metadata +16 -4
@@ -0,0 +1,493 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rest_spec_helper'
|
3
|
+
require 'rhc/commands/env'
|
4
|
+
require 'rhc/config'
|
5
|
+
|
6
|
+
describe RHC::Commands::Env do
|
7
|
+
|
8
|
+
def exit_with_code_and_message(code, message=nil)
|
9
|
+
expect{ run }.to exit_with_code(code)
|
10
|
+
run_output.should match(message) if message
|
11
|
+
end
|
12
|
+
|
13
|
+
def exit_with_code_and_without_message(code, message=nil)
|
14
|
+
expect{ run }.to exit_with_code(code)
|
15
|
+
run_output.should_not match(message) if message
|
16
|
+
end
|
17
|
+
|
18
|
+
def succeed_with_message(message="done")
|
19
|
+
exit_with_code_and_message(0, message)
|
20
|
+
end
|
21
|
+
|
22
|
+
def succeed_without_message(message="done")
|
23
|
+
exit_with_code_and_without_message(0, message)
|
24
|
+
end
|
25
|
+
|
26
|
+
let!(:rest_client) { MockRestClient.new }
|
27
|
+
|
28
|
+
before(:each) do
|
29
|
+
user_config
|
30
|
+
@rest_domain = rest_client.add_domain("mock_domain_0")
|
31
|
+
@rest_app = @rest_domain.add_application("mock_app_0", "ruby-1.8.7")
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'env help' do
|
35
|
+
let(:arguments) { ['env', '--help'] }
|
36
|
+
context 'help is run' do
|
37
|
+
it "should display help" do
|
38
|
+
expect { run }.to exit_with_code(0)
|
39
|
+
end
|
40
|
+
it('should output usage') { run_output.should match("Usage: rhc env <action>$") }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'env set --help' do
|
45
|
+
[['env', 'set', '--help'],
|
46
|
+
['env', 'add', '--help'],
|
47
|
+
['set-env', '--help'],
|
48
|
+
['env-set', '--help']
|
49
|
+
].each_with_index do |args, i|
|
50
|
+
context "help is run run with arguments #{i}" do
|
51
|
+
let(:arguments) { args }
|
52
|
+
it "should display help" do
|
53
|
+
expect { run }.to exit_with_code(0)
|
54
|
+
end
|
55
|
+
it('should output usage') { run_output.should match("Usage: rhc env-set <VARIABLE=VALUE>") }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'env unset --help' do
|
61
|
+
[['env', 'unset', '--help'],
|
62
|
+
['env', 'remove', '--help'],
|
63
|
+
['unset-env', '--help'],
|
64
|
+
['env-unset', '--help']
|
65
|
+
].each_with_index do |args, i|
|
66
|
+
context "help is run run with arguments #{i}" do
|
67
|
+
let(:arguments) { args }
|
68
|
+
it "should display help" do
|
69
|
+
expect { run }.to exit_with_code(0)
|
70
|
+
end
|
71
|
+
it('should output usage') { run_output.should match("Usage: rhc env-unset <VARIABLE>") }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'env list --help' do
|
77
|
+
[['env', 'list', '--help'],
|
78
|
+
['list-env', '--help'],
|
79
|
+
['env-list', '--help']
|
80
|
+
].each_with_index do |args, i|
|
81
|
+
context "help is run run with arguments #{i}" do
|
82
|
+
let(:arguments) { args }
|
83
|
+
it "should display help" do
|
84
|
+
expect { run }.to exit_with_code(0)
|
85
|
+
end
|
86
|
+
it('should output usage') { run_output.should match("Usage: rhc env-list <app> [--namespace NAME]") }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'env show --help' do
|
92
|
+
[['env', 'show', '--help'],
|
93
|
+
['show-env', '--help'],
|
94
|
+
['env-show', '--help']
|
95
|
+
].each_with_index do |args, i|
|
96
|
+
context "help is run run with arguments #{i}" do
|
97
|
+
let(:arguments) { args }
|
98
|
+
it "should display help" do
|
99
|
+
expect { run }.to exit_with_code(0)
|
100
|
+
end
|
101
|
+
it('should output usage') { run_output.should match("Usage: rhc env-show <VARIABLE>") }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'set env' do
|
107
|
+
|
108
|
+
[['env', 'set', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
109
|
+
['set-env', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
110
|
+
['env', 'set', '-e', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
111
|
+
['env', 'set', '--env', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
112
|
+
['env', 'set', 'FOO_BAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
113
|
+
['env', 'set', 'F1=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
114
|
+
['env', 'set', 'F_=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
115
|
+
['env', 'set', '_FOO=1', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
116
|
+
['env', 'set', 'FOO=BAR=BAZ', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
117
|
+
['env', 'set', 'FOO==', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
118
|
+
['env', 'set', 'FOO=Test 1 2 3', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
119
|
+
].each_with_index do |args, i|
|
120
|
+
context "when run with single env var #{i}" do
|
121
|
+
let(:arguments) { args }
|
122
|
+
it { succeed_with_message /Setting environment variable\(s\) \.\.\./ }
|
123
|
+
it { succeed_with_message /done/ }
|
124
|
+
it { succeed_without_message /TEST_ENV_VAR=1/ }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
[['env', 'set', 'TEST_ENV_VAR1=1', 'TEST_ENV_VAR2=2', 'TEST_ENV_VAR3=3', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
130
|
+
['set-env', 'TEST_ENV_VAR1=1', 'TEST_ENV_VAR2=2', 'TEST_ENV_VAR3=3', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
131
|
+
['set-env', '-e', 'TEST_ENV_VAR1=1', '-e', 'TEST_ENV_VAR2=2', '-e', 'TEST_ENV_VAR3=3', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
132
|
+
['set-env', '--env', 'TEST_ENV_VAR1=1', '--env', 'TEST_ENV_VAR2=2', '--env', 'TEST_ENV_VAR3=3', '--app', 'mock_app_0', '--noprompt', '--confirm' ]
|
133
|
+
].each_with_index do |args, i|
|
134
|
+
context "when run with multiple env vars #{i}" do
|
135
|
+
let(:arguments) { args }
|
136
|
+
it { succeed_with_message /Setting environment variable\(s\) \.\.\./ }
|
137
|
+
it { succeed_with_message /done/ }
|
138
|
+
it { succeed_without_message /TEST_ENV_VAR1=1/ }
|
139
|
+
it { succeed_without_message /TEST_ENV_VAR2=2/ }
|
140
|
+
it { succeed_without_message /TEST_ENV_VAR3=3/ }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
[['env', 'set', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
145
|
+
['set-env', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
146
|
+
['env', 'set', '-e', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
147
|
+
['env', 'set', '--env', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
148
|
+
].each_with_index do |args, i|
|
149
|
+
context "when run with no env var provided #{i}" do
|
150
|
+
let(:arguments) { args }
|
151
|
+
it "should raise env var not provided exception" do
|
152
|
+
expect{ run }.to exit_with_code(159)
|
153
|
+
run_output.should match(/Environment variable\(s\) not provided\./)
|
154
|
+
run_output.should match(/Please provide at least one environment variable using the syntax VARIABLE=VALUE\./)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when run with multiple env vars from file' do
|
160
|
+
let(:arguments) {['env', 'set', File.expand_path('../../assets/env_vars.txt', __FILE__), '--app', 'mock_app_0', '--noprompt', '--confirm' ]}
|
161
|
+
it { succeed_with_message /FOO=123/ }
|
162
|
+
it { succeed_with_message /BAR=456/ }
|
163
|
+
it { succeed_with_message /MY_OPENSHIFT_ENV_VAR/ }
|
164
|
+
it { succeed_with_message /MY_EMPTY_ENV_VAR/ }
|
165
|
+
it { succeed_without_message /ZEE/ }
|
166
|
+
it { succeed_without_message /LOL/ }
|
167
|
+
it { succeed_without_message /MUST NOT BE INCLUDED/ }
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when run with multiple env vars from multiple files' do
|
171
|
+
let(:arguments) {['env', 'set', '-e', File.expand_path('../../assets/env_vars.txt', __FILE__), '-e', File.expand_path('../../assets/env_vars_2.txt', __FILE__), '--app', 'mock_app_0', '--noprompt', '--confirm' ]}
|
172
|
+
it { succeed_with_message /FOO=123/ }
|
173
|
+
it { succeed_with_message /BAR=456/ }
|
174
|
+
it { succeed_with_message /MY_OPENSHIFT_ENV_VAR/ }
|
175
|
+
it { succeed_with_message /MY_EMPTY_ENV_VAR/ }
|
176
|
+
it { succeed_with_message /AND=123/ }
|
177
|
+
it { succeed_without_message /ZEE/ }
|
178
|
+
it { succeed_without_message /LOL/ }
|
179
|
+
it { succeed_without_message /MUST NOT BE INCLUDED/ }
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when run with empty file' do
|
183
|
+
let(:arguments) {['env', 'set', File.expand_path('../../assets/empty.txt', __FILE__), '--app', 'mock_app_0', '--noprompt', '--confirm' ]}
|
184
|
+
it "should raise env var not provided exception" do
|
185
|
+
expect{ run }.to exit_with_code(159)
|
186
|
+
run_output.should match(/Environment variable\(s\) not found in the provided file\(s\)\./)
|
187
|
+
run_output.should match(/Please provide at least one environment variable using the syntax VARIABLE=VALUE\./)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'when run with --noprompt and without --confirm' do
|
192
|
+
let(:arguments) { ['env', 'set', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt' ] }
|
193
|
+
it("should not ask for confirmation") { expect{ run }.to exit_with_code(0) }
|
194
|
+
it("should output confirmation") { run_output.should_not match("This action requires the --confirm option") }
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when run with --noprompt and without --confirm from file' do
|
198
|
+
let(:arguments) { ['env', 'set', File.expand_path('../../assets/env_vars.txt', __FILE__), '--app', 'mock_app_0', '--noprompt' ] }
|
199
|
+
it "should ask for confirmation" do
|
200
|
+
expect{ run }.to exit_with_code(1)
|
201
|
+
end
|
202
|
+
it("should output confirmation") { run_output.should match("This action requires the --confirm option") }
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'when run against an unsupported server' do
|
206
|
+
before {
|
207
|
+
@rest_app.links.delete 'SET_UNSET_ENVIRONMENT_VARIABLES'
|
208
|
+
@rest_app.links.delete 'LIST_ENVIRONMENT_VARIABLES'
|
209
|
+
}
|
210
|
+
let(:arguments) { ['env', 'set', 'TEST_ENV_VAR=1', '--app', 'mock_app_0', '--noprompt', '--confirm' ] }
|
211
|
+
it "should raise env var not found exception" do
|
212
|
+
expect{ run }.to exit_with_code(158)
|
213
|
+
run_output.should match(/Server does not support environment variables/)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
[['env', 'set', 'FOO.Z=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
218
|
+
['env', 'set', '2FOO=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
219
|
+
['env', 'set', 'FO$O=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
220
|
+
['env', 'set', 'FO%O=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
221
|
+
['env', 'set', 'FO*O=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
222
|
+
['env', 'set', 'FOO.=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
223
|
+
['env', 'set', '=BAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
224
|
+
['env', 'set', '==', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
225
|
+
].each_with_index do |args, i|
|
226
|
+
context "when run with invalid env var names #{i}" do
|
227
|
+
let(:arguments) { args }
|
228
|
+
it "should raise env var not provided exception" do
|
229
|
+
expect{ run }.to exit_with_code(159)
|
230
|
+
run_output.should match(/Environment variable\(s\) not provided\./)
|
231
|
+
run_output.should match(/Please provide at least one environment variable using the syntax VARIABLE=VALUE\./)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
describe 'unset env' do
|
239
|
+
|
240
|
+
[['env', 'unset', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
241
|
+
['unset-env', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm'],
|
242
|
+
['env', 'unset', '-e', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
243
|
+
['env', 'unset', '--env', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt', '--confirm' ]
|
244
|
+
].each_with_index do |args, i|
|
245
|
+
context "when run with single env var #{i}" do
|
246
|
+
let(:arguments) { args }
|
247
|
+
it { succeed_with_message /TEST_ENV_VAR/ }
|
248
|
+
it { succeed_with_message /Removing environment variable\(s\) \.\.\./ }
|
249
|
+
it { succeed_with_message /removed/ }
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
[['env', 'unset', 'TEST_ENV_VAR1', 'TEST_ENV_VAR2', 'TEST_ENV_VAR3', '--app', 'mock_app_0', '--noprompt', '--confirm' ],
|
254
|
+
['unset-env', 'TEST_ENV_VAR1', 'TEST_ENV_VAR2', 'TEST_ENV_VAR3', '--app', 'mock_app_0', '--noprompt', '--confirm' ]
|
255
|
+
].each_with_index do |args, i|
|
256
|
+
context "when run with multiple env vars #{i}" do
|
257
|
+
let(:arguments) { args }
|
258
|
+
it { succeed_with_message /TEST_ENV_VAR1/ }
|
259
|
+
it { succeed_with_message /TEST_ENV_VAR2/ }
|
260
|
+
it { succeed_with_message /TEST_ENV_VAR3/ }
|
261
|
+
it { succeed_with_message /Removing environment variable\(s\) \.\.\./ }
|
262
|
+
it { succeed_with_message /removed/ }
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
context 'when run with --noprompt and without --confirm' do
|
267
|
+
let(:arguments) { ['env', 'unset', 'TEST_ENV_VAR', '--app', 'mock_app_0', '--noprompt' ] }
|
268
|
+
it "should ask for confirmation" do
|
269
|
+
expect{ run }.to exit_with_code(1)
|
270
|
+
end
|
271
|
+
it("should output confirmation") { run_output.should match("This action requires the --confirm option") }
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
describe 'list env' do
|
276
|
+
context 'when list with default format' do
|
277
|
+
before(:each) do
|
278
|
+
@rest_app.set_environment_variables(
|
279
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
280
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
281
|
+
end
|
282
|
+
let(:arguments) { ['env', 'list', '--app', 'mock_app_0'] }
|
283
|
+
it { succeed_with_message /FOO=123/ }
|
284
|
+
it { succeed_with_message /BAR=456/ }
|
285
|
+
it "should contain the environment variables" do
|
286
|
+
@rest_app.environment_variables.length.should == 2
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context 'when list with default format and empty env vars' do
|
291
|
+
let(:arguments) { ['env', 'list', '--app', 'mock_app_0'] }
|
292
|
+
it "should exit with no message" do
|
293
|
+
expect{ run }.to exit_with_code(0)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context 'when list with quotes format' do
|
298
|
+
before(:each) do
|
299
|
+
@rest_app.set_environment_variables(
|
300
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
301
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
302
|
+
end
|
303
|
+
let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--quotes'] }
|
304
|
+
it { succeed_with_message /FOO="123"/ }
|
305
|
+
it { succeed_with_message /BAR="456"/ }
|
306
|
+
it "should contain the environment variables" do
|
307
|
+
@rest_app.environment_variables.length.should == 2
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context 'when list with quotes format and empty env vars' do
|
312
|
+
let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--quotes'] }
|
313
|
+
it "should exit with no message" do
|
314
|
+
expect{ run }.to exit_with_code(0)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
context 'when list with table format' do
|
319
|
+
before(:each) do
|
320
|
+
@rest_app.set_environment_variables(
|
321
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
322
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
323
|
+
end
|
324
|
+
let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--table'] }
|
325
|
+
it { succeed_with_message /Name\s+Value/ }
|
326
|
+
it { succeed_with_message /FOO\s+123/ }
|
327
|
+
it { succeed_with_message /BAR\s+456/ }
|
328
|
+
it "should contain the right number of env vars" do
|
329
|
+
@rest_app.environment_variables.length.should == 2
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context 'when list with table and quotes format' do
|
334
|
+
before(:each) do
|
335
|
+
@rest_app.set_environment_variables(
|
336
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
337
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
338
|
+
end
|
339
|
+
let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--table', '--quotes'] }
|
340
|
+
it { succeed_with_message /Name\s+Value/ }
|
341
|
+
it { succeed_with_message /FOO\s+"123"/ }
|
342
|
+
it { succeed_with_message /BAR\s+"456"/ }
|
343
|
+
it "should contain the right number of env vars" do
|
344
|
+
@rest_app.environment_variables.length.should == 2
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context 'when list with table format and empty env vars' do
|
349
|
+
let(:arguments) { ['env', 'list', '--app', 'mock_app_0', '--table'] }
|
350
|
+
it "should exit with no message" do
|
351
|
+
expect{ run }.to exit_with_code(0)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
describe 'show env' do
|
357
|
+
context 'when show with default format' do
|
358
|
+
before(:each) do
|
359
|
+
@rest_app.set_environment_variables(
|
360
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
361
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
362
|
+
end
|
363
|
+
let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0'] }
|
364
|
+
it { succeed_with_message /FOO=123/ }
|
365
|
+
it "should not contain env vars not specified to show" do
|
366
|
+
run_output.should_not match(/BAR=456/)
|
367
|
+
end
|
368
|
+
it "should contain the right number of env vars" do
|
369
|
+
@rest_app.environment_variables.length.should == 2
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
context 'when show with default format and not found env var' do
|
374
|
+
let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0'] }
|
375
|
+
it "should raise env var not found exception" do
|
376
|
+
expect{ run }.to exit_with_code(157)
|
377
|
+
run_output.should match(/Environment variable\(s\) FOO can't be found in application mock_app_0/)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
context 'when show with default format and not found env var' do
|
382
|
+
before(:each) do
|
383
|
+
@rest_app.set_environment_variables(
|
384
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
385
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
386
|
+
end
|
387
|
+
let(:arguments) { ['env', 'show', 'ZEE', '--app', 'mock_app_0'] }
|
388
|
+
it "should contain the right number of env vars" do
|
389
|
+
@rest_app.environment_variables.length.should == 2
|
390
|
+
end
|
391
|
+
it "should not contain env vars not specified to show" do
|
392
|
+
run_output.should_not match(/FOO=123/)
|
393
|
+
run_output.should_not match(/BAR=456/)
|
394
|
+
end
|
395
|
+
it "should raise env var not found exception" do
|
396
|
+
expect{ run }.to exit_with_code(157)
|
397
|
+
run_output.should match(/Environment variable\(s\) ZEE can't be found in application mock_app_0/)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
context 'when show with quotes format' do
|
402
|
+
before(:each) do
|
403
|
+
@rest_app.set_environment_variables(
|
404
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
405
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
406
|
+
end
|
407
|
+
let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0', '--quotes'] }
|
408
|
+
it { succeed_with_message /FOO="123"/ }
|
409
|
+
it "should not contain env vars not specified to show" do
|
410
|
+
run_output.should_not match(/BAR="456"/)
|
411
|
+
end
|
412
|
+
it "should contain the right number of env vars" do
|
413
|
+
@rest_app.environment_variables.length.should == 2
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
context 'when show with quotes format and not found env var' do
|
418
|
+
before(:each) do
|
419
|
+
@rest_app.set_environment_variables(
|
420
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
421
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
422
|
+
end
|
423
|
+
let(:arguments) { ['env', 'show', 'ZEE', '--app', 'mock_app_0', '--quotes'] }
|
424
|
+
it "should contain the right number of env vars" do
|
425
|
+
@rest_app.environment_variables.length.should == 2
|
426
|
+
end
|
427
|
+
it "should not contain env vars not specified to show" do
|
428
|
+
run_output.should_not match(/FOO=123/)
|
429
|
+
run_output.should_not match(/BAR=456/)
|
430
|
+
end
|
431
|
+
it "should raise env var not found exception" do
|
432
|
+
expect{ run }.to exit_with_code(157)
|
433
|
+
run_output.should match(/Environment variable\(s\) ZEE can't be found in application mock_app_0/)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
context 'when show with table format' do
|
438
|
+
before(:each) do
|
439
|
+
@rest_app.set_environment_variables(
|
440
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
441
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
442
|
+
end
|
443
|
+
let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0', '--table'] }
|
444
|
+
it { succeed_with_message /Name\s+Value/ }
|
445
|
+
it { succeed_with_message /FOO\s+123/ }
|
446
|
+
it "should not contain env vars not specified to show" do
|
447
|
+
run_output.should_not match(/BAR/)
|
448
|
+
end
|
449
|
+
it "should contain the right number of env vars" do
|
450
|
+
@rest_app.environment_variables.length.should == 2
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
context 'when show with table and quotes format' do
|
455
|
+
before(:each) do
|
456
|
+
@rest_app.set_environment_variables(
|
457
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
458
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
459
|
+
end
|
460
|
+
let(:arguments) { ['env', 'show', 'FOO', '--app', 'mock_app_0', '--table', '--quotes'] }
|
461
|
+
it { succeed_with_message /Name\s+Value/ }
|
462
|
+
it { succeed_with_message /FOO\s+"123"/ }
|
463
|
+
it "should not contain env vars not specified to show" do
|
464
|
+
run_output.should_not match(/BAR/)
|
465
|
+
end
|
466
|
+
it "should contain the right number of env vars" do
|
467
|
+
@rest_app.environment_variables.length.should == 2
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
context 'when show with table format and not found env var' do
|
472
|
+
before(:each) do
|
473
|
+
@rest_app.set_environment_variables(
|
474
|
+
[RHC::Rest::EnvironmentVariable.new({:name => 'FOO', :value => '123'}),
|
475
|
+
RHC::Rest::EnvironmentVariable.new({:name => 'BAR', :value => '456'})])
|
476
|
+
end
|
477
|
+
let(:arguments) { ['env', 'show', 'ZEE', '--app', 'mock_app_0', '--table'] }
|
478
|
+
it "should contain the right number of env vars" do
|
479
|
+
@rest_app.environment_variables.length.should == 2
|
480
|
+
end
|
481
|
+
it "should not contain env vars not specified to show" do
|
482
|
+
run_output.should_not match(/FOO/)
|
483
|
+
run_output.should_not match(/BAR/)
|
484
|
+
end
|
485
|
+
it "should raise env var not found exception" do
|
486
|
+
expect{ run }.to exit_with_code(157)
|
487
|
+
run_output.should match(/Environment variable\(s\) ZEE can't be found in application mock_app_0/)
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
end
|
492
|
+
|
493
|
+
end
|
data/spec/rhc/helpers_spec.rb
CHANGED
@@ -329,7 +329,7 @@ describe AllRhcHelpers do
|
|
329
329
|
it "should handle a block in multi_ssh calls" do
|
330
330
|
expect_multi_ssh('foo', 'fakegearid0@fakesshurl.com' => 'bar')
|
331
331
|
capture{ subject.table_from_gears('foo', [RHC::Rest::Mock::MockRestGearGroup.new], :header => ['cart','col']) }.should match /cart.*col\n-+.*fakegearid0.*bar/m
|
332
|
-
end
|
332
|
+
end
|
333
333
|
|
334
334
|
it "should handle a run_on_gears error for unrecognized type" do
|
335
335
|
expect_multi_ssh('foo', {})
|
@@ -385,21 +385,21 @@ describe AllRhcHelpers do
|
|
385
385
|
|
386
386
|
describe "#strip_ansi" do
|
387
387
|
it{ "\e[1m \e[1m".strip_ansi.should == " " }
|
388
|
-
it{ "\eiei0".strip_ansi.should == "\eiei0" }
|
389
|
-
it{ "\e[iei0]".strip_ansi.should == "\e[iei0]" }
|
388
|
+
it{ "\eiei0".strip_ansi.should == "\eiei0" }
|
389
|
+
it{ "\e[iei0]".strip_ansi.should == "\e[iei0]" }
|
390
390
|
end
|
391
391
|
|
392
392
|
context "Resolv helper" do
|
393
393
|
let(:resolver) { Object.new }
|
394
394
|
let(:existent_host) { 'real_host' }
|
395
395
|
let(:nonexistent_host) { 'fake_host' }
|
396
|
-
|
396
|
+
|
397
397
|
before do
|
398
398
|
Resolv::Hosts.stub(:new) { resolver }
|
399
399
|
resolver.stub(:getaddress).with(existent_host) { existent_host }
|
400
400
|
resolver.stub(:getaddress).with(nonexistent_host){ Resolv::ResolvError }
|
401
401
|
end
|
402
|
-
|
402
|
+
|
403
403
|
context "when hosts file has the desired host" do
|
404
404
|
it "does not raise error" do
|
405
405
|
expect {
|
@@ -446,6 +446,26 @@ describe AllRhcHelpers do
|
|
446
446
|
end
|
447
447
|
end
|
448
448
|
end
|
449
|
+
|
450
|
+
describe "#collect_env_vars" do
|
451
|
+
it { subject.collect_env_vars('FOO=BAR').first.to_hash.should == { :name => 'FOO', :value => 'BAR' } }
|
452
|
+
it { subject.collect_env_vars('FOO2=BAR2').first.to_hash.should == { :name => 'FOO2', :value => 'BAR2' } }
|
453
|
+
it { subject.collect_env_vars('FOO_BAR=ZEE').first.to_hash.should == { :name => 'FOO_BAR', :value => 'ZEE' } }
|
454
|
+
it { subject.collect_env_vars('_FOO=BAR').first.to_hash.should == { :name => '_FOO', :value => 'BAR' } }
|
455
|
+
it { subject.collect_env_vars('FOO=').first.to_hash.should == { :name => 'FOO', :value => '' } }
|
456
|
+
it { subject.collect_env_vars('FOO==').first.to_hash.should == { :name => 'FOO', :value => '=' } }
|
457
|
+
it { subject.collect_env_vars('FOO=BAR=ZEE').first.to_hash.should == { :name => 'FOO', :value => 'BAR=ZEE' } }
|
458
|
+
it { subject.collect_env_vars('foo25_=BAR=\][#%*').first.to_hash.should == { :name => 'foo25_', :value => 'BAR=\][#%*' } }
|
459
|
+
it { subject.collect_env_vars('FOO=Test 1 2 3').first.to_hash.should == { :name => 'FOO', :value => 'Test 1 2 3' } }
|
460
|
+
it { subject.collect_env_vars('2FOO=BAR').empty?.should be_true }
|
461
|
+
it { subject.collect_env_vars('FOO.2=BAR').empty?.should be_true }
|
462
|
+
it { subject.collect_env_vars('FOO BAR=ZEE').empty?.should be_true }
|
463
|
+
it { subject.collect_env_vars('FOO*BAR=ZEE').empty?.should be_true }
|
464
|
+
it { subject.collect_env_vars('FOO&BAR=ZEE').empty?.should be_true }
|
465
|
+
it { subject.collect_env_vars('FOO:BAR=ZEE').empty?.should be_true }
|
466
|
+
it { subject.collect_env_vars('FOO@BAR=ZEE').empty?.should be_true }
|
467
|
+
it { subject.collect_env_vars('FOO!BAR=ZEE').empty?.should be_true }
|
468
|
+
end
|
449
469
|
end
|
450
470
|
|
451
471
|
describe RHC::Helpers::StringTee do
|
data/spec/rhc/rest_spec.rb
CHANGED
@@ -293,19 +293,20 @@ module RHC
|
|
293
293
|
{:field => 'base', :severity => 'result', :text => 'Result severity'}, # >= 1.5 API
|
294
294
|
{:field => 'base', :severity => 'info', :text => 'Non-result message' },
|
295
295
|
{:field => 'result', :severity => 'debug', :text => 'Debug message' },
|
296
|
+
{:field => 'base', :severity => 'warning', :text => 'Warning message' },
|
296
297
|
]
|
297
298
|
end
|
298
299
|
let(:response) do
|
299
300
|
{ :type => 'user', :data => object, :messages => messages }.to_json
|
300
301
|
end
|
301
302
|
|
302
|
-
it "copies
|
303
|
+
it "copies all non-warning and non-info messages to the object" do
|
303
304
|
subject.send(:parse_response, response).messages.should == ['Result field', 'Result severity']
|
304
305
|
end
|
305
306
|
|
306
|
-
it "includes debug info when debug true" do
|
307
|
+
it "includes debug and info when debug true" do
|
307
308
|
subject.stub(:debug?).and_return(true)
|
308
|
-
subject.send(:parse_response, response).messages.should == ['Result field', 'Result severity', 'Debug message']
|
309
|
+
subject.send(:parse_response, response).messages.should == ['Nil field', 'Result field', 'Result severity', 'Non-result message', 'Debug message']
|
309
310
|
end
|
310
311
|
end
|
311
312
|
end
|