cf 3.0.0 → 3.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -132,18 +132,28 @@ module CF
132
132
  log_error(e)
133
133
 
134
134
  err "Denied: #{e.description}"
135
+ rescue CFoundry::StagingError => e
136
+ message = "Application failed to stage"
137
+ formatted_exception_output(e, message)
135
138
 
136
139
  rescue Exception => e
137
- log_error(e)
140
+ formatted_exception_output(e, add_exception_name_to_msg(e))
141
+ end
138
142
 
139
- msg = e.class.name
140
- msg << ": #{e}" unless e.to_s.empty?
141
- msg << "\nFor more information, see #{CF::CRASH_FILE}"
143
+ def formatted_exception_output(e, msg)
144
+ log_error(e)
145
+ msg << "\ncat #{CF::CRASH_FILE} # for more details"
142
146
  err msg
143
147
 
144
148
  raise if debug?
145
149
  end
146
150
 
151
+ def add_exception_name_to_msg(e)
152
+ msg = e.class.name
153
+ msg << ": #{e}" unless e.to_s.empty?
154
+ msg
155
+ end
156
+
147
157
  def execute(cmd, argv, global = {})
148
158
  if input[:help]
149
159
  invoke :help, :command => cmd.name.to_s
@@ -31,28 +31,8 @@ module CF
31
31
  end
32
32
  end
33
33
 
34
- def memory_choices(exclude = 0)
35
- info = client.info
36
-
37
- usage = info[:usage]
38
- limit = info[:limits][:memory]
39
-
40
- ceiling =
41
- if usage
42
- used = usage[:memory]
43
- limit - used + exclude
44
- else
45
- limit
46
- end
47
-
48
- mem = 64
49
- choices = []
50
- until mem > ceiling
51
- choices << human_mb(mem)
52
- mem *= 2
53
- end
54
-
55
- choices
34
+ def memory_choices
35
+ [128, 256, 512, 1024].map{|n| human_mb(n)}
56
36
  end
57
37
 
58
38
  def human_mb(num)
@@ -15,11 +15,11 @@ module CF::App
15
15
 
16
16
  options = {
17
17
  :choices => choices + ["none"],
18
- :display => proc { |d| d.is_a?(String) ? d : d.name },
18
+ :display => proc { |choice| choice.is_a?(String) ? choice : choice.name },
19
19
  :allow_other => true
20
20
  }
21
21
 
22
- options[:default] = choices.first if choices.size == 1
22
+ options[:default] = choices.first
23
23
 
24
24
  ask "Domain", options
25
25
  end
@@ -28,7 +28,7 @@ module CF::App
28
28
  ask("Memory Limit",
29
29
  :choices => memory_choices,
30
30
  :allow_other => true,
31
- :default => default || "64M")
31
+ :default => default || "128M")
32
32
  end
33
33
 
34
34
  def ask_instances
@@ -56,7 +56,7 @@ module CF::App
56
56
  end
57
57
 
58
58
  def ask_memory(default)
59
- ask("Memory Limit", :choices => memory_choices(default),
59
+ ask("Memory Limit", :choices => memory_choices,
60
60
  :default => human_mb(default), :allow_other => true)
61
61
  end
62
62
  end
@@ -1,3 +1,3 @@
1
1
  module CF
2
- VERSION = "3.0.0".freeze
2
+ VERSION = "3.0.1.rc1".freeze
3
3
  end
@@ -439,34 +439,6 @@ module CF
439
439
  end
440
440
  end
441
441
  end
442
-
443
- describe "#memory_choices" do
444
- let(:info) { {} }
445
-
446
- before do
447
- client.stub(:info).and_return(info)
448
- end
449
-
450
- context "when the user has usage information" do
451
- let(:info) do
452
- {:usage => {:memory => 512},
453
- :limits => {:memory => 2048}
454
- }
455
- end
456
-
457
- it "asks for the memory with the ceiling taking the memory usage into account" do
458
- expect(push_command.memory_choices).to eq(%w[64M 128M 256M 512M 1G])
459
- end
460
- end
461
-
462
- context "when the user does not have usage information" do
463
- let(:info) { {:limits => {:memory => 2048}} }
464
-
465
- it "asks for the memory with the ceiling as their overall limit" do
466
- expect(push_command.memory_choices).to eq(%w[64M 128M 256M 512M 1G 2G])
467
- end
468
- end
469
- end
470
442
  end
471
443
  end
472
444
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ module CF::App
5
+ class PushInteractionClass
6
+ include PushInteractions
7
+ def ask(question, options); end
8
+ end
9
+
10
+ describe PushInteractionClass do
11
+ let(:domains) { [build(:domain), build(:domain)]}
12
+ let(:app){ build(:app, :space => build(:space, :domains => domains)) }
13
+
14
+ describe "#ask_domain" do
15
+ it "uses all space domains as choices with optional none" do
16
+ subject.should_receive(:ask).with("Domain", anything) do |_, options|
17
+ expect(options[:choices]).to eq(domains + ["none"])
18
+ end
19
+
20
+ subject.ask_domain(app)
21
+ end
22
+
23
+ it "has always a default value" do
24
+ subject.should_receive(:ask).with("Domain", anything) do |_, options|
25
+ expect(options[:default]).to eq domains.first
26
+ end
27
+
28
+ subject.ask_domain(app)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -43,6 +43,32 @@ module CF
43
43
  :with_message => "user friendly"
44
44
  end
45
45
 
46
+ context "with a CFoundry::StagingError" do
47
+ let(:exception) { CFoundry::StagingError.new("whatever", 170001, nil, nil) }
48
+ let(:action) { proc { raise exception } }
49
+ before { exception.should_receive(:backtrace).at_least(1).times.and_return([]) }
50
+
51
+ it "prints the message" do
52
+ subject
53
+ expect(stderr.string).to include "Application failed to stage"
54
+ end
55
+
56
+ it "sets the exit code to 1" do
57
+ context.should_receive(:exit_status).with(1)
58
+ subject
59
+ end
60
+
61
+ it "does mention ~/.cf/crash" do
62
+ subject
63
+ expect(stderr.string).to include CF::CRASH_FILE
64
+ end
65
+
66
+ it "logs the error" do
67
+ context.should_receive(:log_error).with(anything)
68
+ subject
69
+ end
70
+ end
71
+
46
72
  context "with a SystemExit" do
47
73
  let(:action) { proc { exit 1 } }
48
74
 
@@ -2,6 +2,7 @@ FactoryGirl.define do
2
2
  factory :space, :class => CFoundry::V2::Space do
3
3
  sequence(:guid) { |n| "space-guid-#{n}" }
4
4
  sequence(:name) { |n| "space-name-#{n}" }
5
+ domains { [build(:domain)] }
5
6
 
6
7
  ignore do
7
8
  client { FactoryGirl.build(:client) }
@@ -9,4 +10,4 @@ FactoryGirl.define do
9
10
 
10
11
  initialize_with { new(guid, client) }
11
12
  end
12
- end
13
+ end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
5
- prerelease:
4
+ version: 3.0.1.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cloud Foundry Team
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-18 00:00:00.000000000 Z
13
+ date: 2013-06-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.0
54
+ version: 2.1.2.rc1
55
55
  - - <
56
56
  - !ruby/object:Gem::Version
57
57
  version: '3.0'
@@ -62,7 +62,7 @@ dependencies:
62
62
  requirements:
63
63
  - - ! '>='
64
64
  - !ruby/object:Gem::Version
65
- version: 2.1.0
65
+ version: 2.1.2.rc1
66
66
  - - <
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
@@ -476,6 +476,7 @@ files:
476
476
  - spec/cf/cli/app/delete_spec.rb
477
477
  - spec/cf/cli/app/instances_spec.rb
478
478
  - spec/cf/cli/app/push/create_spec.rb
479
+ - spec/cf/cli/app/push/interactions_spec.rb
479
480
  - spec/cf/cli/app/push_spec.rb
480
481
  - spec/cf/cli/app/rename_spec.rb
481
482
  - spec/cf/cli/app/scale_spec.rb
@@ -565,15 +566,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
565
566
  - - ! '>='
566
567
  - !ruby/object:Gem::Version
567
568
  version: '0'
569
+ segments:
570
+ - 0
571
+ hash: 428685765814888758
568
572
  required_rubygems_version: !ruby/object:Gem::Requirement
569
573
  none: false
570
574
  requirements:
571
- - - ! '>='
575
+ - - ! '>'
572
576
  - !ruby/object:Gem::Version
573
- version: '0'
577
+ version: 1.3.1
574
578
  requirements: []
575
579
  rubyforge_project: cf
576
- rubygems_version: 1.8.24
580
+ rubygems_version: 1.8.25
577
581
  signing_key:
578
582
  specification_version: 3
579
583
  summary: Friendly command-line interface for Cloud Foundry.
@@ -635,6 +639,7 @@ test_files:
635
639
  - spec/cf/cli/app/delete_spec.rb
636
640
  - spec/cf/cli/app/instances_spec.rb
637
641
  - spec/cf/cli/app/push/create_spec.rb
642
+ - spec/cf/cli/app/push/interactions_spec.rb
638
643
  - spec/cf/cli/app/push_spec.rb
639
644
  - spec/cf/cli/app/rename_spec.rb
640
645
  - spec/cf/cli/app/scale_spec.rb