cf 0.6.1.rc3 → 0.6.1.rc4
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/cf/cli.rb +6 -3
- data/lib/cf/cli/populators/base.rb +14 -0
- data/lib/cf/cli/populators/organization.rb +23 -0
- data/lib/cf/cli/populators/populator_methods.rb +52 -0
- data/lib/cf/cli/populators/space.rb +29 -0
- data/lib/cf/cli/populators/target.rb +13 -0
- data/lib/cf/cli/service/services.rb +5 -2
- data/lib/cf/cli/space/base.rb +6 -0
- data/lib/cf/cli/space/spaces.rb +46 -44
- data/lib/cf/cli/start/base.rb +7 -56
- data/lib/cf/cli/start/login.rb +3 -8
- data/lib/cf/cli/start/target.rb +5 -9
- data/lib/cf/version.rb +1 -1
- data/spec/assets/hello-sinatra/main.rb +5 -3
- data/spec/cf/cli/app/scale_spec.rb +5 -1
- data/spec/cf/cli/app/start_spec.rb +5 -1
- data/spec/cf/cli/domain/map_spec.rb +5 -1
- data/spec/cf/cli/domain/unmap_spec.rb +5 -1
- data/spec/cf/cli/organization/orgs_spec.rb +1 -1
- data/spec/cf/cli/populators/organization_spec.rb +130 -0
- data/spec/cf/cli/populators/space_spec.rb +131 -0
- data/spec/cf/cli/populators/target_spec.rb +18 -0
- data/spec/cf/cli/route/map_spec.rb +5 -1
- data/spec/cf/cli/route/unmap_spec.rb +5 -1
- data/spec/cf/cli/service/services_spec.rb +72 -0
- data/spec/cf/cli/space/create_spec.rb +24 -7
- data/spec/cf/cli/space/rename_spec.rb +16 -5
- data/spec/cf/cli/space/spaces_spec.rb +12 -2
- data/spec/cf/cli/space/switch_space_spec.rb +18 -3
- data/spec/cf/cli/start/login_spec.rb +28 -81
- data/spec/cf/cli/start/target_spec.rb +33 -32
- data/spec/cf/cli/user/register_spec.rb +5 -1
- data/spec/cf/cli_spec.rb +21 -1
- data/spec/features/account_lifecycle_spec.rb +8 -3
- data/spec/features/login_spec.rb +16 -11
- data/spec/features/push_flow_spec.rb +26 -11
- data/spec/features/switching_targets_spec.rb +42 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/{command_helper.rb → cli_helper.rb} +18 -25
- data/spec/support/shared_examples/populate_organization.rb +6 -0
- metadata +20 -6
- data/lib/cf/cli/start/target_interactions.rb +0 -37
data/lib/cf/version.rb
CHANGED
@@ -0,0 +1,130 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "webmock/rspec"
|
3
|
+
require "cf/cli/populators/organization"
|
4
|
+
|
5
|
+
describe CF::Populators::Organization do
|
6
|
+
stub_home_dir_with { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
|
7
|
+
|
8
|
+
describe "#populate_and_save!" do
|
9
|
+
let(:tokens_file_path) { "~/.cf/tokens.yml" }
|
10
|
+
let(:user) { stub! }
|
11
|
+
let(:organizations) do
|
12
|
+
[
|
13
|
+
fake(:organization, :name => "My Org", :guid => "organization-id-1", :users => [user]),
|
14
|
+
fake(:organization, :guid => "organization-id-2")
|
15
|
+
]
|
16
|
+
end
|
17
|
+
let(:organization) { organizations.first }
|
18
|
+
let(:client) { fake_client :organizations => organizations }
|
19
|
+
|
20
|
+
let(:input) { {:organization => organization} }
|
21
|
+
let(:tokens_yaml) { YAML.load_file(File.expand_path(tokens_file_path)) }
|
22
|
+
let(:populator) { populator = CF::Populators::Organization.new(Mothership::Inputs.new(nil, nil, input)) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
stub(client).current_user { user }
|
26
|
+
stub(client).organization { organization }
|
27
|
+
stub(client).current_organization { organization }
|
28
|
+
any_instance_of(described_class) do |instance|
|
29
|
+
stub(instance).client { client }
|
30
|
+
end
|
31
|
+
|
32
|
+
write_token_file({:organization => "organization-id-1"})
|
33
|
+
end
|
34
|
+
|
35
|
+
subject do
|
36
|
+
capture_output { populator.populate_and_save! }
|
37
|
+
end
|
38
|
+
|
39
|
+
it "updates the client with the new organization" do
|
40
|
+
write_token_file({:organization => "organization-id-2"})
|
41
|
+
any_instance_of(described_class) do |instance|
|
42
|
+
stub.proxy(instance).client
|
43
|
+
end
|
44
|
+
populator.client.current_organization.guid.should == "organization-id-2"
|
45
|
+
|
46
|
+
subject
|
47
|
+
|
48
|
+
populator.client.current_organization.guid.should == "organization-id-1"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns the organization" do
|
52
|
+
subject.should == organization
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with an organization in the input" do
|
56
|
+
let(:input) { {:organization => organization} }
|
57
|
+
before { write_token_file({:organization => "organization-id-2"}) }
|
58
|
+
|
59
|
+
it "uses that organization" do
|
60
|
+
subject.should == organization
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not reprompt for organization" do
|
64
|
+
dont_allow_ask("Organization", anything)
|
65
|
+
subject
|
66
|
+
end
|
67
|
+
|
68
|
+
it "sets the organization in the token file" do
|
69
|
+
subject
|
70
|
+
expect(tokens_yaml["https://api.some-domain.com"][:organization]).to be == "organization-id-1"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "prints out that it is switching to that organization" do
|
74
|
+
subject
|
75
|
+
expect(output).to say("Switching to organization #{organization.name}")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "without an organization in the input" do
|
80
|
+
let(:input) { {} }
|
81
|
+
|
82
|
+
context "with an organization in the config file" do
|
83
|
+
it "should not reprompt for organization" do
|
84
|
+
dont_allow_ask("Organization", anything)
|
85
|
+
subject
|
86
|
+
end
|
87
|
+
|
88
|
+
it "sets the organization in the token file" do
|
89
|
+
subject
|
90
|
+
expect(tokens_yaml["https://api.some-domain.com"][:organization]).to be == "organization-id-1"
|
91
|
+
end
|
92
|
+
|
93
|
+
context "but that organization doesn't exist anymore (not valid)" do
|
94
|
+
before { stub(organization).users { raise CFoundry::APIError } }
|
95
|
+
|
96
|
+
it "asks the user for an organization" do
|
97
|
+
mock_ask("Organization", anything) { organization }
|
98
|
+
subject
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "without an organization in the config file" do
|
104
|
+
before { write_token_file({}) }
|
105
|
+
|
106
|
+
it "prompts for the organization" do
|
107
|
+
mock_ask("Organization", anything) { organization }
|
108
|
+
subject
|
109
|
+
|
110
|
+
expect(output).to say("Switching to organization #{organization.name}")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "sets the organization in the token file" do
|
114
|
+
mock_ask("Organization", anything) { organization }
|
115
|
+
|
116
|
+
subject
|
117
|
+
expect(tokens_yaml["https://api.some-domain.com"][:organization]).to be == "organization-id-1"
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when the user has no organizations" do
|
121
|
+
let(:client) { fake_client :organizations => [] }
|
122
|
+
|
123
|
+
it "tells the user to create one by raising a UserFriendlyError" do
|
124
|
+
expect { subject }.to raise_error(CF::UserFriendlyError, /There are no organizations/)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "webmock/rspec"
|
3
|
+
require "cf/cli/populators/space"
|
4
|
+
|
5
|
+
describe CF::Populators::Space do
|
6
|
+
stub_home_dir_with { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
|
7
|
+
|
8
|
+
describe "#populate_and_save!" do
|
9
|
+
let(:tokens_file_path) { "~/.cf/tokens.yml" }
|
10
|
+
let(:spaces) {
|
11
|
+
[fake(:space, :name => "Development", :guid => "space-id-1", :developers => [user]),
|
12
|
+
fake(:space, :name => "Staging", :guid => "space-id-2")]
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:user) { stub! }
|
16
|
+
let(:organization) { fake(:organization, :name => "My Org", :guid => "organization-id-1", :users => [user], :spaces => spaces) }
|
17
|
+
let(:space) { spaces.first }
|
18
|
+
let(:client) do
|
19
|
+
fake_client :organizations => [organization]
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:input) { {:space => space} }
|
23
|
+
let(:tokens_yaml) { YAML.load_file(File.expand_path(tokens_file_path)) }
|
24
|
+
let(:populator) { populator = CF::Populators::Space.new(Mothership::Inputs.new(nil, nil, input), organization) }
|
25
|
+
|
26
|
+
before do
|
27
|
+
stub(client).current_user { user }
|
28
|
+
stub(client).space { space }
|
29
|
+
any_instance_of(described_class) do |instance|
|
30
|
+
stub(instance).client { client }
|
31
|
+
end
|
32
|
+
|
33
|
+
write_token_file({:space => "space-id-1", :organization => "organization-id-1"})
|
34
|
+
end
|
35
|
+
|
36
|
+
subject do
|
37
|
+
capture_output { populator.populate_and_save! }
|
38
|
+
end
|
39
|
+
|
40
|
+
it "updates the client with the new space" do
|
41
|
+
write_token_file({:space => "space-id-2"})
|
42
|
+
any_instance_of(described_class) do |instance|
|
43
|
+
stub.proxy(instance).client
|
44
|
+
end
|
45
|
+
populator.client.current_space.guid.should == "space-id-2"
|
46
|
+
|
47
|
+
subject
|
48
|
+
|
49
|
+
populator.client.current_space.guid.should == "space-id-1"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns the space" do
|
53
|
+
subject.should == space
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with a space in the input" do
|
57
|
+
let(:input) { {:space => space} }
|
58
|
+
before { write_token_file({:space => "space-id-2"}) }
|
59
|
+
|
60
|
+
it "uses that space" do
|
61
|
+
subject.should == space
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not reprompt for space" do
|
65
|
+
dont_allow_ask("Space", anything)
|
66
|
+
subject
|
67
|
+
end
|
68
|
+
|
69
|
+
it "sets the space in the token file" do
|
70
|
+
subject
|
71
|
+
expect(tokens_yaml["https://api.some-domain.com"][:space]).to be == "space-id-1"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "prints out that it is switching to that space" do
|
75
|
+
subject
|
76
|
+
expect(output).to say("Switching to space #{space.name}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "without a space in the input" do
|
81
|
+
let(:input) { {} }
|
82
|
+
|
83
|
+
context "with a space in the config file" do
|
84
|
+
it "should not reprompt for space" do
|
85
|
+
dont_allow_ask("Space", anything)
|
86
|
+
subject
|
87
|
+
end
|
88
|
+
|
89
|
+
it "sets the space in the token file" do
|
90
|
+
subject
|
91
|
+
expect(tokens_yaml["https://api.some-domain.com"][:space]).to be == "space-id-1"
|
92
|
+
end
|
93
|
+
|
94
|
+
context "but that space doesn't exist anymore (not valid)" do
|
95
|
+
before { stub(space).developers { raise CFoundry::APIError } }
|
96
|
+
|
97
|
+
it "asks the user for an space" do
|
98
|
+
mock_ask("Space", anything) { space }
|
99
|
+
subject
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "without a space in the config file" do
|
105
|
+
before { write_token_file({}) }
|
106
|
+
|
107
|
+
it "prompts for the space" do
|
108
|
+
mock_ask("Space", anything) { space }
|
109
|
+
subject
|
110
|
+
|
111
|
+
expect(output).to say("Switching to space #{space.name}")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "sets the space in the token file" do
|
115
|
+
mock_ask("Space", anything) { space }
|
116
|
+
|
117
|
+
subject
|
118
|
+
expect(tokens_yaml["https://api.some-domain.com"][:space]).to be == "space-id-1"
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when the user has no spaces in that organization" do
|
122
|
+
let(:organization) { fake(:organization, :name => "My Org", :guid => "organization-id-1", :users => [user]) }
|
123
|
+
|
124
|
+
it "tells the user to create one by raising a UserFriendlyError" do
|
125
|
+
expect { subject }.to raise_error(CF::UserFriendlyError, /There are no spaces/)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "webmock/rspec"
|
3
|
+
require "cf/cli/populators/target"
|
4
|
+
|
5
|
+
describe CF::Populators::Target do
|
6
|
+
describe "#populate_and_save!" do
|
7
|
+
let(:input) { stub! }
|
8
|
+
let(:organization) { stub! }
|
9
|
+
|
10
|
+
subject { CF::Populators::Target.new(input).populate_and_save! }
|
11
|
+
|
12
|
+
it "uses a organization then a space populator" do
|
13
|
+
mock(CF::Populators::Organization).new(input) { mock!.populate_and_save! { organization } }
|
14
|
+
mock(CF::Populators::Space).new(input, organization) { mock!.populate_and_save! }
|
15
|
+
subject
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe CF::Route::Map do
|
4
|
+
before do
|
5
|
+
stub_client_and_precondition
|
6
|
+
end
|
7
|
+
|
4
8
|
let(:client) { fake_client(:apps => apps, :routes => routes) }
|
5
9
|
|
6
10
|
let(:app) { fake(:app, :space => space, :name => "app-name") }
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CF::Service::Services do
|
4
|
+
let(:command) { Mothership.commands[:services] }
|
5
|
+
|
6
|
+
describe 'metadata' do
|
7
|
+
describe 'command' do
|
8
|
+
subject { command }
|
9
|
+
its(:description) { should eq "List your services" }
|
10
|
+
it { expect(Mothership::Help.group(:services)).to include(subject) }
|
11
|
+
end
|
12
|
+
|
13
|
+
include_examples 'inputs must have descriptions'
|
14
|
+
|
15
|
+
describe 'arguments' do
|
16
|
+
subject { command.arguments }
|
17
|
+
it 'has no required arguments' do
|
18
|
+
should eq([])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'inputs' do
|
23
|
+
subject { command.inputs }
|
24
|
+
it 'has the expected inputs' do
|
25
|
+
subject.keys.should =~ [:name, :service, :plan, :provider, :version, :app, :full, :space]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'listing services' do
|
31
|
+
let(:global) { { :color => false } }
|
32
|
+
let(:inputs) { {} }
|
33
|
+
let(:given) { {} }
|
34
|
+
let(:client) { fake_client(:current_space => current_space, :service_instances => service_instances) }
|
35
|
+
|
36
|
+
let(:service_plan) { fake(:service_plan, :service => fake(:service, :version => 'service_version', :provider => 'provider') ) }
|
37
|
+
let(:service1) { fake(:service_instance, :service_plan => service_plan ) }
|
38
|
+
|
39
|
+
let(:service_instances) { [service1] }
|
40
|
+
let(:current_space) { fake(:space, :name => 'the space' ) }
|
41
|
+
|
42
|
+
subject do
|
43
|
+
capture_output { Mothership.new.invoke(:services, inputs, given, global) }
|
44
|
+
end
|
45
|
+
|
46
|
+
before do
|
47
|
+
any_instance_of(CF::CLI) do |cli|
|
48
|
+
stub(cli).client { client }
|
49
|
+
stub(cli).precondition { nil }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'produces a table of services' do
|
54
|
+
subject
|
55
|
+
stdout.rewind
|
56
|
+
output = stdout.read
|
57
|
+
|
58
|
+
expect(output).to match /Getting services in the space.*OK/
|
59
|
+
|
60
|
+
expect(output).to match /name\s+service\s+provider\s+version\s+plan\s+bound apps/
|
61
|
+
expect(output).to match /service_instance-.+?\s+ # name
|
62
|
+
service-.*?\s+ # service
|
63
|
+
provider.*?\s+ # provider
|
64
|
+
service_version\s+ # version
|
65
|
+
service_plan-.*?\s+ # plan
|
66
|
+
none\s+ # bound apps
|
67
|
+
/x
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|