rhc 0.97.17 → 0.98.16

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 (93) hide show
  1. data/bin/rhc +9 -9
  2. data/bin/rhc-port-forward +3 -0
  3. data/bin/rhc-sshkey +3 -0
  4. data/features/README.md +163 -35
  5. data/features/application.feature +24 -0
  6. data/features/cartridge.feature +24 -0
  7. data/features/client.feature +11 -0
  8. data/features/domain.feature +29 -0
  9. data/features/lib/rhc_helper.rb +14 -0
  10. data/features/lib/rhc_helper/app.rb +2 -8
  11. data/features/lib/rhc_helper/cartridge.rb +1 -7
  12. data/features/lib/rhc_helper/commandify.rb +37 -6
  13. data/features/lib/rhc_helper/domain.rb +5 -1
  14. data/features/lib/rhc_helper/httpify.rb +124 -60
  15. data/features/lib/rhc_helper/loggable.rb +0 -2
  16. data/features/lib/rhc_helper/persistable.rb +12 -2
  17. data/features/lib/rhc_helper/sshkey.rb +29 -0
  18. data/features/multiple_cartridge.feature +17 -0
  19. data/features/sshkey.feature +58 -0
  20. data/features/step_definitions/application_steps.rb +60 -52
  21. data/features/step_definitions/cartridge_steps.rb +22 -24
  22. data/features/step_definitions/client_steps.rb +9 -2
  23. data/features/step_definitions/domain_steps.rb +4 -0
  24. data/features/step_definitions/sshkey_steps.rb +56 -0
  25. data/features/support/assumptions.rb +37 -0
  26. data/features/support/before_hooks.rb +25 -0
  27. data/features/support/env.rb +84 -39
  28. data/features/support/key1 +27 -0
  29. data/features/support/key1.pub +1 -0
  30. data/features/support/key2 +27 -0
  31. data/features/support/key2.pub +1 -0
  32. data/features/support/key3.pub +1 -0
  33. data/features/support/ssh.sh +2 -0
  34. data/features/verify.feature +18 -159
  35. data/lib/rhc-common.rb +8 -21
  36. data/lib/rhc.rb +9 -5
  37. data/lib/rhc/autocomplete.rb +68 -0
  38. data/lib/rhc/autocomplete_templates/rhc.erb +33 -0
  39. data/lib/rhc/cli.rb +9 -6
  40. data/lib/rhc/command_runner.rb +108 -0
  41. data/lib/rhc/commands.rb +66 -132
  42. data/lib/rhc/commands/base.rb +95 -24
  43. data/lib/rhc/commands/domain.rb +33 -50
  44. data/lib/rhc/commands/port-forward.rb +81 -0
  45. data/lib/rhc/commands/setup.rb +1 -1
  46. data/lib/rhc/commands/sshkey.rb +95 -0
  47. data/lib/rhc/config.rb +108 -103
  48. data/lib/rhc/context_helper.rb +19 -0
  49. data/lib/rhc/coverage_helper.rb +1 -1
  50. data/lib/rhc/exceptions.rb +55 -4
  51. data/lib/rhc/help_formatter.rb +2 -3
  52. data/lib/rhc/helpers.rb +31 -23
  53. data/lib/{rhc-rest.rb → rhc/rest.rb} +95 -23
  54. data/lib/{rhc-rest → rhc/rest}/application.rb +1 -1
  55. data/lib/{rhc-rest → rhc/rest}/cartridge.rb +1 -1
  56. data/lib/{rhc-rest → rhc/rest}/client.rb +40 -9
  57. data/lib/{rhc-rest → rhc/rest}/domain.rb +1 -1
  58. data/lib/{rhc-rest → rhc/rest}/key.rb +11 -1
  59. data/lib/{rhc-rest → rhc/rest}/user.rb +1 -1
  60. data/lib/rhc/ssh_key_helpers.rb +10 -1
  61. data/lib/rhc/targz.rb +7 -8
  62. data/lib/rhc/usage_templates/command_help.erb +7 -6
  63. data/lib/rhc/usage_templates/help.erb +6 -9
  64. data/lib/rhc/usage_templates/missing_help.erb +1 -0
  65. data/lib/rhc/version.rb +2 -2
  66. data/lib/rhc/wizard.rb +4 -9
  67. data/spec/coverage_helper.rb +2 -2
  68. data/spec/rest_spec_helper.rb +66 -16
  69. data/spec/rhc/cli_spec.rb +16 -5
  70. data/spec/rhc/command_spec.rb +61 -6
  71. data/spec/rhc/commands/domain_spec.rb +50 -27
  72. data/spec/rhc/commands/port-forward_spec.rb +133 -0
  73. data/spec/rhc/commands/setup_spec.rb +2 -2
  74. data/spec/rhc/commands/sshkey_spec.rb +141 -0
  75. data/spec/rhc/common_spec.rb +1 -1
  76. data/spec/rhc/config_spec.rb +6 -4
  77. data/spec/rhc/helpers_spec.rb +0 -21
  78. data/spec/rhc/rest_application_spec.rb +7 -7
  79. data/spec/rhc/rest_client_spec.rb +87 -24
  80. data/spec/rhc/rest_spec.rb +36 -36
  81. data/spec/rhc/wizard_spec.rb +3 -3
  82. data/spec/spec.opts +1 -0
  83. data/spec/spec_helper.rb +3 -3
  84. metadata +61 -31
  85. data/lib/rhc-rest/exceptions/exceptions.rb +0 -75
  86. data/test/functional/application_test.rb +0 -71
  87. data/test/functional/domain_test.rb +0 -123
  88. data/test/functional/test_credentials.rb +0 -5
  89. data/test/sample-usage.rb +0 -122
  90. data/test/support/server.rb +0 -14
  91. data/test/support/testcase.rb +0 -3
  92. data/test/test_helper.rb +0 -4
  93. data/test/unit/command_test.rb +0 -19
@@ -1,4 +1,4 @@
1
- module Rhc
1
+ module RHC
2
2
  module Rest
3
3
  class Domain
4
4
  include Rest
@@ -1,4 +1,4 @@
1
- module Rhc
1
+ module RHC
2
2
  module Rest
3
3
  class Key
4
4
  include Rest
@@ -29,6 +29,16 @@ module Rhc
29
29
  return request(request)
30
30
  end
31
31
  alias :delete :destroy
32
+
33
+ def fingerprint
34
+ begin
35
+ public_key = Net::SSH::KeyFactory.load_data_public_key("#{type} #{content}")
36
+ public_key.fingerprint
37
+ rescue NotImplementedError, OpenSSL::PKey::PKeyError => e
38
+ 'Invalid key'
39
+ end
40
+
41
+ end
32
42
  end
33
43
  end
34
44
  end
@@ -1,4 +1,4 @@
1
- module Rhc
1
+ module RHC
2
2
  module Rest
3
3
  class User
4
4
  include Rest
@@ -39,7 +39,7 @@ module RHC
39
39
  :comment => comment)
40
40
  ssh_dir = "#{RHC::Config.home_dir}/.ssh"
41
41
  if File.exists?("#{ssh_dir}/id_rsa")
42
- puts "SSH key already exists: #{ssh_dir}/id_rsa. Reusing..."
42
+ say "SSH key already exists: #{ssh_dir}/id_rsa. Reusing..."
43
43
  return nil
44
44
  else
45
45
  unless File.exists?(ssh_dir)
@@ -60,6 +60,15 @@ module RHC
60
60
  File.executable?(File.join(directory, executable.to_s))
61
61
  end
62
62
  end
63
+
64
+ # Public: Format SSH key's core attributes (name, type, fingerprint)
65
+ # in a given ERB template
66
+ #
67
+ # key - an object to be formatted
68
+ # template - ERB template
69
+ def format(key, template)
70
+ template.result(binding)
71
+ end
63
72
 
64
73
  private
65
74
 
data/lib/rhc/targz.rb CHANGED
@@ -11,17 +11,16 @@ module RHC
11
11
 
12
12
  def self.contains(filename, search, force_ruby=false)
13
13
 
14
- return false if ! (File.file? filename and File.basename(filename).downcase =~ /.\.tar\.gz$/i)
14
+ return false if ! (File.file? filename and File.basename(filename).downcase =~ /.\.t(ar\.)?gz$/i)
15
15
 
16
- contains = false
16
+ regex = Regexp.new search
17
17
  if RHC::Helpers.windows? or force_ruby
18
- search = /#{search.to_s}/ if ! search.is_a?(Regexp)
19
18
  begin
20
19
  RHC::Vendor::Zlib::GzipReader.open(filename) do |gz|
21
20
  Minitar::Reader.open gz do |tar|
22
21
  tar.each_entry do |entry|
23
- if entry.full_name =~ search
24
- contains = true
22
+ if entry.full_name =~ regex
23
+ return true
25
24
  end
26
25
  end
27
26
  end
@@ -30,10 +29,10 @@ module RHC
30
29
  return false
31
30
  end
32
31
  else
33
- `#{TAR_BIN} --wildcards -tf #{filename} '#{search.to_s}' 2> /dev/null`
34
- contains = $?.exitstatus == 0
32
+ # combining STDOUT and STDERR (i.e., 2>&1) does not suppress output
33
+ # when the specs run via 'bundle exec rake spec'
34
+ return system "#{TAR_BIN} --wildcards -tf #{filename} #{regex.source} 2>/dev/null >/dev/null"
35
35
  end
36
- contains
37
36
  end
38
37
 
39
38
  end
@@ -1,5 +1,6 @@
1
1
  Usage: rhc <%= @command.name %> <%= @command.syntax %>
2
- <%= @command.description || @command.summary || 'No description.' %>
2
+
3
+ <%= @command.description || @command.summary %>
3
4
  <% unless @actions.nil? or @actions.empty? -%>
4
5
 
5
6
  List of Actions
@@ -7,17 +8,17 @@ List of Actions
7
8
  <%= "%-18s %s\n" % [action[:name], action[:summary]] -%>
8
9
  <% end -%>
9
10
  <% end -%>
10
- <% unless @command.options.nil? or @command.options.empty? -%>
11
+ <% unless @command.options.nil? or @command.options.empty? or @command.options.all?{ |o| o[:hide] } -%>
11
12
 
12
13
  Options for <%= @command.name %>
13
- <% for option in @command.options -%>
14
- <%= "%-25s %s\n" % [option[:switches].join('|'), option[:description]] -%>
14
+ <% for option in @command.options -%><% next if option[:hide] -%>
15
+ <%= "%-25s %s\n" % [option[:switches].join(', '), option[:description]] -%>
15
16
  <% end -%>
16
17
  <% end -%>
17
18
 
18
19
  Global Options
19
- <% for option in @global_options -%>
20
- <%= "%-25s %s\n" % [option[:switches].join('|'), option[:description]] -%>
20
+ <% for option in @global_options -%><% next if option[:hide] -%>
21
+ <%= "%-25s %s\n" % [option[:switches].join(', '), option[:description]] -%>
21
22
  <% end -%>
22
23
  <%#-
23
24
  Other Attrs we may wish to use:
@@ -1,23 +1,20 @@
1
1
  Usage: <%= program :name %> (<resource> | --help) [<action>] [<args>]
2
2
  <%= program :description %>
3
3
 
4
- List of Resources
5
- <%# remove these as they are added to commander%>
6
- app Manage applications within the rhcloud account.
7
- sshkey Manage multiple keys for the registered rhcloud user.
8
- port-forward Forward remote ports to the workstation
4
+ List of Commands and Resources
5
+ app Manage applications within the OpenShift account.
9
6
  <% for name, command in @commands.sort -%>
10
- <%- unless alias? name or name == "help" or name.include?(" ") -%> <%="%-18s %s\n" % [command.name, command.summary || command.description] %><%- end -%>
7
+ <%- unless alias? name or name == "help" or name.include?(" ") or command.summary.nil? -%> <%="%-18s %s\n" % [command.name, command.summary || command.description] %><%- end -%>
11
8
  <%- end -%>
12
9
 
13
10
  Global Options
14
11
  <%- unless @options.nil? or @options.empty? -%>
15
- <% for option in @options -%>
16
- <%= "%-25s %s\n" % [option[:switches].join('|'), option[:description]] -%>
12
+ <% for option in @options -%><% next if option[:hide] -%>
13
+ <%= "%-25s %s\n" % [option[:switches].join(', '), option[:description]] -%>
17
14
  <% end -%>
18
15
  <%- end -%>
19
16
 
20
- See '<%= program :name %> <resource> --help' for more applicable commands and arguments on a specific resource.
17
+ See '<%= program :name %> help <resource>' for more specifics on each resource or command.
21
18
  <% if program :help -%>
22
19
  <% for title, body in program(:help) %>
23
20
  <%= $terminal.color title.to_s.upcase, :bold %>:
@@ -0,0 +1 @@
1
+ See '<%= program :name %> help' for a list of available commands.
data/lib/rhc/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module RHC
2
2
  module VERSION #:nocov:
3
3
  MAJOR = 0
4
- MINOR = 97
5
- MICRO = 17
4
+ MINOR = 98
5
+ MICRO = 16
6
6
  #PRE = ''
7
7
  STRING = [MAJOR,MINOR,MICRO].compact.join('.')
8
8
  end
data/lib/rhc/wizard.rb CHANGED
@@ -52,10 +52,6 @@ module RHC
52
52
  true
53
53
  end
54
54
 
55
- def needs_configuration?
56
- not (@config.has_local_config? or @config.has_opts_config? or @config.noprompt?)
57
- end
58
-
59
55
  private
60
56
 
61
57
  def greeting_stage
@@ -95,7 +91,7 @@ module RHC
95
91
  # instantiate a REST client that stages can use
96
92
  # TODO: use only REST calls in the wizard
97
93
  end_point = "https://#{@libra_server}/broker/rest/api"
98
- @rest_client = Rhc::Rest::Client.new(end_point, @username, @password)
94
+ @rest_client = RHC::Rest::Client.new(end_point, @username, @password)
99
95
 
100
96
  true
101
97
  end
@@ -116,7 +112,7 @@ EOF
116
112
 
117
113
  paragraph do
118
114
  say "Created local config file: " + @config_path
119
- say "The express.conf file contains user configuration, and can be transferred to different computers."
115
+ say "The #{File.basename(@config_path)} file contains user configuration, and can be transferred to different computers."
120
116
  end
121
117
 
122
118
  true
@@ -368,13 +364,12 @@ EOF
368
364
  return true
369
365
  end
370
366
 
371
-
372
367
  begin
373
368
  domain = @rest_client.add_domain(namespace)
374
369
 
375
370
  say "Your domain name '#{domain.id}' has been successfully created"
376
- rescue Rhc::Rest::ValidationException => e
377
- say "#{e.to_s}"
371
+ rescue RHC::Rest::ValidationException => e
372
+ say e.message
378
373
  return false
379
374
  end
380
375
  end
@@ -29,7 +29,7 @@ unless RUBY_VERSION < '1.9'
29
29
  # Filters - these files will be ignored.
30
30
  add_filter 'lib/rhc/vendor/' # vendored files should be taken directly and only
31
31
  # namespaces changed
32
- add_filter 'lib/rhc-rest/' # REST coverage is not yet 100%
32
+ add_filter 'lib/rhc/rest/' # REST coverage is not yet 100%
33
33
  add_filter 'lib/bin/' # This is just for safety; simplecov isn't picking these up.
34
34
  add_filter 'lib/rhc-common.rb' # deprecated, functionality moved into client or rhc/helpers.rb
35
35
  add_filter 'features/' # Don't report on the files that run the cucumber tests
@@ -39,7 +39,7 @@ unless RUBY_VERSION < '1.9'
39
39
  # Groups - general categories of test areas
40
40
  add_group('Commands') { |src_file| src_file.filename.include?(File.join(%w[lib rhc commands])) }
41
41
  add_group('RHC Lib') { |src_file| src_file.filename.include?(File.join(%w[lib rhc])) }
42
- add_group('REST') { |src_file| src_file.filename.include?(File.join(%w[lib rhc-rest])) }
42
+ add_group('REST') { |src_file| src_file.filename.include?(File.join(%w[lib rhc/rest])) }
43
43
  add_group('Legacy') { |src_file| src_file.filename.include?(File.join(%w[bin])) or
44
44
  src_file.filename.include?(File.join(%w[lib rhc-common.rb])) }
45
45
  add_group('Test') { |src_file| src_file.filename.include?(File.join(%w[features])) or
@@ -1,6 +1,7 @@
1
1
  require 'webmock/rspec'
2
- require 'rhc-rest'
2
+ require 'rhc/rest'
3
3
  require 'rhc/exceptions'
4
+ require 'base64'
4
5
 
5
6
  Spec::Matchers.define :have_same_attributes_as do |expected|
6
7
  match do |actual|
@@ -10,6 +11,15 @@ Spec::Matchers.define :have_same_attributes_as do |expected|
10
11
  end
11
12
  end
12
13
 
14
+ # ruby 1.8 does not have strict_encode
15
+ if RUBY_VERSION.to_f == 1.8
16
+ module Base64
17
+ def strict_encode64(value)
18
+ encode64(value).delete("\n")
19
+ end
20
+ end
21
+ end
22
+
13
23
  module RestSpecHelper
14
24
  def mock_user
15
25
  "test_user"
@@ -113,24 +123,51 @@ module RestSpecHelper
113
123
  }
114
124
  end
115
125
 
116
- class MockRestClient < Rhc::Rest::Client
126
+ class MockRestClient < RHC::Rest::Client
117
127
  def initialize
118
- Rhc::Rest::Client.stub(:new) { self }
128
+ RHC::Rest::Client.stub(:new) { self }
119
129
  @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
+ ]
120
134
  end
121
135
 
122
136
  def domains
123
137
  @domains
124
138
  end
125
139
 
140
+ 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")]
144
+ end
145
+
126
146
  def add_domain(id)
127
147
  d = MockRestDomain.new(id, self)
128
148
  @domains << d
129
149
  d
130
150
  end
151
+
152
+ 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
159
+ end
160
+
161
+ def add_key(name, type, content)
162
+ @keys << MockRestKey.new(name, type, content)
163
+ end
164
+
165
+ def delete_key(name)
166
+ @keys.delete_if { |key| key.name == name }
167
+ end
131
168
  end
132
169
 
133
- class MockRestDomain
170
+ class MockRestDomain < RHC::Rest::Domain
134
171
  attr_reader :id
135
172
 
136
173
  def initialize(id, client)
@@ -145,18 +182,15 @@ module RestSpecHelper
145
182
  end
146
183
 
147
184
  def destroy
148
- @client.domains.delete_if do |d|
149
- match = (d.id == @id)
150
- raise Rhc::Rest::ClientErrorException.new("Mock error. Trying to delete domain with apps.", 128) if match and not applications.empty?
151
- match
152
- end
185
+ raise RHC::Rest::ClientErrorException.new("Applications must be empty.") unless @applications.empty?
186
+ @client.domains.delete_if { |d| d.id == @id }
153
187
 
154
188
  @client = nil
155
189
  @applications = nil
156
190
  end
157
191
 
158
- def add_application(name, type)
159
- a = MockRestApplication.new(name, type, self)
192
+ def add_application(name, type=nil, scale=nil)
193
+ a = MockRestApplication.new(name, type, self, scale)
160
194
  @applications << a
161
195
  a
162
196
  end
@@ -167,9 +201,9 @@ module RestSpecHelper
167
201
  end
168
202
 
169
203
  class MockRestApplication
170
- attr_reader :name, :uuid, :creation_time, :git_url, :app_url, :aliases
204
+ attr_reader :name, :uuid, :creation_time, :git_url, :app_url, :aliases, :scalable, :embedded, :ssh_url
171
205
 
172
- def initialize(name, type, domain)
206
+ def initialize(name, type, domain, scale=nil)
173
207
  @name = name
174
208
  @domain = domain
175
209
  @cartridges = []
@@ -177,8 +211,14 @@ module RestSpecHelper
177
211
  @uuid = "fakeuuidfortests"
178
212
  @git_url = "git:fake.foo/git/#{@name}.git"
179
213
  @app_url = "https://#{@name}-#{@domain.id}.fake.foo/"
214
+ @ssh_url = "ssh://#{@uuid}@127.0.0.1"
215
+ @embedded = {}
180
216
  @aliases = []
181
- add_cartridge(type, false)
217
+ if scale
218
+ @scalable = true
219
+ @embedded = {"haproxy-1.4" => {:info => ""}}
220
+ end
221
+ add_cartridge(type, false) if type
182
222
  end
183
223
 
184
224
  def add_cartridge(name, embedded=true)
@@ -193,16 +233,26 @@ module RestSpecHelper
193
233
  end
194
234
  end
195
235
 
196
- class MockRestCartridge < Rhc::Rest::Cartridge
236
+ class MockRestCartridge < RHC::Rest::Cartridge
197
237
  attr_reader :name
198
238
  attr_reader :type
199
239
  attr_reader :properties
200
240
 
201
- def initialize(name, type, app, properties={:cart_data => {:connection_url => {'value' => "http://fake.url" }}})
241
+ def initialize(name, type, app=nil, properties={:cart_data => {:connection_url => {'value' => "http://fake.url" }}})
202
242
  @name = name
203
243
  @type = type
204
244
  @app = app
205
245
  @properties = properties
206
246
  end
207
247
  end
248
+
249
+ class MockRestKey < RHC::Rest::Key
250
+ attr_reader :name, :type, :content
251
+ def initialize(name, type, content)
252
+ @name = name
253
+ @type = type
254
+ @content = content
255
+ end
256
+
257
+ end
208
258
  end
data/spec/rhc/cli_spec.rb CHANGED
@@ -9,16 +9,27 @@ describe RHC::CLI do
9
9
  it('should provide a --config switch') { run_output.should =~ /\-\-config FILE/ }
10
10
  end
11
11
 
12
+ shared_examples_for 'an invalid command' do
13
+ let(:arguments) { @arguments }
14
+ it('should contain the invalid command message') { run_output.should =~ /is not recognized/ }
15
+ it('should contain the arguments') { run_output.should include(@arguments[0]) }
16
+ it('should reference --help') { run_output.should =~ / help\b/ }
17
+ end
18
+
12
19
  describe '#start' do
13
20
  context 'with no arguments' do
14
- let(:arguments) { [] }
15
- it { expect { run }.should exit_with_code(1) }
16
- it('should provide a message about --help') { run_output.should =~ /\-\-help/ }
21
+ before(:each) { @arguments = [] }
22
+ it_should_behave_like 'a help page'
23
+ end
24
+
25
+ context 'with an invalid command' do
26
+ before(:each) { @arguments = ['invalidcommand'] }
27
+ it_should_behave_like 'an invalid command'
17
28
  end
18
29
 
19
30
  context 'with help and invalid command' do
20
- let(:arguments) { ['invalidcommand', 'help'] }
21
- it { expect { run }.should exit_with_code(1) }
31
+ before(:each) { @arguments = ['invalidcommand', '--help'] }
32
+ it_should_behave_like 'an invalid command'
22
33
  end
23
34
 
24
35
  context 'with --help' do
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'rhc/commands/base'
3
+ require 'rhc/exceptions'
3
4
 
4
5
  describe RHC::Commands::Base do
5
6
  describe '#object_name' do
@@ -13,7 +14,7 @@ describe RHC::Commands::Base do
13
14
  end
14
15
  StaticRootClass
15
16
  end
16
- its(:object_name) { should == 'staticrootclass' }
17
+ its(:object_name) { should == 'static-root-class' }
17
18
  end
18
19
  context 'when the class is nested in a module' do
19
20
  subject do
@@ -22,7 +23,7 @@ describe RHC::Commands::Base do
22
23
  end
23
24
  Nested::StaticRootClass
24
25
  end
25
- its(:object_name) { should == 'staticrootclass' }
26
+ its(:object_name) { should == 'static-root-class' }
26
27
  end
27
28
  end
28
29
 
@@ -87,9 +88,18 @@ describe RHC::Commands::Base do
87
88
 
88
89
  def test; 1; end
89
90
 
90
- argument :testarg, "Test arg", "--testarg testarg"
91
+ argument :testarg, "Test arg", ["--testarg testarg"]
91
92
  summary "Test command execute"
92
- def execute; 1; end
93
+ alias_action :exe, :deprecated => true
94
+ def execute(testarg); 1; end
95
+
96
+ argument :args, "Test arg list", [], :arg_type => :list
97
+ summary "Test command execute_list"
98
+ def execute_list(*args); 1; end
99
+
100
+ def raise_error
101
+ raise StandardError.new("test exception")
102
+ end
93
103
  def raise_exception
94
104
  raise Exception.new("test exception")
95
105
  end
@@ -98,7 +108,7 @@ describe RHC::Commands::Base do
98
108
  Static
99
109
  end
100
110
 
101
- it("should register itself") { expect { subject }.to change(commands, :length).by(3) }
111
+ it("should register itself") { expect { subject }.to change(commands, :length).by(5) }
102
112
  it("should have an object name of the class") { subject.object_name.should == 'static' }
103
113
 
104
114
  context 'and when test is called' do
@@ -122,13 +132,58 @@ describe RHC::Commands::Base do
122
132
  it { expects_running('static', 'execute').should exit_with_code(1) }
123
133
  end
124
134
 
135
+ 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']) }
138
+ end
139
+
140
+ context 'and when an error is raised in a call' do
141
+ it { expects_running('static', 'raise_error').should raise_error(StandardError, "test exception") }
142
+ end
143
+
125
144
  context 'and when an exception is raised in a call' do
126
- it { expects_running('static', 'raise_exception').should exit_with_code(128) }
145
+ it { expects_running('static', 'raise_exception').should raise_error(Exception, "test exception") }
127
146
  end
128
147
 
129
148
  context 'and when an exception is raised in a call with --trace option' do
130
149
  it { expects_running('static', 'raise_exception', "--trace").should raise_error(Exception, "test exception") }
131
150
  end
151
+
152
+ context 'and when deprecated alias is called' do
153
+ it do
154
+ expects_running('static', 'exe', "arg").should call(:execute).on(instance).with('arg')
155
+ $stderr.seek(0)
156
+ $stderr.read.should match("Warning: The command 'rhc static exe' is deprecated. Please use 'rhc static execute' instead.")
157
+ end
158
+ end
159
+
160
+ context 'and when deprecated alias is called with DISABLE_DEPRECATED env var' do
161
+ before { ENV['DISABLE_DEPRECATED'] = '1' }
162
+ after { ENV['DISABLE_DEPRECATED'] = nil }
163
+ it { expects_running('static', 'exe', 'arg', '--trace').should raise_error(RHC::DeprecatedError) }
164
+ end
165
+ end
166
+ end
167
+
168
+ describe "rest_client" do
169
+ before do
170
+ FakeFS.activate!
171
+ RHC::Rest::Client.stub!(:new) { |openshift_rest_node, username, password, debug| @username = username; @password = password; true}
172
+ end
173
+
174
+ 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!
132
186
  end
133
187
  end
188
+
134
189
  end