rhc 1.23.7 → 1.24.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.
data/lib/rhc/rest/team.rb CHANGED
@@ -2,6 +2,8 @@ module RHC
2
2
  module Rest
3
3
  class Team < Base
4
4
 
5
+ include Membership
6
+
5
7
  define_attr :id, :name, :global
6
8
 
7
9
  def global?
@@ -15,6 +17,18 @@ module RHC
15
17
  def to_s
16
18
  self.name
17
19
  end
20
+
21
+ def destroy(force=false)
22
+ debug "Deleting team #{name} (#{id})"
23
+ raise RHC::OperationNotSupportedException.new("The server does not support deleting this resource.") unless supports? 'DELETE'
24
+ rest_method "DELETE"
25
+ end
26
+ alias :delete :destroy
27
+
28
+ def default_member_role
29
+ 'view'
30
+ end
31
+
18
32
  end
19
33
  end
20
34
  end
@@ -1,4 +1,14 @@
1
+ <% if @command.syntax.is_a?(Array) -%>
2
+ Usage
3
+ <%= table(
4
+ @command.syntax.map do |s|
5
+ s ? [Array(program :name).first, @command.name, s] : [' ']
6
+ end,
7
+ table_args(' ')
8
+ ).join("\n") %>
9
+ <% else -%>
1
10
  Usage: <%= Array(program :name).first %> <%= @command.name %> <%= @command.syntax %>
11
+ <% end -%>
2
12
 
3
13
  <%= @command.description || @command.summary %>
4
14
  <% if @actions.blank? or @command.root? and @command.info.present? and @command.info[:method].present? -%>
@@ -1,4 +1,15 @@
1
+ <% if @command.syntax.is_a?(Array) -%>
2
+ Usage
3
+ <%= table(
4
+ @command.syntax.map do |s|
5
+ s ? [Array(program :name).first, @command.name, s] : [' ']
6
+ end,
7
+ table_args(' ')
8
+ ).join("\n") %>
9
+
10
+ <% else -%>
1
11
  Usage: <%= Array(program :name).first %> <%= @command.name %><%= " #{@command.syntax}" if @command.syntax %>
12
+ <% end -%>
2
13
  <% unless @command.options.blank? or @command.options.all?{ |o| o[:hide] } -%>
3
14
  Pass '--help' to see the full list of options
4
15
  <% end -%>
@@ -246,6 +246,21 @@ describe RHC::Commands::Base do
246
246
  end
247
247
  end
248
248
 
249
+ describe "find_team" do
250
+ let(:instance){ subject }
251
+ let(:rest_client){ subject.send(:rest_client) }
252
+ let(:options){ subject.send(:options) }
253
+ def expects_method(*args)
254
+ expect{ subject.send(:find_team, *args) }
255
+ end
256
+
257
+ it("should raise without option"){ expects_method(nil).to raise_error(ArgumentError, /You must specify a team name with -t, or a team id with --team-id/) }
258
+ it("should handle team_id option"){ options[:team_id] = 'team_id_o'; expects_method.to call(:find_team_by_id).on(rest_client).with('team_id_o', {}) }
259
+ it("should handle team_name option"){ options[:team_name] = 'team_o'; expects_method.to call(:find_team).on(rest_client).with('team_o', {}) }
260
+ it("should handle team_name param"){ options[:team_name] = 'team_o'; expects_method.to call(:find_team).on(rest_client).with('team_o', {}) }
261
+
262
+ end
263
+
249
264
  describe "find_domain" do
250
265
  let(:instance){ subject }
251
266
  let(:rest_client){ subject.send(:rest_client) }
@@ -284,19 +299,23 @@ describe RHC::Commands::Base do
284
299
  end
285
300
  end
286
301
 
287
- describe "find_domain_or_app" do
302
+ describe "find_membership_container" do
288
303
  let(:instance){ subject }
289
304
  let(:rest_client){ subject.send(:rest_client) }
290
305
  let(:options){ subject.send(:options) }
291
306
  before{ subject.stub(:namespace_context).and_return('domain_s') }
292
307
  def expects_method(*args)
293
- expect{ subject.send(:find_app_or_domain, *args) }
308
+ expect{ subject.send(:find_membership_container, *args) }
294
309
  end
295
310
 
296
- it("should not infer domain") { expects_method.to raise_error(ArgumentError, /You must specify a domain with -n, or an application with -a/) }
311
+ it("should prompt for domain, app, or team") { expects_method.to raise_error(ArgumentError, /You must specify a domain with -n, an application with -a, or a team with -t/) }
312
+ it("should prompt for domain, or team") { expects_method(:writable => true).to raise_error(ArgumentError, /You must specify a domain with -n, or a team with -t/) }
297
313
  it("should assume domain with -n") { options[:namespace] = 'domain_o'; expects_method.to call(:find_domain).on(rest_client).with('domain_o') }
298
314
  it("should infer -n when -a is available"){ options[:app] = 'app_o'; expects_method.to call(:find_application).on(rest_client).with('domain_s', 'app_o') }
299
315
  it("should split -a param") { options[:app] = 'domain_o/app_o'; expects_method.to call(:find_application).on(rest_client).with('domain_o', 'app_o') }
316
+ it("should split target arg") { options[:target] = 'domain_o/app_o'; expects_method.to call(:find_application).on(rest_client).with('domain_o', 'app_o') }
317
+ it("should find team by name") { options[:team_name] = 'team_o'; expects_method.to call(:find_team).on(rest_client).with('team_o') }
318
+ it("should find team by id") { options[:team_id] = 'team_id_o'; expects_method.to call(:find_team_by_id).on(rest_client).with('team_id_o') }
300
319
 
301
320
  context "when an app context is available" do
302
321
  before{ subject.instance_variable_set(:@local_git_config, {:app => 'app_s'}) }
@@ -490,6 +490,25 @@ describe RHC::Commands::App do
490
490
  end
491
491
  end
492
492
 
493
+ context 'when cloning a scalable app as not scalable' do
494
+ before do
495
+ @scaled = @domain.add_application("scaled", "mock_standalone_cart-1", true)
496
+ @scaled.cartridges.each do |c|
497
+ c.scales_from = 2
498
+ c.scales_to = -1
499
+ end
500
+ end
501
+ let(:arguments) { ['app', 'create', 'clone', '--from-app', 'scaled', '--no-git', '--no-scaling'] }
502
+ it "should result in only one gear" do
503
+ expect { run }.to exit_with_code(0)
504
+ @domain.applications.size.should == 3
505
+ @domain.applications.select{|a| a.name == 'clone'}.size.should == 1
506
+ @domain.applications.select{|a| a.name == 'clone'}.first.cartridges.size.should == 1
507
+ @domain.applications.select{|a| a.name == 'clone'}.first.cartridges.first.scales_from.should == 1
508
+ @domain.applications.select{|a| a.name == 'clone'}.first.cartridges.first.scales_to.should == 1
509
+ end
510
+ end
511
+
493
512
  context 'alias already registered' do
494
513
  let(:arguments) { ['app', 'create', 'clone', '--from-app', 'app1', '--no-git'] }
495
514
  before do
@@ -611,6 +630,28 @@ describe RHC::Commands::App do
611
630
  it { run_output.should match(/Gears:\s+1 medium/) }
612
631
  end
613
632
 
633
+ context 'when run with premium cartridge with single rate' do
634
+ before do
635
+ @domain = rest_client.add_domain("mockdomain")
636
+ app = @domain.add_application("app1", "mock_type", true)
637
+ cart1 = app.add_cartridge('mock_premium_cart-1')
638
+ cart1.usage_rates = {0.01 => []}
639
+ end
640
+ it { run_output.should match(/This cartridge costs an additional \$0.01 per gear after the first 3 gears\./) }
641
+ end
642
+
643
+ context 'when run with premium cartridge with multiple rates' do
644
+ before do
645
+ @domain = rest_client.add_domain("mockdomain")
646
+ app = @domain.add_application("app1", "mock_type", true)
647
+ cart1 = app.add_cartridge('mock_premium_cart-2')
648
+ cart1.usage_rates = {0.01 => ['plan1','plan2', 'plan3'], 0.02 => ['plan4'], 0.03 => []}
649
+ end
650
+ it { run_output.should match(/This cartridge costs an additional \$0\.01 per gear after the first 3 gears on the Plan1, Plan2 and Plan3 plans\./) }
651
+ it { run_output.should match(/This cartridge costs an additional \$0\.02 per gear after the first 3 gears on the Plan4 plan\./) }
652
+ it { run_output.should match(/This cartridge costs an additional \$0\.03 per gear after the first 3 gears\./) }
653
+ end
654
+
614
655
  context 'when run with custom app' do
615
656
  before do
616
657
  @domain = rest_client.add_domain("mockdomain")
@@ -220,7 +220,7 @@ describe RHC::Commands::Cartridge do
220
220
  app = domain.add_application("app1", "mock_type")
221
221
  end
222
222
  it {
223
- succeed_with_message /This gear costs an additional \$0\.05 per gear after the first 3 gears\./
223
+ succeed_with_message /This cartridge costs an additional \$0\.05 per gear after the first 3 gears\./
224
224
  }
225
225
  end
226
226
  end
@@ -424,7 +424,7 @@ describe RHC::Commands::Cartridge do
424
424
  end
425
425
 
426
426
  context 'when run with a premium cartridge' do
427
- it { run_output.should match(/This gear costs an additional \$0\.05 per gear after the first 3 gears./) }
427
+ it { run_output.should match(/This cartridge costs an additional \$0\.05 per gear after the first 3 gears./) }
428
428
  end
429
429
  end
430
430
 
@@ -34,6 +34,9 @@ describe RHC::Commands::Member do
34
34
  app
35
35
  end
36
36
  end
37
+ def with_mock_team
38
+ @team ||= with_mock_rest_client.add_team("mock-team-0")
39
+ end
37
40
 
38
41
  let(:owner){ RHC::Rest::Membership::Member.new(:id => '1', :role => 'admin', :explicit_role => 'admin', :owner => true, :login => 'alice', :type => 'user') }
39
42
  let(:other_admin){ RHC::Rest::Membership::Member.new(:id => '2', :role => 'admin', :explicit_role => 'admin', :login => 'Bob', :type => 'user') }
@@ -212,8 +215,13 @@ describe RHC::Commands::Member do
212
215
 
213
216
  context 'with an invalid type' do
214
217
  let(:arguments) { ['add-member', 'invalidteam', '-n', 'test', '--type', 'foo'] }
218
+ before do
219
+ stub_api_request(:patch, "broker/rest/domains/test/members").
220
+ with(:body => {:members => [{'login' => 'invalidteam', 'role' => 'edit', 'type' => 'foo'}]}).
221
+ to_return({:body => {:messages => [{:exit_code => 1, :field => 'type', :index => 0, :severity => 'error', :text => "Members of type foo not supported for domain. Supported types are 'user', 'team'."}]}.to_json, :status => 422})
222
+ end
215
223
  it { expect { run }.to exit_with_code(1) }
216
- it { run_output.should =~ /Type must be/ }
224
+ it { run_output.should =~ /type foo not supported for domain/ }
217
225
  end
218
226
 
219
227
  context 'with an invalid team' do
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+ require 'rest_spec_helper'
3
+ require 'rhc/commands/team'
4
+
5
+ describe RHC::Commands::Team do
6
+ let(:rest_client){ MockRestClient.new }
7
+ before{
8
+ user_config
9
+ }
10
+
11
+ describe 'default action' do
12
+ before{ rest_client }
13
+ context 'when run with no teams' do
14
+ let(:arguments) { ['team'] }
15
+
16
+ it { expect { run }.to exit_with_code(1) }
17
+ it { run_output.should match(/To create.*rhc create-team/m) }
18
+ end
19
+ context 'when help is shown' do
20
+ let(:arguments) { ['team', '--noprompt', '--help'] }
21
+
22
+ it { expect { run }.to exit_with_code(0) }
23
+ it { run_output.should match(/create.*delete.*leave.*list/m) }
24
+ end
25
+ end
26
+
27
+ describe 'show' do
28
+ before{ rest_client }
29
+
30
+ context 'when run with no teams' do
31
+ let(:arguments) { ['team', 'show'] }
32
+ it { expect { run }.to exit_with_code(1) }
33
+ it { run_output.should match(/specify a team name/) }
34
+ end
35
+
36
+ context 'when run with one team' do
37
+ let(:arguments) { ['team', 'show', 'oneteam'] }
38
+ before{ rest_client.add_team("oneteam") }
39
+ it { expect { run }.to exit_with_code(0) }
40
+ it { run_output.should match(/oneteam/) }
41
+ it { run_output.should match(/ID: 123/) }
42
+ end
43
+
44
+ context 'when run with two teams' do
45
+ let(:arguments) { ['team', 'show', 'twoteam'] }
46
+ before do
47
+ rest_client.add_team("oneteam")
48
+ rest_client.add_team("twoteam")
49
+ end
50
+ it { expect { run }.to exit_with_code(0) }
51
+ it { run_output.should match(/twoteam/) }
52
+ it { run_output.should_not match(/oneteam/) }
53
+ end
54
+ end
55
+
56
+ describe 'list' do
57
+ before{ rest_client }
58
+ let(:arguments) { ['team', 'list'] }
59
+
60
+ context 'when run with no teams' do
61
+ it { expect { run }.to exit_with_code(0) }
62
+ it { run_output.should match(/member of 0 teams/) }
63
+ end
64
+
65
+ context 'when run with one team' do
66
+ before{ rest_client.add_team("oneteam") }
67
+
68
+ it { expect { run }.to exit_with_code(0) }
69
+ it "should match output" do
70
+ output = run_output
71
+ output.should match("You are a member of 1 team\\.")
72
+ output.should match("oneteam")
73
+ end
74
+
75
+ context 'when has no members' do
76
+ before{ rest_client.teams.first.attributes.merge(:members => nil, :id => '123') }
77
+ it { expect { run }.to exit_with_code(0) }
78
+ it "should match output" do
79
+ output = run_output
80
+ output.should match("oneteam")
81
+ output.should_not match ("Members:")
82
+ output.should match ("ID: 123")
83
+ end
84
+ end
85
+
86
+ context 'when an ID is present and differs from name' do
87
+ let(:arguments) { ['team', 'list'] }
88
+ before{ rest_client.teams.first.attributes['id'] = '123' }
89
+ it { expect { run }.to exit_with_code(0) }
90
+ it "should match output" do
91
+ output = run_output
92
+ output.should match("oneteam")
93
+ output.should match ("ID:.*123")
94
+ end
95
+ end
96
+
97
+ end
98
+
99
+ context 'when run with one owned team' do
100
+ let(:arguments) { ['teams', '--mine'] }
101
+ before{ t = rest_client.add_team('mine', true); rest_client.stub(:owned_teams).and_return([t]) }
102
+
103
+ it { expect { run }.to exit_with_code(0) }
104
+ it "should match output" do
105
+ output = run_output
106
+ output.should match("You have 1 team\\.")
107
+ output.should match("mine")
108
+ end
109
+ end
110
+ end
111
+
112
+ describe 'create' do
113
+ before{ rest_client }
114
+ let(:arguments) { ['team', 'create', 'testname'] }
115
+
116
+ context 'when no issues with ' do
117
+
118
+ it "should create a team" do
119
+ expect { run }.to exit_with_code(0)
120
+ rest_client.teams[0].name.should == 'testname'
121
+ end
122
+ it { run_output.should match(/Creating.*'testname'.*done/m) }
123
+ end
124
+ end
125
+
126
+ describe 'leave' do
127
+ before{ rest_client.add_team("deleteme") }
128
+ let(:arguments) { ['team', 'leave', 'deleteme'] }
129
+
130
+ it "should leave the team" do
131
+ rest_client.teams.first.should_receive(:leave).and_return(RHC::Rest::Membership::Member.new)
132
+ expect { run }.to exit_with_code(0)
133
+ end
134
+ end
135
+
136
+ describe 'delete' do
137
+ before{ rest_client }
138
+ let(:arguments) { ['team', 'delete', 'deleteme'] }
139
+
140
+ context 'when no issues with ' do
141
+ before{
142
+ t = rest_client.add_team("deleteme")
143
+ rest_client.should_receive(:owned_teams).and_return([t])
144
+ }
145
+
146
+ it "should delete a team" do
147
+ expect { run }.to exit_with_code(0)
148
+ rest_client.teams.empty?.should be_true
149
+ end
150
+ end
151
+
152
+ context 'when there is a different team' do
153
+ before do
154
+ t = rest_client.add_team("dontdelete")
155
+ rest_client.should_receive(:owned_teams).and_return([t])
156
+ end
157
+
158
+ it "should error out" do
159
+ expect { run }.to exit_with_code(162)
160
+ rest_client.teams[0].name.should == 'dontdelete'
161
+ end
162
+ it { run_output.should match("Team with name deleteme not found") }
163
+ end
164
+
165
+ context 'when the server does not allow deleting' do
166
+ before do
167
+ t = rest_client.add_team("dontdelete")
168
+ t.links.delete 'DELETE'
169
+ t.id = "123"
170
+ end
171
+ let(:arguments) { ['team','delete','--team-id','123'] }
172
+ it "should error out" do
173
+ expect { run }.to exit_with_code(1)
174
+ rest_client.teams[0].name.should == 'dontdelete'
175
+ end
176
+ it { run_output.should match(/not support/) }
177
+ end
178
+
179
+ end
180
+
181
+ describe 'help' do
182
+ let(:arguments) { ['team', '--help'] }
183
+
184
+ context 'help is run' do
185
+ it "should display help" do
186
+ expect { run }.to exit_with_code(0)
187
+ end
188
+ it('should output usage') { run_output.should match("Usage: rhc team") }
189
+ end
190
+ end
191
+ end
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: 69
4
+ hash: 127
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 23
9
- - 7
10
- version: 1.23.7
8
+ - 24
9
+ - 4
10
+ version: 1.24.4
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: 2014-04-22 00:00:00 Z
18
+ date: 2014-05-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: net-ssh
@@ -267,6 +267,7 @@ files:
267
267
  - lib/rhc/context_helper.rb
268
268
  - lib/rhc/config.rb
269
269
  - lib/rhc/exceptions.rb
270
+ - lib/rhc/commands/team.rb
270
271
  - lib/rhc/commands/threaddump.rb
271
272
  - lib/rhc/commands/cartridge.rb
272
273
  - lib/rhc/commands/base.rb
@@ -356,6 +357,7 @@ files:
356
357
  - spec/rhc/commands/apps_spec.rb
357
358
  - spec/rhc/commands/account_spec.rb
358
359
  - spec/rhc/commands/domain_spec.rb
360
+ - spec/rhc/commands/team_spec.rb
359
361
  - spec/rhc/commands/cartridge_spec.rb
360
362
  - spec/rhc/commands/app_spec.rb
361
363
  - spec/rhc/commands/snapshot_spec.rb
@@ -452,6 +454,7 @@ test_files:
452
454
  - spec/rhc/commands/apps_spec.rb
453
455
  - spec/rhc/commands/account_spec.rb
454
456
  - spec/rhc/commands/domain_spec.rb
457
+ - spec/rhc/commands/team_spec.rb
455
458
  - spec/rhc/commands/cartridge_spec.rb
456
459
  - spec/rhc/commands/app_spec.rb
457
460
  - spec/rhc/commands/snapshot_spec.rb