rhc 0.98.16 → 1.0.4

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 (94) hide show
  1. data/bin/rhc +7 -49
  2. data/bin/rhc-app +14 -3
  3. data/bin/rhc-chk +16 -16
  4. data/bin/rhc-create-app +2 -0
  5. data/bin/rhc-create-domain +1 -2
  6. data/bin/rhc-ctl-app +12 -3
  7. data/bin/rhc-ctl-domain +1 -2
  8. data/bin/rhc-domain +1 -2
  9. data/bin/rhc-domain-info +1 -2
  10. data/bin/rhc-port-forward +1 -2
  11. data/bin/rhc-snapshot +3 -0
  12. data/bin/rhc-sshkey +1 -2
  13. data/bin/rhc-tail-files +1 -1
  14. data/bin/rhc-user-info +1 -3
  15. data/features/application.feature +4 -1
  16. data/features/domain.feature +0 -4
  17. data/features/geared_application.feature +11 -0
  18. data/features/lib/rhc_helper/app.rb +16 -5
  19. data/features/lib/rhc_helper/cartridge.rb +25 -9
  20. data/features/lib/rhc_helper/commandify.rb +34 -7
  21. data/features/lib/rhc_helper/domain.rb +2 -2
  22. data/features/lib/rhc_helper/httpify.rb +24 -14
  23. data/features/lib/rhc_helper/persistable.rb +1 -1
  24. data/features/lib/rhc_helper/sshkey.rb +11 -7
  25. data/features/lib/rhc_helper.rb +5 -3
  26. data/features/multiple_cartridge.feature +1 -1
  27. data/features/scaled_application.feature +48 -0
  28. data/features/sshkey.feature +37 -31
  29. data/features/step_definitions/application_steps.rb +18 -7
  30. data/features/step_definitions/cartridge_steps.rb +29 -3
  31. data/features/step_definitions/domain_steps.rb +2 -2
  32. data/features/step_definitions/sshkey_steps.rb +34 -34
  33. data/features/support/assumptions.rb +21 -9
  34. data/features/support/before_hooks.rb +24 -6
  35. data/features/support/env.rb +45 -19
  36. data/lib/rhc/cartridge_helper.rb +27 -0
  37. data/lib/rhc/cli.rb +1 -1
  38. data/lib/rhc/command_runner.rb +31 -3
  39. data/lib/rhc/commands/alias.rb +38 -0
  40. data/lib/rhc/commands/app.rb +478 -0
  41. data/lib/rhc/commands/base.rb +42 -12
  42. data/lib/rhc/commands/cartridge.rb +189 -0
  43. data/lib/rhc/commands/domain.rb +11 -49
  44. data/lib/rhc/commands/port-forward.rb +0 -1
  45. data/lib/rhc/commands/setup.rb +2 -1
  46. data/lib/rhc/commands/snapshot.rb +118 -0
  47. data/lib/rhc/commands/sshkey.rb +24 -38
  48. data/lib/rhc/commands/tail.rb +24 -0
  49. data/lib/rhc/commands/threaddump.rb +16 -0
  50. data/lib/rhc/commands.rb +33 -7
  51. data/lib/rhc/config.rb +28 -12
  52. data/lib/rhc/context_helper.rb +19 -5
  53. data/lib/rhc/core_ext.rb +86 -0
  54. data/lib/rhc/exceptions.rb +44 -0
  55. data/lib/rhc/git_helper.rb +59 -0
  56. data/lib/rhc/helpers.rb +86 -5
  57. data/lib/rhc/output_helpers.rb +213 -0
  58. data/lib/rhc/rest/application.rb +134 -67
  59. data/lib/rhc/rest/base.rb +48 -0
  60. data/lib/rhc/rest/cartridge.rb +40 -44
  61. data/lib/rhc/rest/client.rb +127 -59
  62. data/lib/rhc/rest/domain.rb +29 -39
  63. data/lib/rhc/rest/gear_group.rb +10 -0
  64. data/lib/rhc/rest/key.rb +8 -23
  65. data/lib/rhc/rest/user.rb +8 -24
  66. data/lib/rhc/rest.rb +22 -11
  67. data/lib/rhc/ssh_key_helpers.rb +47 -0
  68. data/lib/rhc/usage_templates/help.erb +0 -1
  69. data/lib/rhc/version.rb +3 -3
  70. data/lib/rhc/wizard.rb +123 -225
  71. data/lib/rhc-common.rb +43 -62
  72. data/spec/rest_spec_helper.rb +159 -36
  73. data/spec/rhc/cli_spec.rb +29 -1
  74. data/spec/rhc/command_spec.rb +32 -35
  75. data/spec/rhc/commands/alias_spec.rb +123 -0
  76. data/spec/rhc/commands/app_spec.rb +414 -0
  77. data/spec/rhc/commands/cartridge_spec.rb +342 -0
  78. data/spec/rhc/commands/domain_spec.rb +8 -8
  79. data/spec/rhc/commands/setup_spec.rb +17 -6
  80. data/spec/rhc/commands/snapshot_spec.rb +140 -0
  81. data/spec/rhc/commands/sshkey_spec.rb +26 -4
  82. data/spec/rhc/commands/tail_spec.rb +34 -0
  83. data/spec/rhc/commands/threaddump_spec.rb +83 -0
  84. data/spec/rhc/config_spec.rb +39 -13
  85. data/spec/rhc/context_spec.rb +51 -0
  86. data/spec/rhc/helpers_spec.rb +52 -12
  87. data/spec/rhc/rest_application_spec.rb +16 -3
  88. data/spec/rhc/rest_client_spec.rb +144 -36
  89. data/spec/rhc/rest_spec.rb +1 -1
  90. data/spec/rhc/wizard_spec.rb +133 -232
  91. data/spec/spec_helper.rb +4 -3
  92. metadata +56 -31
  93. data/features/support/ssh.sh +0 -2
  94. data/spec/rhc/common_spec.rb +0 -49
@@ -64,9 +64,13 @@ module RestSpecHelper
64
64
  def mock_app_links(domain_id='test_domain',app_id='test_app')
65
65
  [['ADD_CARTRIDGE', "domains/#{domain_id}/apps/#{app_id}/carts/add", 'post'],
66
66
  ['LIST_CARTRIDGES', "domains/#{domain_id}/apps/#{app_id}/carts/", 'get' ],
67
+ ['GET_GEAR_GROUPS', "domains/#{domain_id}/apps/#{app_id}/gear_groups", 'get' ],
67
68
  ['START', "domains/#{domain_id}/apps/#{app_id}/start", 'post'],
68
69
  ['STOP', "domains/#{domain_id}/apps/#{app_id}/stop", 'post'],
69
70
  ['RESTART', "domains/#{domain_id}/apps/#{app_id}/restart", 'post'],
71
+ ['THREAD_DUMP', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
72
+ ['ADD_ALIAS', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
73
+ ['REMOVE_ALIAS', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
70
74
  ['DELETE', "domains/#{domain_id}/apps/#{app_id}/delete", 'post']]
71
75
  end
72
76
 
@@ -123,14 +127,29 @@ module RestSpecHelper
123
127
  }
124
128
  end
125
129
 
130
+ def mock_gear_groups_response()
131
+ groups = [{}]
132
+ type = 'gear_groups'
133
+
134
+ return {
135
+ :body => {
136
+ :type => type,
137
+ :data => groups
138
+ }.to_json,
139
+ :status => 200
140
+ }
141
+ end
142
+
126
143
  class MockRestClient < RHC::Rest::Client
127
144
  def initialize
128
145
  RHC::Rest::Client.stub(:new) { self }
129
146
  @domains = []
130
- @keys = [
131
- MockRestKey.new('mockkey1', 'ssh-rsa', 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDNK8xT3O+kSltmCMsSqBfAgheB3YFJ9Y0ESJnFjFASVxH70AcCQAgdQSD/r31+atYShJdP7f0AMWiQUTw2tK434XSylnZWEyIR0V+j+cyOPdVQlns6D5gPOnOtweFF0o18YulwCOK8Q1H28GK8qyWhLe0FcMmxtKbbQgaVRvQdXZz4ThzutCJOyJm9xVb93+fatvwZW76oLLvfFJcJSOK2sgW7tJM2A83bm4mwixFDF7wO/+C9WA+PgPKJUIjvy1gZjBhRB+3b58vLOnYhPOgMNruJwzB+wJ3pg8tLJEjxSbHyyoi6OqMBs4BVV7LdzvwTDxEjcgtHVvaVNXgO5iRX'),
132
- MockRestKey.new('mockkey2', 'ssh-dsa', 'AAAAB3NzaC1kc3MAAACBAPaaFj6Xjrjd8Dc4AAkJe0HigqaXMxj/87xHoV+nPgerHIceJWhPUWdW40lSASrgpAV9Eq4zzD+L19kgYdbMw0vSX5Cj3XtNOsow9MmMxFsYjTxCv4eSs/rLdGPaYZ5GVRPDu8tN42Bm8lj5o+ky3HzwW+mkQMZwcADQIgqtn6QhAAAAFQCirDfIMf/JoMOFf8CTnsTKWw/0zwAAAIAIQp6t2sLIp1d2TBfd/qLjOJA10rPADcnhBzWB/cd/oFJ8a/2nmxeSPR5Ov18T6itWqbKwvZw2UC0MrXoYbgcfVNP/ym1bCd9rB5hu1sg8WO4JIxA/47PZooT6PwTKVxHuENEzQyJL2o6ZJq+wuV0taLvm6IaM5TAZuEJ2p4TC/gAAAIBpLcVXZREa7XLY55nyidt/+UC+PxpjhPHOHbzL1OvWEaumN4wcJk/JZPppgXX9+WDkTm1SD891U0cXnGMTP0OZOHkOUHF2ZcfUe7p9kX4WjHs0OccoxV0Lny6MC4DjalJyaaEbijJHSUX3QlLcBOlPHJWpEpvWQ9P8AN4PokiGzA==')
133
- ]
147
+ @user = MockRestUser.new(RHC::Config.username)
148
+ @__json_args__= {:links => mock_response_links(mock_client_links)}
149
+ end
150
+
151
+ def user
152
+ @user
134
153
  end
135
154
 
136
155
  def domains
@@ -138,9 +157,14 @@ module RestSpecHelper
138
157
  end
139
158
 
140
159
  def cartridges
141
- [MockRestCartridge.new("mock_cart-1", "mock_cart_type-1"),
142
- MockRestCartridge.new("mock_cart-2", "mock_cart_type-2"),
143
- MockRestCartridge.new("unique_mock_cart-1", "unique_mock_cart_type-1")]
160
+ [MockRestCartridge.new("mock_standalone_cart-1", "standalone"),
161
+ MockRestCartridge.new("mock_standalone_cart-2", "standalone"),
162
+ MockRestCartridge.new("mock_unique_standalone_cart-1", "standalone"),
163
+ MockRestCartridge.new("jenkins-1.4", "standalone"),
164
+ MockRestCartridge.new("mock_cart-1", "embedded"),
165
+ MockRestCartridge.new("mock_cart-2", "embedded"),
166
+ MockRestCartridge.new("unique_mock_cart-1", "embedded"),
167
+ MockRestCartridge.new("jenkins-client-1.4", "embedded")]
144
168
  end
145
169
 
146
170
  def add_domain(id)
@@ -148,32 +172,44 @@ module RestSpecHelper
148
172
  @domains << d
149
173
  d
150
174
  end
151
-
175
+
152
176
  def sshkeys
153
- @keys
154
- end
155
-
156
- def find_key(name)
157
- # RHC::Rest::Client#find_key(name) returns the first (and only) key
158
- @keys.select { |key| key.name == name }.first
177
+ @user.keys
159
178
  end
160
-
179
+
161
180
  def add_key(name, type, content)
162
- @keys << MockRestKey.new(name, type, content)
181
+ @user.add_key(name, type, content)
163
182
  end
164
-
183
+
165
184
  def delete_key(name)
166
- @keys.delete_if { |key| key.name == name }
185
+ @user.keys.delete_if { |key| key.name == name }
167
186
  end
168
187
  end
169
188
 
170
- class MockRestDomain < RHC::Rest::Domain
171
- attr_reader :id
189
+ class MockRestUser < RHC::Rest::User
190
+ def initialize(login)
191
+ @login = login
192
+ @keys = [
193
+ MockRestKey.new('mockkey1', 'ssh-rsa', 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDNK8xT3O+kSltmCMsSqBfAgheB3YFJ9Y0ESJnFjFASVxH70AcCQAgdQSD/r31+atYShJdP7f0AMWiQUTw2tK434XSylnZWEyIR0V+j+cyOPdVQlns6D5gPOnOtweFF0o18YulwCOK8Q1H28GK8qyWhLe0FcMmxtKbbQgaVRvQdXZz4ThzutCJOyJm9xVb93+fatvwZW76oLLvfFJcJSOK2sgW7tJM2A83bm4mwixFDF7wO/+C9WA+PgPKJUIjvy1gZjBhRB+3b58vLOnYhPOgMNruJwzB+wJ3pg8tLJEjxSbHyyoi6OqMBs4BVV7LdzvwTDxEjcgtHVvaVNXgO5iRX'),
194
+ MockRestKey.new('mockkey2', 'ssh-dsa', 'AAAAB3NzaC1kc3MAAACBAPaaFj6Xjrjd8Dc4AAkJe0HigqaXMxj/87xHoV+nPgerHIceJWhPUWdW40lSASrgpAV9Eq4zzD+L19kgYdbMw0vSX5Cj3XtNOsow9MmMxFsYjTxCv4eSs/rLdGPaYZ5GVRPDu8tN42Bm8lj5o+ky3HzwW+mkQMZwcADQIgqtn6QhAAAAFQCirDfIMf/JoMOFf8CTnsTKWw/0zwAAAIAIQp6t2sLIp1d2TBfd/qLjOJA10rPADcnhBzWB/cd/oFJ8a/2nmxeSPR5Ov18T6itWqbKwvZw2UC0MrXoYbgcfVNP/ym1bCd9rB5hu1sg8WO4JIxA/47PZooT6PwTKVxHuENEzQyJL2o6ZJq+wuV0taLvm6IaM5TAZuEJ2p4TC/gAAAIBpLcVXZREa7XLY55nyidt/+UC+PxpjhPHOHbzL1OvWEaumN4wcJk/JZPppgXX9+WDkTm1SD891U0cXnGMTP0OZOHkOUHF2ZcfUe7p9kX4WjHs0OccoxV0Lny6MC4DjalJyaaEbijJHSUX3QlLcBOlPHJWpEpvWQ9P8AN4PokiGzA==')
195
+ ]
196
+ end
197
+
198
+ def keys
199
+ @keys
200
+ end
172
201
 
202
+ def add_key(name, type, content)
203
+ @keys << MockRestKey.new(name, type, content)
204
+ end
205
+ end
206
+
207
+ class MockRestDomain < RHC::Rest::Domain
173
208
  def initialize(id, client)
174
209
  @id = id
175
210
  @client = client
176
211
  @applications = []
212
+ @__json_args__= {:links => mock_response_links(mock_domain_links('mock_domain_0'))}
177
213
  end
178
214
 
179
215
  def update(id)
@@ -189,9 +225,15 @@ module RestSpecHelper
189
225
  @applications = nil
190
226
  end
191
227
 
192
- def add_application(name, type=nil, scale=nil)
193
- a = MockRestApplication.new(name, type, self, scale)
228
+ def add_application(name, type=nil, scale=nil, gear_profile='default')
229
+ if type.is_a?(Hash)
230
+ scale = type[:scale]
231
+ gear_profile = type[:gear_profile]
232
+ type = type[:cartridge]
233
+ end
234
+ a = MockRestApplication.new(name, type, self, scale, gear_profile)
194
235
  @applications << a
236
+ a.add_message("Success")
195
237
  a
196
238
  end
197
239
 
@@ -200,59 +242,140 @@ module RestSpecHelper
200
242
  end
201
243
  end
202
244
 
203
- class MockRestApplication
204
- attr_reader :name, :uuid, :creation_time, :git_url, :app_url, :aliases, :scalable, :embedded, :ssh_url
245
+ class MockRestGearGroup < RHC::Rest::GearGroup
246
+ def initialize
247
+ @cartridges = [{'name' => 'fake_geargroup_cart-0.1'}]
248
+ @gears = [{'state' => 'started', 'id' => 'fakegearid'}]
249
+ end
250
+ end
251
+
252
+ class MockRestApplication < RHC::Rest::Application
253
+ def fakeuuid
254
+ "fakeuuidfortests#{@name}"
255
+ end
205
256
 
206
- def initialize(name, type, domain, scale=nil)
257
+ def initialize(name, type, domain, scale=nil, gear_profile='default')
207
258
  @name = name
208
259
  @domain = domain
209
260
  @cartridges = []
210
261
  @creation_time = "now"
211
- @uuid = "fakeuuidfortests"
262
+ @uuid = fakeuuid
212
263
  @git_url = "git:fake.foo/git/#{@name}.git"
213
264
  @app_url = "https://#{@name}-#{@domain.id}.fake.foo/"
214
265
  @ssh_url = "ssh://#{@uuid}@127.0.0.1"
215
266
  @embedded = {}
216
267
  @aliases = []
268
+ @gear_profile = gear_profile
217
269
  if scale
218
270
  @scalable = true
219
271
  @embedded = {"haproxy-1.4" => {:info => ""}}
220
272
  end
221
- add_cartridge(type, false) if type
273
+ @__json_args__= {:links => mock_response_links(mock_app_links('mock_domain_0', 'mock_app_0'))}
274
+ cart = add_cartridge(type, false) if type
275
+ if scale
276
+ cart.scales_to = -1
277
+ cart.scales_from = 2
278
+ cart.current_scale = 2
279
+ cart.scales_with = "haproxy-1.4"
280
+ end
281
+ @framework = type
282
+ @messages = []
283
+ end
284
+
285
+ def destroy
286
+ @domain.applications.delete self
222
287
  end
223
288
 
224
289
  def add_cartridge(name, embedded=true)
225
- type = embedded ? "embedded" : "framework"
290
+ type = embedded ? "embedded" : "standalone"
226
291
  c = MockRestCartridge.new(name, type, self)
227
292
  @cartridges << c
228
293
  c
229
294
  end
230
295
 
296
+ def gear_groups
297
+ # we don't have heavy interaction with gear groups yet so keep this simple
298
+ @gear_groups ||= [MockRestGearGroup.new]
299
+ end
300
+
231
301
  def cartridges
232
302
  @cartridges
233
303
  end
304
+
305
+ def start
306
+ @app
307
+ end
308
+
309
+ def stop(*args)
310
+ @app
311
+ end
312
+
313
+ def restart
314
+ @app
315
+ end
316
+
317
+ def reload
318
+ @app
319
+ end
320
+
321
+ def tidy
322
+ @app
323
+ end
234
324
  end
235
325
 
236
326
  class MockRestCartridge < RHC::Rest::Cartridge
237
- attr_reader :name
238
- attr_reader :type
239
- attr_reader :properties
240
-
241
- def initialize(name, type, app=nil, properties={:cart_data => {:connection_url => {'value' => "http://fake.url" }}})
327
+ attr_accessor :scales_to, :scales_from, :current_scale, :scales_with
328
+ def initialize(name, type, app=nil, properties={:cart_data => {:connection_url => {'name' => 'connection_url', 'value' => "http://fake.url" }}})
242
329
  @name = name
243
330
  @type = type
244
331
  @app = app
245
332
  @properties = properties
333
+ @status_messages = [{"message" => "started", "gear_id" => "123"}]
334
+ @scales_from = 1
335
+ @scales_to = 1
336
+ @current_scale = 1
337
+ end
338
+
339
+ def destroy
340
+ @app.cartridges.delete self
341
+ end
342
+
343
+ def status
344
+ @status_messages
345
+ end
346
+
347
+ def start
348
+ @status_messages = [{"message" => "started", "gear_id" => "123"}]
349
+ @app
350
+ end
351
+
352
+ def stop
353
+ @status_messages = [{"message" => "stopped", "gear_id" => "123"}]
354
+ @app
355
+ end
356
+
357
+ def restart
358
+ @status_messages = [{"message" => "started", "gear_id" => "123"}]
359
+ @app
360
+ end
361
+
362
+ def reload
363
+ @app
364
+ end
365
+
366
+ def set_scales(values)
367
+ values.delete_if{|k,v| v.nil? }
368
+ @scales_from = values[:scales_from] if values[:scales_from]
369
+ @scales_to = values[:scales_to] if values[:scales_to]
370
+ self
246
371
  end
247
372
  end
248
-
373
+
249
374
  class MockRestKey < RHC::Rest::Key
250
- attr_reader :name, :type, :content
251
375
  def initialize(name, type, content)
252
376
  @name = name
253
377
  @type = type
254
378
  @content = content
255
379
  end
256
-
257
380
  end
258
381
  end
data/spec/rhc/cli_spec.rb CHANGED
@@ -15,6 +15,29 @@ describe RHC::CLI do
15
15
  it('should contain the arguments') { run_output.should include(@arguments[0]) }
16
16
  it('should reference --help') { run_output.should =~ / help\b/ }
17
17
  end
18
+
19
+ shared_examples_for 'version output' do
20
+ let(:arguments) { @arguments }
21
+ it 'should contain version output' do
22
+ run_output.should =~ /rhc \d+\.\d+(:?\.d+)?/
23
+ end
24
+ end
25
+
26
+ describe "--version" do
27
+ context "by itself" do
28
+ before :each do
29
+ @arguments = ['--version']
30
+ end
31
+ it_should_behave_like 'version output'
32
+ 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
+ end
18
41
 
19
42
  describe '#start' do
20
43
  context 'with no arguments' do
@@ -27,11 +50,16 @@ describe RHC::CLI do
27
50
  it_should_behave_like 'an invalid command'
28
51
  end
29
52
 
30
- context 'with help and invalid command' do
53
+ context 'with --help and invalid command' do
31
54
  before(:each) { @arguments = ['invalidcommand', '--help'] }
32
55
  it_should_behave_like 'an invalid command'
33
56
  end
34
57
 
58
+ context 'with help and invalid command' do
59
+ before(:each) { @arguments = ['help', 'invalidcommand'] }
60
+ it_should_behave_like 'an invalid command'
61
+ end
62
+
35
63
  context 'with --help' do
36
64
  before(:each){ @arguments = ['--help'] }
37
65
  it_should_behave_like 'a help page'
@@ -44,21 +44,19 @@ describe RHC::Commands::Base do
44
44
  it("should register itself") { expect { subject }.to change(commands, :length).by(1) }
45
45
  it("should have an object name") { subject.object_name.should == 'test' }
46
46
  it("should run with wizard") do
47
- FakeFS.activate!
48
-
49
- wizard_run = false
50
- RHC::Wizard.stub!(:new) do |config|
51
- RHC::Wizard.unstub!(:new)
52
- w = RHC::Wizard.new(config)
53
- w.stub!(:run) { wizard_run = true }
54
- w
55
- end
56
-
57
- expects_running('test').should call(:run).on(instance).with(no_args)
58
- wizard_run.should be_true
47
+ FakeFS do
48
+ RHC::Config.set_defaults
49
+ wizard_run = false
50
+ RHC::Wizard.stub!(:new) do |config|
51
+ RHC::Wizard.unstub!(:new)
52
+ w = RHC::Wizard.new(config)
53
+ w.stub!(:run) { wizard_run = true }
54
+ w
55
+ end
59
56
 
60
- FakeFS::FileSystem.clear
61
- FakeFS.deactivate!
57
+ expects_running('test').should call(:run).on(instance).with(no_args)
58
+ wizard_run.should be_true
59
+ end
62
60
  end
63
61
  end
64
62
 
@@ -94,8 +92,8 @@ describe RHC::Commands::Base do
94
92
  def execute(testarg); 1; end
95
93
 
96
94
  argument :args, "Test arg list", [], :arg_type => :list
97
- summary "Test command execute_list"
98
- def execute_list(*args); 1; end
95
+ summary "Test command execute-list"
96
+ def execute_list(args); 1; end
99
97
 
100
98
  def raise_error
101
99
  raise StandardError.new("test exception")
@@ -114,6 +112,7 @@ describe RHC::Commands::Base do
114
112
  context 'and when test is called' do
115
113
  it { expects_running('static', 'test').should call(:test).on(instance).with(no_args) }
116
114
  end
115
+
117
116
  context 'and when execute is called with argument' do
118
117
  it { expects_running('static', 'execute', 'simplearg').should call(:execute).on(instance).with('simplearg') }
119
118
  end
@@ -133,27 +132,29 @@ describe RHC::Commands::Base do
133
132
  end
134
133
 
135
134
  context 'and when execute_list is called' do
136
- it { expects_running('static', 'execute_list').should call(:execute_list).on(instance).with([]) }
137
- it { expects_running('static', 'execute_list', '1', '2', '3').should call(:execute_list).on(instance).with(['1', '2', '3']) }
135
+ it { expects_running('static', 'execute-list', '--trace').should call(:execute_list).on(instance).with([]) }
136
+ it { expects_running('static', 'execute-list', '1', '2', '3').should call(:execute_list).on(instance).with(['1', '2', '3']) }
138
137
  end
139
138
 
140
139
  context 'and when an error is raised in a call' do
141
- it { expects_running('static', 'raise_error').should raise_error(StandardError, "test exception") }
140
+ it { expects_running('static', 'raise-error').should raise_error(StandardError, "test exception") }
142
141
  end
143
142
 
144
143
  context 'and when an exception is raised in a call' do
145
- it { expects_running('static', 'raise_exception').should raise_error(Exception, "test exception") }
144
+ it { expects_running('static', 'raise-exception').should raise_error(Exception, "test exception") }
146
145
  end
147
146
 
148
147
  context 'and when an exception is raised in a call with --trace option' do
149
- it { expects_running('static', 'raise_exception', "--trace").should raise_error(Exception, "test exception") }
148
+ it { expects_running('static', 'raise-exception', "--trace").should raise_error(Exception, "test exception") }
150
149
  end
151
150
 
152
151
  context 'and when deprecated alias is called' do
153
152
  it do
154
153
  expects_running('static', 'exe', "arg").should call(:execute).on(instance).with('arg')
155
154
  $stderr.seek(0)
156
- $stderr.read.should match("Warning: The command 'rhc static exe' is deprecated. Please use 'rhc static execute' instead.")
155
+ # some systems might redirect warnings to stderr
156
+ output = "#{$stderr.read} #{$terminal.read}"
157
+ output.should match("Warning: This command is deprecated. Please use 'rhc static execute' instead.")
157
158
  end
158
159
  end
159
160
 
@@ -167,23 +168,19 @@ describe RHC::Commands::Base do
167
168
 
168
169
  describe "rest_client" do
169
170
  before do
170
- FakeFS.activate!
171
+ mock_terminal
171
172
  RHC::Rest::Client.stub!(:new) { |openshift_rest_node, username, password, debug| @username = username; @password = password; true}
172
173
  end
173
174
 
174
175
  it "should ask for username" do
175
- $terminal.write_line("testuser@foo.bar")
176
- $terminal.write_line("password")
177
- subject.send(:rest_client).should be_true
178
- @username.should == "testuser@foo.bar"
179
- subject.send(:config)["default_rhlogin"].should == @username
180
- @password.should == "password"
181
- end
182
-
183
- after do
184
- FakeFS::FileSystem.clear
185
- FakeFS.deactivate!
176
+ FakeFS do
177
+ $terminal.write_line("testuser@foo.bar")
178
+ $terminal.write_line("password")
179
+ subject.send(:rest_client).should be_true
180
+ @username.should == "testuser@foo.bar"
181
+ subject.send(:config)["default_rhlogin"].should == @username
182
+ @password.should == "password"
183
+ end
186
184
  end
187
185
  end
188
-
189
186
  end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+ require 'rest_spec_helper'
3
+ require 'rhc/commands/alias'
4
+ require 'rhc/config'
5
+ describe RHC::Commands::Alias do
6
+ let(:client_links) { mock_response_links(mock_client_links) }
7
+ let(:domain_0_links) { mock_response_links(mock_domain_links('mock_domain_0')) }
8
+ let(:domain_1_links) { mock_response_links(mock_domain_links('mock_domain_1')) }
9
+ let(:app_0_links) { mock_response_links(mock_app_links('mock_domain_0', 'mock_app_0')) }
10
+ 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'}).
15
+ to_return({ :body => {
16
+ :type => 'domains',
17
+ :data =>
18
+ [{ :id => 'mock_domain_0',
19
+ :links => mock_response_links(mock_domain_links('mock_domain_0')),
20
+ },
21
+ { :id => 'mock_domain_1',
22
+ :links => mock_response_links(mock_domain_links('mock_domain_1')),
23
+ }]
24
+ }.to_json,
25
+ :status => 200
26
+ })
27
+ stub_api_request(:any, domain_0_links['LIST_APPLICATIONS']['relative']).with(:headers => {'Accept-Encoding'=>'gzip, deflate'}).
28
+ to_return({ :body => {
29
+ :type => 'applications',
30
+ :data =>
31
+ [{ :domain_id => 'mock_domain_0',
32
+ :name => 'mock_app_0',
33
+ :creation_time => Time.new.to_s,
34
+ :uuid => 1234,
35
+ :aliases => ['alias_1', 'alias_2'],
36
+ :server_identity => 'mock_server_identity',
37
+ :links => mock_response_links(mock_app_links('mock_domain_0','mock_app_0')),
38
+ }]
39
+ }.to_json,
40
+ :status => 200
41
+ })
42
+ stub_api_request(:any, app_0_links['ADD_ALIAS']['relative']).with(:body => {:event => 'add-alias', :alias => 'www.foo.bar'}, :headers => {'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'33', 'Content-Type'=>'application/x-www-form-urlencoded'}).
43
+ to_return({ :body => {
44
+ :type => 'application',
45
+ :data =>
46
+ { :domain_id => 'mock_domain_1',
47
+ :name => 'mock_app_0',
48
+ :creation_time => Time.new.to_s,
49
+ :uuid => 1234,
50
+ :aliases => ['alias_1', 'alias_2'],
51
+ :server_identity => 'mock_server_identity',
52
+ :links => mock_response_links(mock_app_links('mock_domain_1','mock_app_0')),
53
+ },
54
+ :messages => [{:text => "RESULT:\nApplication event 'add-alias' successful"}]
55
+ }.to_json,
56
+ :status => 200
57
+ })
58
+ stub_api_request(:any, app_0_links['REMOVE_ALIAS']['relative']).with(:body => {:event => 'remove-alias', :alias => 'www.foo.bar'}, :headers => {'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'36', 'Content-Type'=>'application/x-www-form-urlencoded'}).
59
+ to_return({ :body => {
60
+ :type => 'application',
61
+ :data =>
62
+ { :domain_id => 'mock_domain_1',
63
+ :name => 'mock_app_0',
64
+ :creation_time => Time.new.to_s,
65
+ :uuid => 1234,
66
+ :aliases => ['alias_1', 'alias_2'],
67
+ :server_identity => 'mock_server_identity',
68
+ :links => mock_response_links(mock_app_links('mock_domain_1','mock_app_0')),
69
+ },
70
+ :messages => [{:text => "RESULT:\nApplication event 'remove-alias' successful"}]
71
+ }.to_json,
72
+ :status => 200
73
+ })
74
+
75
+ end
76
+
77
+ describe 'alias help' do
78
+ let(:arguments) { ['alias', '--help'] }
79
+
80
+ context 'help is run' do
81
+ it "should display help" do
82
+ expect { run }.should exit_with_code(0)
83
+ end
84
+ it('should output usage') { run_output.should match("Usage: rhc alias <command> <application> <alias> [--namespace namespace]") }
85
+ end
86
+ end
87
+
88
+ describe 'alias add --help' do
89
+ let(:arguments) { ['alias', 'add', '--help'] }
90
+
91
+ context 'help is run' do
92
+ it "should display help" do
93
+ expect { run }.should exit_with_code(0)
94
+ end
95
+ it('should output usage') { run_output.should match("Usage: rhc alias add <application> <alias> [--namespace namespace]") }
96
+ end
97
+ end
98
+
99
+ describe 'alias remove --help' do
100
+ let(:arguments) { ['alias', 'remove', '--help'] }
101
+
102
+ context 'help is run' do
103
+ it "should display help" do
104
+ expect { run }.should exit_with_code(0)
105
+ end
106
+ it('should output usage') { run_output.should match("Usage: rhc alias remove <application> <alias> [--namespace namespace]") }
107
+ end
108
+ end
109
+
110
+ describe 'add alias' do
111
+ let(:arguments) { ['alias', 'add', 'mock_app_0', 'www.foo.bar', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password' ] }
112
+ context 'with no issues' do
113
+ it { expect { run }.should exit_with_code(0) }
114
+ end
115
+ end
116
+
117
+ describe 'remove alias' do
118
+ let(:arguments) { ['alias', 'remove', 'mock_app_0', 'www.foo.bar', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password' ] }
119
+ context 'with no issues' do
120
+ it { expect { run }.should exit_with_code(0) }
121
+ end
122
+ end
123
+ end