rhc 1.8.9 → 1.9.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/bin/rhc CHANGED
@@ -12,6 +12,8 @@ def get_args
12
12
  end
13
13
 
14
14
  begin
15
+ Signal.trap("PIPE", "EXIT") if Signal.list["PIPE"]
16
+
15
17
  retcode = begin
16
18
  require 'rhc/cli'
17
19
  RHC::CLI.set_terminal
data/lib/rhc.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # require 'rhc/version' #FIXME gem should know version
2
- # FIXME Remove rubygems from requirements, ensure library is correct
3
2
 
4
3
  # Only require external gem dependencies here
5
4
  require 'logger'
@@ -22,6 +22,15 @@ module RHC
22
22
  false
23
23
  end
24
24
 
25
+ def options_parse_debug
26
+ if @args.include?("-d") or @args.include?("--debug")
27
+ @args.delete "-d"
28
+ @args.delete "--debug"
29
+ return true
30
+ end
31
+ false
32
+ end
33
+
25
34
  def options_parse_version
26
35
  if @args.include? "--version"
27
36
  say version
@@ -43,18 +52,12 @@ module RHC
43
52
  def run!
44
53
  trace = false
45
54
  require_program :version, :description
46
- #trap('INT') { abort program(:int_message) } if program(:int_message)
47
- #trap('INT') { program(:int_block).call } if program(:int_block)
48
55
 
49
56
  global_option('-h', '--help', 'Help on any command', :hide => true)
50
57
  global_option('--version', 'Display version information', :hide => true)
51
58
 
52
- # remove these because we monkey patch Commands to process all options
53
- # at once, avoiding conflicts between the global and command options
54
- # code left here just in case someone compares this with the original
55
- # commander code
56
- #parse_global_options
57
- #remove_global_options options, @args
59
+ # special case --debug so all commands can output relevant info on it
60
+ $terminal.debug = options_parse_debug
58
61
 
59
62
  # special case --trace because we need to use it in the runner
60
63
  trace = options_parse_trace
@@ -46,6 +46,7 @@ module Commander
46
46
  begin
47
47
  @config = RHC::Config.new
48
48
  @config.use_config(config_path) if config_path
49
+ $terminal.debug("Using config file #{@config.config_path}")
49
50
 
50
51
  unless clean
51
52
  @config.to_options.each_pair do |key, value|
@@ -51,10 +51,6 @@ class RHC::Commands::Base
51
51
  raise ArgumentError, "Please specify an action to take"
52
52
  end
53
53
 
54
- def debug?
55
- @options.debug
56
- end
57
-
58
54
  class InvalidCommand < StandardError ; end
59
55
 
60
56
  def self.inherited(klass)
@@ -85,7 +85,9 @@ module RHC::Commands
85
85
  say "Checking available ports ... "
86
86
 
87
87
  Net::SSH.start(ssh_uri.host, ssh_uri.user) do |ssh|
88
- ssh.exec! "rhc-list-ports" do |channel, stream, data|
88
+ # If a specific gear is targeted, do not include remote (e.g. database) ports
89
+ list_ports_cmd = "rhc-list-ports#{options.gear ? ' --exclude-remote' : ''}"
90
+ ssh.exec! list_ports_cmd do |channel, stream, data|
89
91
  if stream == :stderr
90
92
  data.each_line do |line|
91
93
  line.chomp!
@@ -5,7 +5,7 @@ module RHC
5
5
 
6
6
  module ConfigEnv
7
7
  def conf_name
8
- 'express.conf'
8
+ "#{ENV['OPENSHIFT_CONFIG'].presence || 'express'}.conf"
9
9
  end
10
10
  def home_conf_dir
11
11
  File.join(home_dir, '.openshift')
@@ -198,14 +198,14 @@ module RHC
198
198
  $stdout.tty? and not options.noprompt
199
199
  end
200
200
 
201
- def debug(msg)
202
- $stderr.puts "DEBUG: #{msg}" if debug?
201
+ def debug(*args)
202
+ $terminal.debug(*args)
203
203
  end
204
- def debug_error(e)
205
- debug "#{e.message} (#{e.class})\n #{e.backtrace.join("\n ")}"
204
+ def debug_error(*args)
205
+ $terminal.debug_error(*args)
206
206
  end
207
207
  def debug?
208
- false
208
+ $terminal.debug?
209
209
  end
210
210
 
211
211
  def disable_deprecated?
@@ -295,6 +295,7 @@ module RHC
295
295
  :connection_info => "Connection URL",
296
296
  :gear_profile => "Gear Size",
297
297
  :visible_to_ssh? => 'Available',
298
+ :downloaded_cartridge_url => 'From',
298
299
  })
299
300
 
300
301
  headings[value]
@@ -4,6 +4,8 @@ require 'delegate'
4
4
  # Add specific improved functionality
5
5
  #
6
6
  class HighLineExtension < HighLine
7
+ attr_writer :debug
8
+
7
9
  [:ask, :agree].each do |sym|
8
10
  define_method(sym) do |*args, &block|
9
11
  separate_blocks
@@ -13,6 +15,16 @@ class HighLineExtension < HighLine
13
15
  end
14
16
  end
15
17
 
18
+ def debug(msg)
19
+ $stderr.puts "DEBUG: #{msg}" if debug?
20
+ end
21
+ def debug_error(e)
22
+ debug "#{e.message} (#{e.class})\n #{e.backtrace.join("\n ")}"
23
+ end
24
+ def debug?
25
+ @debug
26
+ end
27
+
16
28
  # OVERRIDE
17
29
  def say(msg)
18
30
  if msg.respond_to? :to_str
@@ -392,19 +404,28 @@ class HighLine::Table
392
404
 
393
405
  def header_rows
394
406
  @header_rows ||= begin
395
- headers << column_widths.map{ |w| '-' * (w.set > 0 ? w.set : w.max) } if headers.present?
407
+ headers << widths.map{ |w| '-' * w } if headers.present?
396
408
  headers
397
409
  end
398
410
  end
399
411
 
400
412
  def rows
401
413
  @rows ||= begin
402
- fmt = "#{indent}#{widths.zip(align).map{ |w, al| "%#{al == :right ? '' : '-'}#{w}s" }.join(joiner)}"
403
-
404
414
  body = (header_rows + source_rows).inject([]) do |a,row|
405
415
  row = row.zip(widths).map{ |column,w| w && w > 0 ? column.textwrap_ansi(w, false) : [column] }
406
416
  (row.map(&:length).max || 0).times do |i|
407
- a << (fmt % row.map{ |r| r[i] }).rstrip
417
+ s = []
418
+ row.each_with_index do |lines, j|
419
+ cell = lines[i]
420
+ l = cell ? cell.strip_ansi.length : 0
421
+ s <<
422
+ if align[j] == :right
423
+ "#{' '*(widths[j]-l) if l < widths[j]}#{cell}"
424
+ else
425
+ "#{cell}#{' '*(widths[j]-l) if l < widths[j]}"
426
+ end
427
+ end
428
+ a << "#{indent}#{s.join(joiner).rstrip}"
408
429
  end
409
430
  a
410
431
  end
@@ -90,6 +90,7 @@ module RHC
90
90
  say format_table \
91
91
  format_cart_header(cart),
92
92
  get_properties(cart, *properties).
93
+ concat([[:downloaded_cartridge_url, cart.url]]).
93
94
  concat([[cart.scalable? ? :scaling : :gears, format_cart_gears(cart)]]).
94
95
  concat(cart.properties.map{ |p| ["#{table_heading(p['name'])}:", p['value']] }.sort{ |a,b| a[0] <=> b[0] }),
95
96
  :delete => true
@@ -113,6 +113,8 @@ module RHC
113
113
 
114
114
  class MultipleCartridgeCreationNotSupported < Exception; end
115
115
 
116
+ class DownloadingCartridgesNotSupported < Exception; end
117
+
116
118
  class InitialGitUrlNotSupported < Exception; end
117
119
 
118
120
  class SslCertificatesNotSupported < Exception; end
@@ -10,30 +10,24 @@ module RHC
10
10
 
11
11
  def destroy
12
12
  debug "Deleting alias #{self.id}"
13
- rest_method "DELETE"
13
+ rest_method :delete
14
14
  end
15
15
  alias :delete :destroy
16
16
 
17
17
  def add_certificate(ssl_certificate_content, private_key_content, pass_phrase)
18
18
  debug "Running add_certificate for alias #{@id}"
19
- if (client.api_version_negotiated >= 1.4)
20
- foo = rest_method "UPDATE", {
21
- :ssl_certificate => ssl_certificate_content,
22
- :private_key => private_key_content,
23
- :pass_phrase => pass_phrase
24
- }
25
- else
26
- raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases."
27
- end
19
+ raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases." unless supports? :update
20
+ foo = rest_method :update, {
21
+ :ssl_certificate => ssl_certificate_content,
22
+ :private_key => private_key_content,
23
+ :pass_phrase => pass_phrase
24
+ }
28
25
  end
29
26
 
30
27
  def delete_certificate
31
28
  debug "Running delete_certificate for alias #{@id}"
32
- if (client.api_version_negotiated >= 1.4)
33
- rest_method "UPDATE", {}
34
- else
35
- raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases."
36
- end
29
+ raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases." unless supports? :update
30
+ rest_method :update, {}
37
31
  end
38
32
 
39
33
  def <=>(a)
@@ -24,25 +24,32 @@ module RHC
24
24
  def add_cartridge(cart, options={})
25
25
  debug "Adding cartridge #{name}"
26
26
  clear_attribute :cartridges
27
- rest_method(
28
- "ADD_CARTRIDGE",
27
+ cart =
29
28
  if cart.is_a? String
30
29
  {:name => cart}
31
30
  elsif cart.respond_to? :[]
32
31
  cart
33
32
  else
34
33
  cart.url ? {:url => cart.url} : {:name => cart.name}
35
- end,
34
+ end
35
+
36
+ if cart.respond_to?(:[]) and cart[:url] and !has_param?('ADD_CARTRIDGE', 'url')
37
+ raise RHC::Rest::DownloadingCartridgesNotSupported, "The server does not support downloading cartridges."
38
+ end
39
+
40
+ rest_method(
41
+ "ADD_CARTRIDGE",
42
+ cart,
36
43
  options
37
44
  )
38
45
  end
39
46
 
40
47
  def cartridges
41
- debug "Getting all cartridges for application #{name}"
42
48
  @cartridges ||=
43
49
  unless (carts = attributes['cartridges']).nil?
44
50
  carts.map{|x| Cartridge.new(x, client) }
45
51
  else
52
+ debug "Getting all cartridges for application #{name}"
46
53
  rest_method "LIST_CARTRIDGES"
47
54
  end
48
55
  end
@@ -17,7 +17,7 @@ module RHC
17
17
  end
18
18
 
19
19
  def rest_method(link_name, payload={}, options={})
20
- link = links[link_name.to_s]
20
+ link = link(link_name)
21
21
  raise "No link defined for #{link_name}" unless link
22
22
  url = link['href']
23
23
  url = url.gsub(/:\w+/) { |s| options[:params][s] } if options[:params]
@@ -35,12 +35,22 @@ module RHC
35
35
  end
36
36
 
37
37
  def supports?(sym)
38
- !!(links[sym.to_s] || links[sym.to_s.upcase])
38
+ !!link(sym)
39
+ end
40
+
41
+ def has_param?(sym, name)
42
+ if l = link(sym)
43
+ (l['required_params'] || []).any?{ |p| p['name'] == name} or (l['optional_params'] || []).any?{ |p| p['name'] == name}
44
+ end
39
45
  end
40
46
 
41
47
  protected
42
48
  attr_reader :client
43
49
 
50
+ def link(sym)
51
+ (links[sym.to_s] || links[sym.to_s.upcase])
52
+ end
53
+
44
54
  def debug(msg, obj=nil)
45
55
  client.debug("#{msg}#{obj ? " #{obj}" : ''}") if client && client.debug?
46
56
  end
@@ -3,7 +3,9 @@ module RHC
3
3
  class Cartridge < Base
4
4
  HIDDEN_TAGS = [:framework, :web_framework, :cartridge].map(&:to_s)
5
5
 
6
- define_attr :type, :name, :display_name, :properties, :gear_profile, :status_messages, :scales_to, :scales_from, :scales_with, :current_scale, :supported_scales_to, :supported_scales_from, :tags, :description, :collocated_with, :base_gear_storage, :additional_gear_storage, :url
6
+ define_attr :type, :name, :display_name, :properties, :gear_profile, :status_messages, :scales_to, :scales_from, :scales_with,
7
+ :current_scale, :supported_scales_to, :supported_scales_from, :tags, :description, :collocated_with, :base_gear_storage,
8
+ :additional_gear_storage, :url
7
9
 
8
10
  def scalable?
9
11
  supported_scales_to != supported_scales_from
@@ -36,26 +36,10 @@ module RHC
36
36
  @user ||= api.rest_method "GET_USER"
37
37
  end
38
38
 
39
- def sshkeys
40
- debug "Finding all keys for #{user.login}"
41
- user.keys
42
- end
43
-
44
- def add_key(name, key, content)
45
- debug "Adding key #{key} for #{user.login}"
46
- user.add_key name, key, content
47
- end
48
-
49
- def delete_key(name)
50
- debug "Deleting key '#{name}'"
51
- key = find_key(name)
52
- key.destroy
53
- end
54
-
55
39
  #Find Domain by namesapce
56
40
  def find_domain(id)
57
41
  debug "Finding domain #{id}"
58
- domains.each { |domain| return domain if domain.id == id }
42
+ domains.each { |domain| return domain if domain.id.downcase == id.downcase }
59
43
 
60
44
  raise DomainNotFoundException.new("Domain #{id} not found")
61
45
  end
@@ -120,17 +104,17 @@ module RHC
120
104
  end
121
105
 
122
106
  def sshkeys
123
- logger.debug "Finding all keys for #{user.login}" if @mydebug
107
+ debug "Finding all keys for #{user.login}"
124
108
  user.keys
125
109
  end
126
110
 
127
111
  def add_key(name, key, content)
128
- logger.debug "Adding key #{key} for #{user.login}" if @mydebug
112
+ debug "Adding key #{key} for #{user.login}"
129
113
  user.add_key name, key, content
130
114
  end
131
115
 
132
116
  def delete_key(name)
133
- logger.debug "Deleting key '#{name}'" if @mydebug
117
+ debug "Deleting key '#{name}'"
134
118
  key = find_key(name)
135
119
  key.destroy
136
120
  end
@@ -182,12 +166,6 @@ module RHC
182
166
  h
183
167
  end
184
168
  end
185
-
186
- def logout
187
- #TODO logout
188
- debug "Logout/Close client"
189
- end
190
- alias :close :logout
191
169
  end
192
170
 
193
171
  class Client < Base
@@ -234,10 +212,6 @@ module RHC
234
212
  debug "Connecting to #{@end_point}"
235
213
  end
236
214
 
237
- def debug?
238
- @debug
239
- end
240
-
241
215
  def url
242
216
  @end_point
243
217
  end
@@ -260,9 +234,9 @@ module RHC
260
234
  auth = options[:auth] || self.auth
261
235
  response = nil
262
236
 
263
- debug "Request #{args[0].to_s.upcase} #{args[1]}#{"?#{args[2].map{|a| a.join('=')}.join(' ')}" if args[2] && args[0] == 'GET'}" if debug?
237
+ debug "Request #{args[0].to_s.upcase} #{args[1]}#{"?#{args[2].map{|a| a.join('=')}.join(' ')}" if args[2] && args[0] == 'GET'}"
264
238
  time = Benchmark.realtime{ response = client.request(*(args << true)) }
265
- debug " code %s %4i ms" % [response.status, (time*1000).to_i] if debug? && response
239
+ debug " code %s %4i ms" % [response.status, (time*1000).to_i] if response
266
240
 
267
241
  next if retry_proxy(response, i, args, client)
268
242
  auth.retry_auth?(response, self) and next if auth
@@ -335,10 +309,7 @@ module RHC
335
309
  rescue RHC::Rest::Exception
336
310
  raise
337
311
  rescue => e
338
- if debug?
339
- logger.debug "#{e.message} (#{e.class})"
340
- logger.debug e.backtrace.join("\n ")
341
- end
312
+ debug_error(e)
342
313
  raise ConnectionException.new("An unexpected error occured: #{e.message}").tap{ |n| n.set_backtrace(e.backtrace) }
343
314
  end
344
315
  end
@@ -389,9 +360,9 @@ module RHC
389
360
  cert = ctx.current_cert
390
361
  if cert && (cert.subject.cmp(cert.issuer) == 0)
391
362
  @self_signed = true
392
- debug "SSL Verification failed -- Using self signed cert" if debug?
363
+ debug "SSL Verification failed -- Using self signed cert"
393
364
  else
394
- debug "SSL Verification failed -- Preverify: #{is_ok}, Error: #{ctx.error_string} (#{ctx.error})" if debug?
365
+ debug "SSL Verification failed -- Preverify: #{is_ok}, Error: #{ctx.error_string} (#{ctx.error})"
395
366
  end
396
367
  return false
397
368
  end
@@ -456,7 +427,7 @@ module RHC
456
427
 
457
428
  def retry_proxy(response, i, args, client)
458
429
  if response.status == 502
459
- debug "ERROR: Received bad gateway from server, will retry once if this is a GET" if debug?
430
+ debug "ERROR: Received bad gateway from server, will retry once if this is a GET"
460
431
  return true if i == 0 && args[0] == :get
461
432
  raise ConnectionException.new(
462
433
  "An error occurred while communicating with the server. This problem may only be temporary."\
@@ -529,7 +500,7 @@ module RHC
529
500
  m.blank?
530
501
  end
531
502
  rescue => e
532
- logger.debug "Response did not include a message from server: #{e.message}" if debug?
503
+ debug "Response did not include a message from server: #{e.message}"
533
504
  end
534
505
  case response.status
535
506
  when 400
@@ -571,10 +542,6 @@ module RHC
571
542
  end
572
543
 
573
544
  private
574
- def logger
575
- @logger ||= Logger.new(STDOUT)
576
- end
577
-
578
545
  def messages_to_error(messages)
579
546
  errors, remaining = messages.partition{ |m| (m['severity'] || "").upcase == 'ERROR' }
580
547
  if errors.present?
@@ -598,7 +565,7 @@ module RHC
598
565
  # HTTPClient, being sure to add the http protocol
599
566
  # if not specified already
600
567
  proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
601
- ENV['http_proxy'] = "http://#{proxy}" if proxy && proxy !~ /^(\w+):\/\//
568
+ ENV['http_proxy'] = "http://#{proxy}" if proxy.present? && proxy !~ /^(\w+):\/\//
602
569
  end
603
570
  end
604
571
  end
@@ -22,6 +22,11 @@ module RHC
22
22
  cart.url ? {:url => cart.url} : cart.name
23
23
  end
24
24
  end.compact.uniq
25
+
26
+ if cartridges.any?{ |c| c.is_a?(Hash) and c[:url] } and !has_param?('ADD_APPLICATION', 'cartridges[][url]')
27
+ raise RHC::Rest::DownloadingCartridgesNotSupported, "The server does not support downloading cartridges."
28
+ end
29
+
25
30
  if client.api_version_negotiated >= 1.3
26
31
  payload[:cartridges] = cartridges
27
32
  else
@@ -29,7 +34,7 @@ module RHC
29
34
  payload[:cartridge] = cartridges.first
30
35
  end
31
36
 
32
- if client.api_version_negotiated < 1.3 && payload[:initial_git_url]
37
+ if payload[:initial_git_url] and !has_param?('ADD_APPLICATION', 'initial_git_url')
33
38
  raise RHC::Rest::InitialGitUrlNotSupported, "The server does not support creating applications from a source repository."
34
39
  end
35
40
 
@@ -161,14 +161,14 @@ module RHC::Rest::Mock
161
161
  def stub_no_domains
162
162
  stub_api_request(:get, 'broker/rest/domains', mock_user_auth).to_return(empty_domains)
163
163
  end
164
- def stub_one_domain(name)
164
+ def stub_one_domain(name, optional_params=nil)
165
165
  stub_api_request(:get, 'broker/rest/domains', mock_user_auth).
166
166
  to_return({
167
167
  :body => {
168
168
  :type => 'domains',
169
169
  :data => [{:id => name, :links => mock_response_links([
170
170
  ['LIST_APPLICATIONS', "broker/rest/domains/#{name}/applications", 'get'],
171
- ['ADD_APPLICATION', "broker/rest/domains/#{name}/applications", 'post'],
171
+ ['ADD_APPLICATION', "broker/rest/domains/#{name}/applications", 'post', ({:optional_params => optional_params} if optional_params)],
172
172
  ])}],
173
173
  }.to_json
174
174
  })
@@ -313,16 +313,11 @@ module RHC::Rest::Mock
313
313
  "https://#{uri_string}/#{relative}"
314
314
  end
315
315
 
316
- # This formats link lists for JSONification
317
316
  def mock_response_links(links)
318
317
  link_set = {}
319
318
  links.each do |link|
320
- operation = link[0]
321
- href = link[1]
322
- method = link[2]
323
- # Note that the 'relative' key/value pair below is a convenience for testing;
324
- # this is not used by the API classes.
325
- link_set[operation] = { 'href' => mock_href(href), 'method' => method, 'relative' => href }
319
+ options = link[3] || {}
320
+ link_set[link[0]] = { 'href' => mock_href(link[1]), 'method' => link[2], 'relative' => link[1]}.merge(options)
326
321
  end
327
322
  link_set
328
323
  end
@@ -45,7 +45,6 @@ module RHC
45
45
  def initialize(config=RHC::Config.new, opts=Commander::Command::Options.new)
46
46
  @config = config
47
47
  @options = opts
48
- @debug = opts.debug if opts
49
48
  end
50
49
 
51
50
  # Public: Runs the setup wizard to make sure ~/.openshift and ~/.ssh are correct
@@ -76,10 +75,6 @@ module RHC
76
75
  attr_accessor :auth, :user
77
76
  attr_writer :rest_client
78
77
 
79
- def debug?
80
- @debug
81
- end
82
-
83
78
  def hostname
84
79
  Socket.gethostname
85
80
  end
@@ -522,6 +522,20 @@ describe RHC::Commands::App do
522
522
  it { run_output.should match(/Gears:\s+Located with mock_type/) }
523
523
  it { run_output.should match(/Gears:\s+1 medium/) }
524
524
  end
525
+
526
+ context 'when run with custom app' do
527
+ before(:each) do
528
+ @domain = rest_client.add_domain("mockdomain")
529
+ app = @domain.add_application("app1", "mock_type", true)
530
+ cart1 = app.add_cartridge('mock_cart-1')
531
+ cart1.url = 'https://foo.bar.com'
532
+ end
533
+ it { run_output.should match("app1 @ https://app1-mockdomain.fake.foo/") }
534
+ it { run_output.should match(/Scaling:.*x2/) }
535
+ it { run_output.should match(/Gears:\s+Located with mock_type/) }
536
+ it { run_output.should match(/Gears:\s+1 small/) }
537
+ it { run_output.should match(%r(From:\s+ https://foo.bar.com)) }
538
+ end
525
539
  end
526
540
 
527
541
  describe 'app show' do
@@ -181,7 +181,7 @@ describe RHC::Commands::PortForward do
181
181
  @gear_id = 'fakegearid'
182
182
  Net::SSH.should_receive(:start).with(gear_host, gear_user).and_yield(@ssh).twice
183
183
 
184
- @ssh.should_receive(:exec!).with("rhc-list-ports").
184
+ @ssh.should_receive(:exec!).with("rhc-list-ports --exclude-remote").
185
185
  and_yield(nil, :stderr, "mongodb -> #{gear_host}:35541")
186
186
  forward = mock(Net::SSH::Service::Forward)
187
187
  @ssh.should_receive(:forward).and_return(forward)
@@ -71,7 +71,7 @@ describe RHC::Helpers do
71
71
  it_should_behave_like "colorized output"
72
72
  end
73
73
 
74
- it("should invoke debug from debug_error"){ expect{ subject.debug_error(mock(:class => "Mock", :message => 'msg', :backtrace => [])) }.to call(:debug).on(subject).with("msg (Mock)\n ") }
74
+ it("should invoke debug from debug_error"){ expect{ subject.debug_error(mock(:class => "Mock", :message => 'msg', :backtrace => [])) }.to call(:debug).on($terminal).with("msg (Mock)\n ") }
75
75
 
76
76
  it("should draw a table") do
77
77
  subject.table([[10,2], [3,40]]) do |i|
@@ -182,6 +182,14 @@ describe HighLineExtension do
182
182
  ]
183
183
  end
184
184
 
185
+ it "should give the header priority over width when color is involved" do
186
+ subject.table([["\e[31mabcd\e[0m", "1234567890"]], :header => ['abcdef', '123'], :width => 12).to_a.should == [
187
+ 'abcdef 123',
188
+ '------ ----------',
189
+ "\e[31mabcd\e[0m 1234567890",
190
+ ]
191
+ end
192
+
185
193
  it "should add a header to a table" do
186
194
  subject.table([["abcd efgh", "1234 6789 a"]], :width => 9, :heading => "Alongtextstring").to_a.should == [
187
195
  "Alongtext",
@@ -75,7 +75,12 @@ module RHC
75
75
 
76
76
  context "with a URL cart" do
77
77
  before{ stub_api_request(:any, app_links['ADD_CARTRIDGE']['relative']).with(:body => {:url => 'http://foo.com'}.to_json).to_return(mock_cartridge_response(1, true)) }
78
+ it "raises without a param" do
79
+ app_obj.should_receive(:has_param?).with('ADD_CARTRIDGE','url').and_return(false)
80
+ expect{ app_obj.add_cartridge({:url => 'http://foo.com'}) }.to raise_error(RHC::Rest::DownloadingCartridgesNotSupported)
81
+ end
78
82
  it "accepts a hash" do
83
+ app_obj.should_receive(:has_param?).with('ADD_CARTRIDGE','url').and_return(true)
79
84
  cart = app_obj.add_cartridge({:url => 'http://foo.com'})
80
85
  cart.should be_an_instance_of RHC::Rest::Cartridge
81
86
  cart.name.should == 'mock_cart_0'
@@ -86,6 +91,7 @@ module RHC
86
91
  cart.only_in_existing?.should be_false
87
92
  end
88
93
  it "accepts an object" do
94
+ app_obj.should_receive(:has_param?).with('ADD_CARTRIDGE','url').and_return(true)
89
95
  cart = app_obj.add_cartridge(stub(:url => 'http://foo.com'))
90
96
  cart.should be_an_instance_of RHC::Rest::Cartridge
91
97
  cart.name.should == 'mock_cart_0'
@@ -4,20 +4,6 @@ require 'stringio'
4
4
  require 'rest_spec_helper'
5
5
  require 'rhc/rest'
6
6
 
7
- # This object is used in a few cases where we need to inspect
8
- # the logged output.
9
- class MockClient < RHC::Rest::Client
10
- def logger
11
- Logger.new((@output = StringIO.new))
12
- end
13
- def use_debug
14
- @debug = true
15
- end
16
- def logged
17
- @output.string
18
- end
19
- end
20
-
21
7
  module RHC
22
8
  module Rest
23
9
  describe Client do
@@ -228,7 +214,12 @@ module RHC
228
214
  it "returns a domain object for matching domain IDs" do
229
215
  match = nil
230
216
  expect { match = client.find_domain('mock_domain_0') }.to_not raise_error
231
-
217
+ match.id.should == 'mock_domain_0'
218
+ match.class.should == RHC::Rest::Domain
219
+ end
220
+ it "returns a domain object for matching case-insensitive domain IDs" do
221
+ match = nil
222
+ expect { match = client.find_domain('MOCK_DOMAIN_0') }.to_not raise_error
232
223
  match.id.should == 'mock_domain_0'
233
224
  match.class.should == RHC::Rest::Domain
234
225
  end
@@ -458,32 +449,6 @@ module RHC
458
449
  end
459
450
  end
460
451
 
461
- shared_examples_for "a logout method" do
462
- before(:each) do
463
- stub_api_request(:get, '').
464
- to_return({ :body => { :data => client_links, :supported_api_versions => [1.0, 1.1] }.to_json,
465
- :status => 200
466
- })
467
- end
468
- context "debug mode is on" do
469
- let(:use_debug){ true }
470
- it "writes a message to the logger" do
471
- capture do
472
- client.send logout_method.to_sym
473
- stderr.should match(/Logout\/Close client$/)
474
- end
475
- end
476
- end
477
- context "debug mode is off" do
478
- it "does nothing" do
479
- capture do
480
- client.send logout_method.to_sym
481
- stderr.should be_empty
482
- end
483
- end
484
- end
485
- end
486
-
487
452
  context "#delete_key" do
488
453
  before(:each) do
489
454
  stub_api_request(:any, client_links['GET_USER']['relative']).
@@ -528,16 +493,6 @@ module RHC
528
493
  expect { client.find_key('no_match') }.to raise_error(RHC::KeyNotFoundException)
529
494
  end
530
495
  end
531
-
532
- context "#logout" do
533
- let(:logout_method) { :logout }
534
- it_should_behave_like "a logout method"
535
- end
536
-
537
- context "#close" do
538
- let(:logout_method) { :close }
539
- it_should_behave_like "a logout method"
540
- end
541
496
  end
542
497
 
543
498
  context "when server supports API versions 1.0 and 1.1" do
@@ -2,16 +2,6 @@ require 'spec_helper'
2
2
  require 'rest_spec_helper'
3
3
  require 'rhc/rest'
4
4
 
5
- class RHCRest
6
- include RHC::Rest
7
- def debug?
8
- false
9
- end
10
- def debug(*args)
11
- raise "Unchecked debug"
12
- end
13
- end
14
-
15
5
  module MockRestResponse
16
6
  attr_accessor :code, :read
17
7
  end
@@ -44,13 +34,14 @@ describe RHC::Rest::Domain do
44
34
  it{ domain.add_application('foo', :cartridges => ['bar']).should be_true }
45
35
  it{ expect{ domain.add_application('foo', :cartridges => ['bar', 'other']) }.to raise_error(RHC::Rest::MultipleCartridgeCreationNotSupported) }
46
36
  it{ expect{ domain.add_application('foo', :initial_git_url => 'a_url') }.to raise_error(RHC::Rest::InitialGitUrlNotSupported) }
37
+ it{ expect{ domain.add_application('foo', :cartridges => [{:url => 'a_url'}]) }.to raise_error(RHC::Rest::DownloadingCartridgesNotSupported) }
47
38
  it{ domain.add_application('foo', :cartridges => 'bar').should be_true }
48
39
  it{ domain.add_application('foo', :cartridge => 'bar').should be_true }
49
40
  it{ domain.add_application('foo', :cartridge => ['bar']).should be_true }
50
41
  end
51
- context "against a server newer than 1.3" do
42
+ context "against a server that supports initial git urls and downloaded carts" do
52
43
  let(:cartridges){ ['bar'] }
53
- before{ stub_api; stub_one_domain('bar') }
44
+ before{ stub_api; stub_one_domain('bar', [{:name => 'initial_git_url'},{:name => 'cartridges[][url]'}]) }
54
45
  before do
55
46
  stub_api_request(:post, 'broker/rest/domains/bar/applications', false).
56
47
  with(:body => {:name => 'foo', :cartridges => cartridges}.to_json).
@@ -95,17 +86,6 @@ module RHC
95
86
  describe Rest do
96
87
  subject{ RHC::Rest::Client.new }
97
88
 
98
- # logger function
99
- describe "#logger" do
100
- it "establishes a logger" do
101
- logger = Logger.new(STDOUT)
102
- subject.send(:logger).should have_same_attributes_as(logger)
103
- end
104
- it "reuses a logger" do
105
- subject.send(:logger).should equal(subject.send(:logger))
106
- end
107
- end
108
-
109
89
  describe "#default_verify_callback" do
110
90
  def invoked_with(is_ok, ctx)
111
91
  subject.send(:default_verify_callback).call(is_ok, ctx)
@@ -8,6 +8,7 @@ require 'pry' if ENV['PRY']
8
8
  # Environment reset
9
9
  ENV['http_proxy'] = nil
10
10
  ENV['HTTP_PROXY'] = nil
11
+ ENV['OPENSHIFT_CONFIG'] = nil
11
12
 
12
13
  class FakeFS::Mode
13
14
  def initialize(mode_s)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 8
9
8
  - 9
10
- version: 1.8.9
9
+ - 6
10
+ version: 1.9.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Red Hat
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-05-10 00:00:00 Z
18
+ date: 2013-06-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: net-ssh