rhc 1.12.4 → 1.13.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rhc/rest/mock.rb CHANGED
@@ -64,7 +64,7 @@ module RHC::Rest::Mock
64
64
  to_return({
65
65
  :body => {
66
66
  :data => mock_response_links(authorizations ? mock_api_with_authorizations : mock_real_client_links),
67
- :supported_api_versions => [1.0, 1.1, 1.2, 1.3, 1.4, 1.5],
67
+ :supported_api_versions => [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6],
68
68
  }.to_json
69
69
  })
70
70
  end
@@ -357,17 +357,19 @@ module RHC::Rest::Mock
357
357
  end
358
358
 
359
359
  def mock_app_links(domain_id='test_domain',app_id='test_app')
360
- [['ADD_CARTRIDGE', "domains/#{domain_id}/apps/#{app_id}/carts/add", 'post'],
361
- ['LIST_CARTRIDGES', "broker/rest/domains/#{domain_id}/applications/#{app_id}/cartridges",'get' ],
362
- ['GET_GEAR_GROUPS', "domains/#{domain_id}/apps/#{app_id}/gear_groups", 'get' ],
363
- ['START', "domains/#{domain_id}/apps/#{app_id}/start", 'post'],
364
- ['STOP', "domains/#{domain_id}/apps/#{app_id}/stop", 'post'],
365
- ['RESTART', "domains/#{domain_id}/apps/#{app_id}/restart", 'post'],
366
- ['THREAD_DUMP', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
367
- ['ADD_ALIAS', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
368
- ['REMOVE_ALIAS', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
369
- ['LIST_ALIASES', "domains/#{domain_id}/apps/#{app_id}/aliases", 'get'],
370
- ['DELETE', "broker/rest/domains/#{domain_id}/applications/#{app_id}", 'DELETE']]
360
+ [['ADD_CARTRIDGE', "domains/#{domain_id}/apps/#{app_id}/carts/add", 'post'],
361
+ ['LIST_CARTRIDGES', "broker/rest/domains/#{domain_id}/applications/#{app_id}/cartridges", 'get' ],
362
+ ['GET_GEAR_GROUPS', "domains/#{domain_id}/apps/#{app_id}/gear_groups", 'get' ],
363
+ ['START', "domains/#{domain_id}/apps/#{app_id}/start", 'post'],
364
+ ['STOP', "domains/#{domain_id}/apps/#{app_id}/stop", 'post'],
365
+ ['RESTART', "domains/#{domain_id}/apps/#{app_id}/restart", 'post'],
366
+ ['THREAD_DUMP', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
367
+ ['ADD_ALIAS', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
368
+ ['REMOVE_ALIAS', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
369
+ ['LIST_ALIASES', "domains/#{domain_id}/apps/#{app_id}/aliases", 'get'],
370
+ ['LIST_ENVIRONMENT_VARIABLES', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
371
+ ['SET_UNSET_ENVIRONMENT_VARIABLES', "domains/#{domain_id}/apps/#{app_id}/event", 'post'],
372
+ ['DELETE', "broker/rest/domains/#{domain_id}/applications/#{app_id}", 'DELETE']]
371
373
  end
372
374
 
373
375
  def mock_cart_links(domain_id='test_domain',app_id='test_app',cart_id='test_cart')
@@ -383,6 +385,7 @@ module RHC::Rest::Mock
383
385
  ['LIST_DOMAINS', 'domains/', 'get' ],
384
386
  ['LIST_CARTRIDGES', 'cartridges/', 'get' ]]
385
387
  end
388
+
386
389
  def mock_real_client_links
387
390
  [['GET_USER', "broker/rest/user", 'GET'],
388
391
  ['LIST_DOMAINS', "broker/rest/domains", 'GET'],
@@ -390,6 +393,7 @@ module RHC::Rest::Mock
390
393
  ['LIST_CARTRIDGES', "broker/rest/cartridges", 'GET'],
391
394
  ]
392
395
  end
396
+
393
397
  def mock_api_with_authorizations
394
398
  mock_real_client_links.concat([
395
399
  ['LIST_AUTHORIZATIONS', "broker/rest/user/authorizations", 'GET'],
@@ -517,10 +521,10 @@ module RHC::Rest::Mock
517
521
  MockRestCartridge.new(self, "mock_standalone_cart-1", "standalone"),
518
522
  MockRestCartridge.new(self, "mock_standalone_cart-2", "standalone"),
519
523
  MockRestCartridge.new(self, "mock_unique_standalone_cart-1", "standalone"),
520
- MockRestCartridge.new(self, "jenkins-1.4", "standalone"),
524
+ MockRestCartridge.new(self, "jenkins-1", "standalone", nil, ['ci']),
521
525
  MockRestCartridge.new(self, "mock_cart-2", "embedded"),
522
526
  MockRestCartridge.new(self, "unique_mock_cart-1", "embedded"),
523
- MockRestCartridge.new(self, "jenkins-client-1.4", "embedded"),
527
+ MockRestCartridge.new(self, "jenkins-client-1", "embedded", nil, ['ci_builder']),
524
528
  MockRestCartridge.new(self, "embcart-1", "embedded"),
525
529
  MockRestCartridge.new(self, "embcart-2", "embedded"),
526
530
  premium_embedded
@@ -645,7 +649,7 @@ module RHC::Rest::Mock
645
649
  def initialize(client=nil, carts=['name' => 'fake_geargroup_cart-0.1'], count=1)
646
650
  super({}, client)
647
651
  @cartridges = carts
648
- @gears = count.times.map do |i|
652
+ @gears = count.times.map do |i|
649
653
  {'state' => 'started', 'id' => "fakegearid#{i}", 'ssh_url' => "ssh://fakegearid#{i}@fakesshurl.com"}
650
654
  end
651
655
  @gear_profile = 'small'
@@ -694,7 +698,7 @@ module RHC::Rest::Mock
694
698
  "fakeuuidfortests#{@name}"
695
699
  end
696
700
 
697
- def initialize(client, name, type, domain, scale=nil, gear_profile='default', initial_git_url=nil)
701
+ def initialize(client, name, type, domain, scale=nil, gear_profile='default', initial_git_url=nil, environment_variables=nil)
698
702
  super({}, client)
699
703
  @name = name
700
704
  @domain = domain
@@ -706,6 +710,7 @@ module RHC::Rest::Mock
706
710
  @app_url = "https://#{@name}-#{@domain.id}.fake.foo/"
707
711
  @ssh_url = "ssh://#{@uuid}@127.0.0.1"
708
712
  @aliases = []
713
+ @environment_variables = environment_variables || []
709
714
  @gear_profile = gear_profile
710
715
  if scale
711
716
  @scalable = true
@@ -730,8 +735,8 @@ module RHC::Rest::Mock
730
735
  @domain.applications.delete self
731
736
  end
732
737
 
733
- def add_cartridge(cart, embedded=true)
734
- name, url =
738
+ def add_cartridge(cart, embedded=true, environment_variables=nil)
739
+ name, url =
735
740
  if cart.is_a? String
736
741
  [cart, nil]
737
742
  elsif cart.respond_to? :[]
@@ -742,10 +747,11 @@ module RHC::Rest::Mock
742
747
 
743
748
  type = embedded ? "embedded" : "standalone"
744
749
  c = MockRestCartridge.new(client, name, type, self)
745
- if url
750
+ if url
746
751
  c.url = url
747
752
  c.name = c.url_basename
748
753
  end
754
+ #set_environment_variables(environment_variables)
749
755
  c.properties << {'name' => 'prop1', 'value' => 'value1', 'description' => 'description1' }
750
756
  @cartridges << c
751
757
  c.messages << "Cartridge added with properties"
@@ -798,6 +804,31 @@ module RHC::Rest::Mock
798
804
  def aliases
799
805
  @aliases
800
806
  end
807
+
808
+ def environment_variables
809
+ if supports? "LIST_ENVIRONMENT_VARIABLES"
810
+ @environment_variables || []
811
+ else
812
+ raise RHC::EnvironmentVariablesNotSupportedException.new
813
+ end
814
+ end
815
+
816
+ def set_environment_variables(env_vars=[])
817
+ if supports? "SET_UNSET_ENVIRONMENT_VARIABLES"
818
+ environment_variables.concat env_vars
819
+ else
820
+ raise RHC::EnvironmentVariablesNotSupportedException.new
821
+ end
822
+ end
823
+
824
+ def unset_environment_variables(env_vars=[])
825
+ if supports? "SET_UNSET_ENVIRONMENT_VARIABLES"
826
+ env_vars.each { |item| environment_variables.delete_if { |env_var| env_var.name == item } }
827
+ else
828
+ raise RHC::EnvironmentVariablesNotSupportedException.new
829
+ end
830
+ end
831
+
801
832
  end
802
833
 
803
834
  class MockRestCartridge < RHC::Rest::Cartridge
@@ -805,11 +836,12 @@ module RHC::Rest::Mock
805
836
 
806
837
  attr_accessor :usage_rate
807
838
 
808
- def initialize(client, name, type, app=nil, properties=[{'type' => 'cart_data', 'name' => 'connection_url', 'value' => "http://fake.url" }])
839
+ def initialize(client, name, type, app=nil, tags=[], properties=[{'type' => 'cart_data', 'name' => 'connection_url', 'value' => "http://fake.url" }])
809
840
  super({}, client)
810
841
  @name = name
811
842
  @type = type
812
843
  @app = app
844
+ @tags = tags
813
845
  @properties = properties.each(&:stringify_keys!)
814
846
  @status_messages = [{"message" => "started", "gear_id" => "123"}]
815
847
  @scales_from = 1
data/lib/rhc/rest.rb CHANGED
@@ -1,21 +1,22 @@
1
1
  module RHC
2
2
  module Rest
3
3
 
4
- autoload :Base, 'rhc/rest/base'
5
- autoload :Attributes, 'rhc/rest/attributes'
6
-
7
- autoload :HTTPClient, 'rhc/rest/httpclient'
8
-
9
- autoload :Api, 'rhc/rest/api'
10
- autoload :Application, 'rhc/rest/application'
11
- autoload :Authorization, 'rhc/rest/authorization'
12
- autoload :Cartridge, 'rhc/rest/cartridge'
13
- autoload :Client, 'rhc/rest/client'
14
- autoload :Domain, 'rhc/rest/domain'
15
- autoload :Key, 'rhc/rest/key'
16
- autoload :User, 'rhc/rest/user'
17
- autoload :GearGroup, 'rhc/rest/gear_group'
18
- autoload :Alias, 'rhc/rest/alias'
4
+ autoload :Base, 'rhc/rest/base'
5
+ autoload :Attributes, 'rhc/rest/attributes'
6
+
7
+ autoload :HTTPClient, 'rhc/rest/httpclient'
8
+
9
+ autoload :Alias, 'rhc/rest/alias'
10
+ autoload :Api, 'rhc/rest/api'
11
+ autoload :Application, 'rhc/rest/application'
12
+ autoload :Authorization, 'rhc/rest/authorization'
13
+ autoload :Cartridge, 'rhc/rest/cartridge'
14
+ autoload :Client, 'rhc/rest/client'
15
+ autoload :Domain, 'rhc/rest/domain'
16
+ autoload :EnvironmentVariable, 'rhc/rest/environment_variable'
17
+ autoload :GearGroup, 'rhc/rest/gear_group'
18
+ autoload :Key, 'rhc/rest/key'
19
+ autoload :User, 'rhc/rest/user'
19
20
 
20
21
  class Exception < RuntimeError
21
22
  attr_reader :code
@@ -32,17 +33,17 @@ module RHC
32
33
  #
33
34
  #503 Service Unavailable
34
35
  #
35
- #The server is currently unable to handle the request due to a temporary
36
- #overloading or maintenance of the server. The implication is that this
36
+ #The server is currently unable to handle the request due to a temporary
37
+ #overloading or maintenance of the server. The implication is that this
37
38
  #is a temporary condition which will be alleviated after some delay.
38
39
  class ServiceUnavailableException < ServerErrorException; end
39
40
 
40
- #Exceptions thrown in case of an HTTP 4xx is received with the exception
41
+ #Exceptions thrown in case of an HTTP 4xx is received with the exception
41
42
  #of 401, 403, 403 and 422 where a more sepcific exception is thrown
42
43
  #
43
44
  #HTTP Error Codes 4xx
44
45
  #
45
- #The 4xx class of status code is intended for cases in which the client
46
+ #The 4xx class of status code is intended for cases in which the client
46
47
  #seems to have errored.
47
48
  class ClientErrorException < Exception; end
48
49
 
@@ -81,16 +82,16 @@ module RHC
81
82
  #403 Forbidden
82
83
  #
83
84
  #The server understood the request, but is refusing to fulfill it.
84
- #Authorization will not help and the request SHOULD NOT be repeated.
85
+ #Authorization will not help and the request SHOULD NOT be repeated.
85
86
  class RequestDeniedException < ClientErrorException; end
86
87
 
87
88
  #Exceptions thrown in case of an HTTP 401 is received.
88
89
  #
89
90
  #401 Unauthorized
90
91
  #
91
- #The request requires user authentication. If the request already
92
- #included Authorization credentials, then the 401 response indicates
93
- #that authorization has been refused for those credentials.
92
+ #The request requires user authentication. If the request already
93
+ #included Authorization credentials, then the 401 response indicates
94
+ #that authorization has been refused for those credentials.
94
95
  class UnAuthorizedException < ClientErrorException; end
95
96
  class TokenExpiredOrInvalid < UnAuthorizedException; end
96
97
 
@@ -4,7 +4,7 @@ Usage: rhc [--help] [--version] [--debug] <command> [<args>]
4
4
 
5
5
  <%
6
6
  remaining = Hash[commands.dup.select{ |name, command| not command.summary.blank? }]
7
- basic = remaining.slice!('setup', 'create-app', 'apps', 'cartridges', 'add-cartridge', 'server', 'logout')
7
+ basic = remaining.slice!('setup', 'create-app', 'apps', 'cartridges', 'add-cartridge', 'set-env', 'logout')
8
8
  remaining.delete_if{ |name, command| alias?(name) }
9
9
  begin -%>
10
10
  Getting started:
@@ -18,14 +18,14 @@ Working with apps:
18
18
  <%= table(debugging.map{ |arr| arr[1] = arr[1].summary || arr[1].description; arr }, table_args(' ', 18)).join("\n") %>
19
19
  <% end unless debugging.empty? %>
20
20
  Management commands:
21
- <%= table(remaining.sort.select{ |arr| arr[1].root? and arr[1].summary.present? }.map do |arr|
21
+ <%= table(remaining.sort.select{ |arr| arr[1].root? and arr[1].summary.present? }.map do |arr|
22
22
  arr[1] = arr[1].summary || arr[1].description
23
- arr
23
+ arr
24
24
  end, table_args(' ', 18)).join("\n") %>
25
25
 
26
26
  Some management commands have nested actions - run 'rhc help <command>' for more info.
27
27
 
28
- See '<%= Array(program :name).first %> help <command>' for more information on a specific command. You can see a list of all commands with 'rhc help commands'. See 'rhc help options' for a list of global command-line options and information about the config file.
28
+ See '<%= Array(program :name).first %> help <command>' for more information on a specific command. You can see a list of all commands with 'rhc help commands'. See 'rhc help options' for a list of global command-line options and information about the config file.
29
29
  <% if program :help -%>
30
30
  <% for title, body in program(:help) %>
31
31
  <%= $terminal.color title.to_s.upcase, :bold %>:
@@ -0,0 +1,7 @@
1
+ FOO=123
2
+ BAR=456
3
+ MY_OPENSHIFT_ENV_VAR=mongodb://user:pass@host:port/
4
+ MY_EMPTY_ENV_VAR=
5
+ ZEE
6
+ LOL
7
+ MUST NOT BE INCLUDED
@@ -0,0 +1 @@
1
+ AND=123
@@ -177,6 +177,7 @@ describe RHC::Commands::App do
177
177
  it { expect { run }.to exit_with_code(0) }
178
178
  it { run_output.should match("Success") }
179
179
  it { run_output.should match("Cartridges: mock_standalone_cart-1\n") }
180
+ it { run_output.should_not match(/Environment Variables:/) }
180
181
  end
181
182
 
182
183
  context 'when Hosts resolver raises an Exception' do
@@ -196,6 +197,7 @@ describe RHC::Commands::App do
196
197
  it { expect { run }.to exit_with_code(0) }
197
198
  it { run_output.should match("Success") }
198
199
  it { run_output.should match("Cartridges: mock_standalone_cart-1, mock_cart-1\n") }
200
+ it { run_output.should_not match(/Environment Variables:/) }
199
201
  after{ rest_client.domains.first.applications.first.cartridges.find{ |c| c.name == 'mock_cart-1' }.should be_true }
200
202
  end
201
203
 
@@ -204,6 +206,7 @@ describe RHC::Commands::App do
204
206
  it { expect { run }.to exit_with_code(0) }
205
207
  it { run_output.should match("Success") }
206
208
  it { run_output.should match("Cartridges: http://foo.com, mock_cart-1\n") }
209
+ it { run_output.should_not match(/Environment Variables:/) }
207
210
  after{ rest_client.domains.first.applications.first.cartridges.find{ |c| c.url == 'http://foo.com' }.should be_true }
208
211
  end
209
212
 
@@ -267,12 +270,12 @@ describe RHC::Commands::App do
267
270
  let(:arguments) { ['app', 'create', 'app1', 'http://foo.com', '--trace', '--noprompt'] }
268
271
  it('tells me about custom carts') { run_output.should match("The cartridge 'http://foo.com' will be downloaded") }
269
272
  it('lists the cart using the short_name') { run_output.should match(%r(Cartridges:\s+http://foo.com$)) }
270
- end
273
+ end
271
274
  context 'when I pick a custom URL cart and a web cart' do
272
275
  let(:arguments) { ['app', 'create', 'app1', 'http://foo.com', 'embcart-1', '--trace', '--noprompt'] }
273
276
  it('tells me about custom carts') { run_output.should match("The cartridge 'http://foo.com' will be downloaded") }
274
277
  it('lists the carts using the short_name') { run_output.should match(%r(Cartridges:\s+http://foo.com, embcart-1$)) }
275
- end
278
+ end
276
279
  end
277
280
 
278
281
  describe 'app create enable-jenkins' do
@@ -286,9 +289,9 @@ describe RHC::Commands::App do
286
289
  #puts run_output
287
290
  expect { run }.to exit_with_code(0)
288
291
  jenkins_app = rest_client.find_application(@domain.id,"jenkins")
289
- jenkins_app.cartridges[0].name.should == "jenkins-1.4"
292
+ jenkins_app.cartridges[0].name.should == "jenkins-1"
290
293
  app = rest_client.find_application(@domain.id,"app1")
291
- app.find_cartridge("jenkins-client-1.4")
294
+ app.find_cartridge("jenkins-client-1")
292
295
  end
293
296
  end
294
297
  end
@@ -321,7 +324,7 @@ describe RHC::Commands::App do
321
324
  context 'when run' do
322
325
  before(:each) do
323
326
  @domain = rest_client.add_domain("mockdomain")
324
- @domain.add_application("jenkins", "jenkins-1.4")
327
+ @domain.add_application("jenkins", "jenkins-1")
325
328
  end
326
329
  it "should use existing jenkins" do
327
330
  expect { run }.to exit_with_code(0)
@@ -355,6 +358,15 @@ describe RHC::Commands::App do
355
358
  run_output.should match("Jenkins client failed to install")
356
359
  end
357
360
  end
361
+
362
+ context 'when run without jenkins cartridge available on server' do
363
+ before(:each) do
364
+ @instance.stub(:all_cartridges) { rest_client.cartridges.delete_if { |item| item.name =~ /\Ajenkins/i } }
365
+ end
366
+ it "should exit with jenkins error" do
367
+ run_output.should match("There is no installed cartridge that exposes Jenkins")
368
+ end
369
+ end
358
370
  end
359
371
 
360
372
  describe 'app create jenkins install with retries' do
@@ -503,12 +515,12 @@ describe RHC::Commands::App do
503
515
  let(:password){ 'password' }
504
516
  let(:server){ mock_uri }
505
517
  let(:arguments){ ['delete-app', 'foo', '--confirm', '--trace'] }
506
- before do
518
+ before do
507
519
  stub_api
508
520
  challenge{ stub_one_domain('test') }
509
521
  stub_one_application('test', 'foo')
510
522
  end
511
- before do
523
+ before do
512
524
  stub_api_request(:delete, "broker/rest/domains/test/applications/foo").
513
525
  to_return({
514
526
  :body => {
@@ -568,7 +580,7 @@ describe RHC::Commands::App do
568
580
  it { run_output.should match(/Gears:\s+Located with mock_type/) }
569
581
  it { run_output.should match(/Gears:\s+1 small/) }
570
582
  it { run_output.should match(%r(From:\s+ https://foo.bar.com)) }
571
- end
583
+ end
572
584
  end
573
585
 
574
586
  describe 'app show' do
@@ -616,7 +628,7 @@ describe RHC::Commands::App do
616
628
  before do
617
629
  @domain = rest_client.add_domain("mockdomain")
618
630
  @domain.add_application("app1", "mock_type", true)
619
- expect_multi_ssh('echo "$(du -s 2>/dev/null | cut -f 1)"', 'fakegearid0@fakesshurl.com' => '1734934', 'fakegearid1@fakesshurl.com' => '1934234')
631
+ expect_multi_ssh('echo "$(du --block-size=1 -s 2>/dev/null | cut -f 1)"', 'fakegearid0@fakesshurl.com' => '1734334', 'fakegearid1@fakesshurl.com' => '1934348')
620
632
  end
621
633
  it { run_output.should match(/Gear.*Cartridges.*Used.*fakegearid0.*1\.7 MB.*1 GB.*fakegearid1.*1\.9 MB/m) }
622
634
  it { expect{ run }.to exit_with_code(0) }
@@ -705,7 +717,36 @@ describe RHC::Commands::App do
705
717
  subject.should_receive(:list_cartridges)
706
718
  domain = double
707
719
  domain.stub(:add_application).and_raise(RHC::Rest::ValidationException.new('Foo', :cartridges, 109))
708
- expect{ subject.send(:create_app, 'name', 'jenkins-1.4', domain) }.to raise_error(RHC::Rest::ValidationException)
720
+ expect{ subject.send(:create_app, 'name', 'jenkins-1', domain) }.to raise_error(RHC::Rest::ValidationException)
709
721
  end
710
722
  end
723
+
724
+ describe 'create app with env vars' do
725
+ before{ rest_client.add_domain("mockdomain") }
726
+
727
+ [['app', 'create', 'app1', 'mock_standalone_cart-1', '-e', 'FOO=BAR', '--noprompt', '--timeout', '10', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'],
728
+ ['app', 'create', 'app1', 'mock_standalone_cart-1', '--env', 'FOO=BAR', '--noprompt', '--timeout', '10', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password']
729
+ ].each_with_index do |args, i|
730
+ context "when run with single env var #{i}" do
731
+ let(:arguments) { args }
732
+ it { expect { run }.to exit_with_code(0) }
733
+ it { run_output.should match("Success") }
734
+ it { run_output.should match(/Cartridges:\s+mock_standalone_cart-1\n/) }
735
+ it { run_output.should match(/Environment Variables:\s+FOO=BAR\n/) }
736
+ end
737
+ end
738
+
739
+ [['app', 'create', 'app1', 'mock_standalone_cart-1', '-e', 'VAR1=VAL1', '-e', 'VAR2=VAL2', '-e', 'VAR3=VAL3', '--noprompt', '--timeout', '10', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'],
740
+ ['app', 'create', 'app1', 'mock_standalone_cart-1', '--env', 'VAR1=VAL1', '--env', 'VAR2=VAL2', '--env', 'VAR3=VAL3', '--noprompt', '--timeout', '10', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password']
741
+ ].each_with_index do |args, i|
742
+ context "when run with multiple env vars #{i}" do
743
+ let(:arguments) { args }
744
+ it { expect { run }.to exit_with_code(0) }
745
+ it { run_output.should match("Success") }
746
+ it { run_output.should match(/Cartridges:\s+mock_standalone_cart-1\n/) }
747
+ it { run_output.should match(/Environment Variables:\s+VAR1=VAL1, VAR2=VAL2, VAR3=VAL3\n/) }
748
+ end
749
+ end
750
+
751
+ end
711
752
  end
@@ -27,11 +27,11 @@ describe RHC::Commands::Cartridge do
27
27
  describe 'run' do
28
28
  let!(:rest_client){ MockRestClient.new }
29
29
  context "with all arguments" do
30
- let(:arguments) { ['cartridge', '--trace', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
30
+ let(:arguments) { ['cartridges', '--trace', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
31
31
  it { succeed_with_message /mock_cart-1.*mock_cart-2.*unique_mock_cart-1/m }
32
32
  end
33
33
  context "without password" do
34
- let(:arguments) { ['cartridge', '--trace', '--noprompt', '--config', 'test.conf'] }
34
+ let(:arguments) { ['cartridges', '--trace', '--noprompt', '--config', 'test.conf'] }
35
35
  it { succeed_with_message /mock_cart-1.*mock_cart-2.*unique_mock_cart-1/m }
36
36
  end
37
37
  end
@@ -66,7 +66,7 @@ describe RHC::Commands::Cartridge do
66
66
 
67
67
  describe 'alias app cartridge' do
68
68
  let!(:rest_client){ MockRestClient.new }
69
- let(:arguments) { ['app', 'cartridge', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
69
+ let(:arguments) { ['app', 'cartridge', 'list', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] }
70
70
 
71
71
  context 'when run' do
72
72
  it { succeed_with_message /mock_cart-1.*mock_cart-2.*unique_mock_cart-1/m }
@@ -86,6 +86,9 @@ describe RHC::Commands::Cartridge do
86
86
  it { succeed_with_message /Connection URL:\s+http\:\/\/fake\.url/ }
87
87
  it { succeed_with_message /Prop1:\s+value1/ }
88
88
  it { succeed_with_message /Cartridge added with properties/ }
89
+ it "should not contain env var info" do
90
+ run_output.should_not match(/Environment Variables/)
91
+ end
89
92
  end
90
93
  end
91
94
 
@@ -215,15 +218,15 @@ describe RHC::Commands::Cartridge do
215
218
  let(:username){ mock_user }
216
219
  let(:password){ 'password' }
217
220
  let(:server){ mock_uri }
218
- let(:arguments){ ['remove-cartridge', 'jenkins-1.4', '-a', 'foo', '--confirm', '--trace'] }
219
- before do
221
+ let(:arguments){ ['remove-cartridge', 'jenkins-1', '-a', 'foo', '--confirm', '--trace'] }
222
+ before do
220
223
  stub_api(false)
221
224
  challenge{ stub_one_domain('test') }
222
225
  stub_one_application('test', 'foo').with(:query => {:include => 'cartridges'})
223
- stub_application_cartridges('test', 'foo', [{:name => 'php-5.3'}, {:name => 'jenkins-1.4'}])
226
+ stub_application_cartridges('test', 'foo', [{:name => 'php-5.3'}, {:name => 'jenkins-1'}])
224
227
  end
225
- before do
226
- stub_api_request(:delete, "broker/rest/domains/test/applications/foo/cartridges/jenkins-1.4").
228
+ before do
229
+ stub_api_request(:delete, "broker/rest/domains/test/applications/foo/cartridges/jenkins-1").
227
230
  to_return({
228
231
  :body => {
229
232
  :type => nil,
@@ -238,7 +241,7 @@ describe RHC::Commands::Cartridge do
238
241
  end
239
242
 
240
243
  it("should not display info returned by the server"){ run_output.should_not match "Removed Jenkins" }
241
- it("should display prefix returned by the server"){ run_output.should match "Removing jenkins-1.4" }
244
+ it("should display prefix returned by the server"){ run_output.should match "Removing jenkins-1" }
242
245
  it("should display results returned by the server"){ run_output.should match "Job URL changed" }
243
246
  it('should exit successfully'){ expect{ run }.to exit_with_code(0) }
244
247
  end
@@ -550,4 +553,53 @@ describe RHC::Commands::Cartridge do
550
553
 
551
554
  end
552
555
  end
556
+
557
+ describe 'cartridge add with env vars' do
558
+ let!(:rest_client){ MockRestClient.new }
559
+
560
+ [['app', 'cartridge', 'add', 'unique_mock_cart', '-e', 'FOO=BAR', '--app', 'app1', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'],
561
+ ['app', 'cartridge', 'add', 'unique_mock_cart', '--env', 'FOO=BAR', '--app', 'app1', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password']
562
+ ].each_with_index do |args, i|
563
+ context "when run with single env var #{i}" do
564
+ let(:arguments) { args }
565
+ before(:each) do
566
+ domain = rest_client.add_domain("mock_domain")
567
+ app = domain.add_application("app1", "mock_type")
568
+ end
569
+ it {
570
+ succeed_with_message(/Environment Variables:\s+FOO=BAR/)
571
+ }
572
+ end
573
+ end
574
+
575
+ [['app', 'cartridge', 'add', 'unique_mock_cart', '-e', 'FOO1=BAR1', '-e', 'FOO2=BAR2', '--app', 'app1', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'],
576
+ ['app', 'cartridge', 'add', 'unique_mock_cart', '--env', 'FOO1=BAR1', '--env', 'FOO2=BAR2', '--app', 'app1', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password']
577
+ ].each_with_index do |args, i|
578
+ context "when run with multiple env vars #{i}" do
579
+ let(:arguments) { args }
580
+ before(:each) do
581
+ domain = rest_client.add_domain("mock_domain")
582
+ app = domain.add_application("app1", "mock_type")
583
+ end
584
+ it {
585
+ succeed_with_message(/Environment Variables:\s+FOO1=BAR1, FOO2=BAR2/)
586
+ }
587
+ end
588
+ end
589
+
590
+ [['app', 'cartridge', 'add', 'unique_mock_cart', '-e', File.expand_path('../../assets/env_vars.txt', __FILE__), '--app', 'app1', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'],
591
+ ['app', 'cartridge', 'add', 'unique_mock_cart', '--env', File.expand_path('../../assets/env_vars.txt', __FILE__), '--app', 'app1', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password']
592
+ ].each_with_index do |args, i|
593
+ context "when run with env vars from files #{i}" do
594
+ let(:arguments) { args }
595
+ before(:each) do
596
+ domain = rest_client.add_domain("mock_domain")
597
+ app = domain.add_application("app1", "mock_type")
598
+ end
599
+ it {
600
+ succeed_with_message(/Environment Variables:\s+BAR=456, FOO=123, MY_EMPTY_ENV_VAR=, MY_OPENSHIFT_ENV_VAR=mongodb:\/\/user:pass@host:port\/\n/)
601
+ }
602
+ end
603
+ end
604
+ end
553
605
  end