cf 0.6.1.rc4 → 0.6.1.rc5

Sign up to get free protection for your applications and to get access to all the features.
@@ -111,7 +111,7 @@ module CF
111
111
  err e.message
112
112
  rescue CFoundry::InvalidAuthToken => e
113
113
  line
114
- line c("Invalid authentication token. Try logging in again with 'cf login'", :warning)
114
+ line c("Invalid authentication token. Try logging in again with 'cf login'. If problems continue, please contact your Cloud Operator.", :warning)
115
115
  rescue CFoundry::Forbidden => e
116
116
  if !$cf_asked_auth
117
117
  $cf_asked_auth = true
@@ -4,14 +4,16 @@ require "cf/cli/populators/organization"
4
4
  module CF
5
5
  module Space
6
6
  class Base < CLI
7
+ attr_reader :org
8
+
7
9
  def precondition
8
10
  check_target
9
11
  check_logged_in
10
- check_organization
11
12
  end
12
13
 
13
- def check_organization
14
- CF::Populators::Organization.new(input).populate_and_save!
14
+ def run(name)
15
+ @org = CF::Populators::Organization.new(input).populate_and_save!
16
+ super(name)
15
17
  end
16
18
 
17
19
  def self.space_by_name
@@ -16,39 +16,26 @@ module CF::Space
16
16
  input :auditor, :desc => "Add yourself as auditor", :default => false
17
17
 
18
18
  def create_space
19
- # TODO: ask org instead
20
- return invoke :help,
21
- :command => "create-space" if input[:organization].nil?
22
-
23
19
  space = client.space
24
- space.organization = input[:organization]
20
+ space.organization = org
25
21
  space.name = input[:name]
26
22
 
27
- with_progress("Creating space #{c(space.name, :name)}") do
28
- space.create!
29
- end
23
+ with_progress("Creating space #{c(space.name, :name)}") { space.create! }
30
24
 
31
25
  if input[:manager]
32
- with_progress("Adding you as a manager") do
33
- space.add_manager client.current_user
34
- end
26
+ with_progress("Adding you as a manager") { space.add_manager client.current_user }
35
27
  end
36
28
 
37
29
  if input[:developer]
38
- with_progress("Adding you as a developer") do
39
- space.add_developer client.current_user
40
- end
30
+ with_progress("Adding you as a developer") { space.add_developer client.current_user }
41
31
  end
42
32
 
43
33
  if input[:auditor]
44
- with_progress("Adding you as an auditor") do
45
- space.add_auditor client.current_user
46
- end
34
+ with_progress("Adding you as an auditor") { space.add_auditor client.current_user }
47
35
  end
48
36
 
49
37
  if input[:target]
50
- invoke :target, :organization => space.organization,
51
- :space => space
38
+ invoke :target, :organization => space.organization, :space => space
52
39
  else
53
40
  line c("Space created! Use #{b("switch-space #{space.name}")} to target it.", :good)
54
41
  end
@@ -11,7 +11,6 @@ module CF::Space
11
11
  :from_given => by_name(:space)
12
12
  input :name, :desc => "New space name", :argument => :optional
13
13
  def rename_space
14
- org = input[:organization]
15
14
  space = input[:space, org]
16
15
  name = input[:name]
17
16
 
@@ -14,8 +14,7 @@ module CF::Space
14
14
  input :full, :desc => "Show full information for apps, services, etc.",
15
15
  :default => false
16
16
  def space
17
- org = input[:organization]
18
- space = input[:space, org]
17
+ space = CF::Populators::Space.new(input, org).populate_and_save!
19
18
 
20
19
  unless space
21
20
  return if quiet?
@@ -12,8 +12,8 @@ module CF
12
12
  input :name, :desc => "Filter by name"
13
13
  input :full, :desc => "Show full information for apps, services, etc.",
14
14
  :default => false
15
+
15
16
  def spaces
16
- org = input[:organization]
17
17
  spaces =
18
18
  with_progress("Getting spaces in #{c(org.name, :name)}") do
19
19
  org.spaces(:depth => quiet? ? 0 : 1).sort_by(&:name)
@@ -6,7 +6,9 @@ module CF::Space
6
6
  group :spaces, :hidden => true
7
7
  input :name, :desc => "Space name", :argument => true
8
8
  def switch_space
9
- if (space = client.space_by_name(input[:name]))
9
+ space = client.space_by_name(input[:name])
10
+
11
+ if space
10
12
  invoke :target, :space => space
11
13
  else
12
14
  raise CF::UserError, "The space #{input[:name]} does not exist, please create the space first."
@@ -1,3 +1,3 @@
1
1
  module CF
2
- VERSION = "0.6.1.rc4".freeze
2
+ VERSION = "0.6.1.rc5".freeze
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require "cf/cli/app/base"
3
+
4
+ describe CF::Space::Base do
5
+ describe '#run' do
6
+ subject { CF::Space::Base.new }
7
+
8
+ it "uses a populator to set organization" do
9
+ org = stub
10
+ mock(CF::Populators::Organization).new(instance_of(Mothership::Inputs)) { stub!.populate_and_save! { org } }
11
+ stub(subject).send()
12
+
13
+ subject.run(:some_command)
14
+ subject.org.should == org
15
+ end
16
+ end
17
+
18
+ describe '.space_by_name' do
19
+ subject { CF::Space::Base::space_by_name }
20
+ let(:org) do
21
+ Object.new.tap do |o|
22
+ mock(o).space_by_name("mySpace").returns(space)
23
+ end
24
+ end
25
+
26
+ context "with a space" do
27
+ let(:space) { mock }
28
+ it "returns a space matching the name from the given org" do
29
+ subject.call("mySpace", org).should == space
30
+ end
31
+ end
32
+
33
+ context "with no matching space" do
34
+ let(:space) { nil }
35
+ it "fails when no space matches the name" do
36
+ expect {
37
+ subject.call("mySpace", org)
38
+ }.to raise_exception
39
+ end
40
+ end
41
+ end
42
+ end
@@ -33,8 +33,6 @@ describe CF::Space::Create do
33
33
 
34
34
  let(:client) { fake_client(:current_organization => organization, :spaces => spaces) }
35
35
 
36
-
37
-
38
36
  before do
39
37
  stub(client).space { new_space }
40
38
  stub(new_space).create!
@@ -46,7 +44,7 @@ describe CF::Space::Create do
46
44
 
47
45
  stub(cli).check_logged_in
48
46
  stub(cli).check_target
49
- stub(cli).check_organization
47
+ any_instance_of(CF::Populators::Organization, :populate_and_save! => organization)
50
48
  end
51
49
  end
52
50
 
@@ -67,44 +65,6 @@ describe CF::Space::Create do
67
65
  subject
68
66
  expect(output).to say("Space created! Use switch-space #{new_space.name} to target it.")
69
67
  end
70
-
71
- it_should_behave_like "a_command_that_populates_organization" do
72
- before do
73
- any_instance_of described_class do |cli|
74
- stub.proxy(cli).check_organization
75
- end
76
- end
77
- end
78
-
79
- end
80
-
81
- context "when we don't specify an organization" do
82
- subject { cf %W[create-space #{new_space.name}] }
83
-
84
- context "when we have a default organization" do
85
- it "uses that organization to create a space" do
86
- subject
87
-
88
- stdout.rewind
89
- expect(stdout.readline).to include "Creating space"
90
- end
91
- end
92
-
93
- context "when we don't have a default organization" do
94
- let(:organization) { nil }
95
-
96
- it "shows the help for the command" do
97
- subject
98
-
99
- stdout.rewind
100
- expect(stdout.readline).to include "Create a space in an organization"
101
- end
102
-
103
- it "does not try to create the space" do
104
- new_space.create! { raise "should not call this method" } # rr not behaving
105
- subject
106
- end
107
- end
108
68
  end
109
69
  end
110
70
  end
@@ -13,7 +13,7 @@ describe CF::Space::Rename do
13
13
 
14
14
  stub(cli).check_logged_in
15
15
  stub(cli).check_target
16
- stub(cli).check_organization
16
+ any_instance_of(CF::Populators::Organization, :populate_and_save! => organization)
17
17
  end
18
18
  end
19
19
 
@@ -76,15 +76,6 @@ describe CF::Space::Rename do
76
76
  context 'when no name is provided, but a space is' do
77
77
  subject { cf %W[rename-space --space #{renamed_space.name} --no-force] }
78
78
 
79
- it_should_behave_like "a_command_that_populates_organization" do
80
- subject { cf %W[rename-space --no-force --no-quiet #{renamed_space}] }
81
- before do
82
- any_instance_of described_class do |cli|
83
- stub.proxy(cli).check_organization
84
- end
85
- end
86
- end
87
-
88
79
  it 'asks for the new name and renames' do
89
80
  dont_allow_ask("Rename which space?", anything)
90
81
  mock_ask("New name") { new_name }
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe CF::Space::Space do
5
+ let(:apps) { fake_list(:app, 2) }
6
+ let(:domains) { fake_list(:domain, 2) }
7
+ let(:services) { fake_list(:service_instance, 2) }
8
+ let!(:space_1) { fake(:space, :name => "some_space_name", :apps => apps, :service_instances => services, :domains => domains) }
9
+ let(:spaces) { [space_1] }
10
+ let(:organization) { fake(:organization, :name => "Spacey Org", :spaces => spaces) }
11
+ let(:client) { fake_client(:spaces => spaces, :current_organization => organization) }
12
+
13
+ before do
14
+ any_instance_of described_class do |cli|
15
+ stub(cli).client { client }
16
+ stub(cli).check_logged_in
17
+ stub(cli).check_target
18
+ any_instance_of(CF::Populators::Organization, :populate_and_save! => organization)
19
+ any_instance_of(CF::Populators::Space, :populate_and_save! => space_1)
20
+ end
21
+ end
22
+
23
+ context "with --quiet" do
24
+ subject { cf %W[space some_space_name --quiet] }
25
+
26
+ it "shows only the name" do
27
+ subject
28
+ expect(stdout.read).to eq("some_space_name\n")
29
+ end
30
+ end
31
+
32
+ context "with --no-quiet" do
33
+ subject { cf %W[space some_space_name --no-quiet] }
34
+
35
+ before { subject }
36
+
37
+ it "shows the space's name" do
38
+ expect(stdout.read).to include("some_space_name:")
39
+ end
40
+
41
+ it "shows the space's org" do
42
+ expect(stdout.read).to include("organization: Spacey Org")
43
+ end
44
+
45
+ it "shows apps" do
46
+ expect(stdout.read).to include("apps: #{apps.first.name}, #{apps.last.name}")
47
+ end
48
+
49
+ it "shows services" do
50
+ expect(stdout.read).to include("services: #{services.first.name}, #{services.last.name}")
51
+ end
52
+
53
+ it "shows domains" do
54
+ expect(stdout.read).to include("domains: #{domains.first.name}, #{domains.last.name}")
55
+ end
56
+ end
57
+ end
@@ -7,7 +7,7 @@ describe CF::Space::Spaces do
7
7
  let!(:space_2) { fake(:space, :name => "aa_first", :apps => [fake(:app)], :service_instances => fake_list(:service_instance, 3), :domains => [fake(:domain)]) }
8
8
  let!(:space_3) { fake(:space, :name => "cc_last", :apps => fake_list(:app, 2), :service_instances => fake_list(:service_instance, 2), :domains => fake_list(:domain, 2)) }
9
9
  let(:spaces) { [space_1, space_2, space_3]}
10
- let(:organization) { fake(:organization, :spaces => spaces) }
10
+ let(:organization) { fake(:organization, :spaces => spaces, :name => 'foo') }
11
11
  let(:client) { fake_client(:spaces => spaces, :current_organization => organization) }
12
12
 
13
13
  before do
@@ -15,7 +15,7 @@ describe CF::Space::Spaces do
15
15
  stub(cli).client { client }
16
16
  stub(cli).check_logged_in
17
17
  stub(cli).check_target
18
- stub(cli).check_organization
18
+ any_instance_of(CF::Populators::Organization, :populate_and_save! => organization)
19
19
  end
20
20
  end
21
21
 
@@ -74,14 +74,6 @@ describe CF::Space::Spaces do
74
74
  end
75
75
 
76
76
  context 'when there are spaces' do
77
- it_should_behave_like "a_command_that_populates_organization" do
78
- before do
79
- any_instance_of described_class do |cli|
80
- stub.proxy(cli).check_organization
81
- end
82
- end
83
- end
84
-
85
77
  context 'and the full flag is given' do
86
78
  let(:full) { true }
87
79
 
@@ -13,9 +13,8 @@ describe CF::Space::Switch do
13
13
 
14
14
  stub(cli).check_logged_in
15
15
  stub(cli).check_target
16
- stub(cli).check_organization
16
+ any_instance_of(CF::Populators::Organization, :populate_and_save! => organization)
17
17
  end
18
-
19
18
  end
20
19
 
21
20
  describe 'metadata' do
@@ -39,7 +38,6 @@ describe CF::Space::Switch do
39
38
 
40
39
  subject { cf %W[--no-quiet switch-space #{space_to_switch_to.name} --no-color] }
41
40
 
42
-
43
41
  context "when the space exists" do
44
42
  before do
45
43
  any_instance_of(Mothership) do |m|
@@ -50,14 +48,6 @@ describe CF::Space::Switch do
50
48
  it "switches to that space" do
51
49
  subject
52
50
  end
53
-
54
- it_should_behave_like "a_command_that_populates_organization" do
55
- before do
56
- any_instance_of described_class do |cli|
57
- stub.proxy(cli).check_organization
58
- end
59
- end
60
- end
61
51
  end
62
52
 
63
53
  context "when the space does not exist" do
@@ -76,7 +76,7 @@ describe CF::CLI do
76
76
 
77
77
  it "tells the user they are not authenticated" do
78
78
  subject
79
- expect(stdout.string).to include "Invalid authentication token. Try logging in again with 'cf login'"
79
+ expect(stdout.string).to include "Invalid authentication token. Try logging in again with 'cf login'. If problems continue, please contact your Cloud Operator."
80
80
  end
81
81
 
82
82
  it "exits without attempting to login again" do
@@ -33,15 +33,15 @@ if ENV['CF_V2_RUN_INTEGRATION']
33
33
 
34
34
  it "registers a new account and deletes it" do
35
35
  email = Faker::Internet.email
36
- run("#{cf_bin} logout") do |runner|
36
+ BlueShell::Runner.run("#{cf_bin} logout") do |runner|
37
37
  runner.wait_for_exit
38
38
  end
39
39
 
40
- run("#{cf_bin} target #{target}") do |runner|
40
+ BlueShell::Runner.run("#{cf_bin} target #{target}") do |runner|
41
41
  runner.wait_for_exit
42
42
  end
43
43
 
44
- run("#{cf_bin} login #{username} --password #{password}") do |runner|
44
+ BlueShell::Runner.run("#{cf_bin} login #{username} --password #{password}") do |runner|
45
45
  expect(runner).to say(
46
46
  "Organization>" => proc {
47
47
  runner.send_keys organization
@@ -59,7 +59,7 @@ if ENV['CF_V2_RUN_INTEGRATION']
59
59
  )
60
60
  end
61
61
 
62
- run("#{cf_bin} register #{email} --password p") do |runner|
62
+ BlueShell::Runner.run("#{cf_bin} register #{email} --password p") do |runner|
63
63
  expect(runner).to say "Confirm Password>"
64
64
  runner.send_keys 'p'
65
65
  expect(runner).to say "Your password strength is: good"
@@ -67,11 +67,11 @@ if ENV['CF_V2_RUN_INTEGRATION']
67
67
  expect(runner).to say "Authenticating... OK"
68
68
  end
69
69
 
70
- run("#{cf_bin} logout") do |runner|
70
+ BlueShell::Runner.run("#{cf_bin} logout") do |runner|
71
71
  runner.wait_for_exit
72
72
  end
73
73
 
74
- run("#{cf_bin} login #{username} --password #{password}") do |runner|
74
+ BlueShell::Runner.run("#{cf_bin} login #{username} --password #{password}") do |runner|
75
75
  expect(runner).to say "Organization>"
76
76
  runner.send_keys "1"
77
77
  expect(runner).to say "Space>"
@@ -79,7 +79,7 @@ if ENV['CF_V2_RUN_INTEGRATION']
79
79
  end
80
80
 
81
81
  # TODO: do this when cf delete-user is implemented
82
- #run("#{cf_bin} delete-user #{email}") do |runner|
82
+ #BlueShell::Runner.run("#{cf_bin} delete-user #{email}") do |runner|
83
83
  # expect(runner).to say "Really delete user #{email}?>"
84
84
  # runner.send_keys "y"
85
85
  # expect(runner).to say "Deleting #{email}... OK"
@@ -93,7 +93,7 @@ if ENV['CF_V2_RUN_INTEGRATION']
93
93
  user.delete!
94
94
  client.base.uaa.delete_user(guid)
95
95
 
96
- run("#{cf_bin} login #{email} --password p") do |runner|
96
+ BlueShell::Runner.run("#{cf_bin} login #{email} --password p") do |runner|
97
97
  expect(runner).to say "Authenticating... FAILED"
98
98
 
99
99
  expect(runner).to say "Password>"