trucker-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +1277 -0
- data/Rakefile +13 -0
- data/bin/truck +18 -0
- data/lib/admin/README.md +30 -0
- data/lib/admin/curl.rb +59 -0
- data/lib/admin/guid.rb +89 -0
- data/lib/admin/plugin.rb +8 -0
- data/lib/admin/service_auth_token.rb +93 -0
- data/lib/admin/service_broker/add.rb +54 -0
- data/lib/admin/service_broker/remove.rb +33 -0
- data/lib/admin/service_broker/service_brokers.rb +29 -0
- data/lib/admin/service_broker/update.rb +60 -0
- data/lib/admin/set_quota.rb +44 -0
- data/lib/cf.rb +14 -0
- data/lib/cf/cli.rb +495 -0
- data/lib/cf/cli/app/app.rb +43 -0
- data/lib/cf/cli/app/apps.rb +87 -0
- data/lib/cf/cli/app/base.rb +72 -0
- data/lib/cf/cli/app/delete.rb +95 -0
- data/lib/cf/cli/app/deprecated.rb +11 -0
- data/lib/cf/cli/app/env.rb +99 -0
- data/lib/cf/cli/app/events.rb +45 -0
- data/lib/cf/cli/app/files.rb +137 -0
- data/lib/cf/cli/app/health.rb +26 -0
- data/lib/cf/cli/app/instances.rb +53 -0
- data/lib/cf/cli/app/logs.rb +76 -0
- data/lib/cf/cli/app/push.rb +104 -0
- data/lib/cf/cli/app/push/create.rb +108 -0
- data/lib/cf/cli/app/push/interactions.rb +90 -0
- data/lib/cf/cli/app/push/sync.rb +57 -0
- data/lib/cf/cli/app/rename.rb +35 -0
- data/lib/cf/cli/app/restart.rb +31 -0
- data/lib/cf/cli/app/scale.rb +63 -0
- data/lib/cf/cli/app/start.rb +175 -0
- data/lib/cf/cli/app/stats.rb +66 -0
- data/lib/cf/cli/app/stop.rb +27 -0
- data/lib/cf/cli/domain/base.rb +9 -0
- data/lib/cf/cli/domain/domains.rb +40 -0
- data/lib/cf/cli/domain/map.rb +55 -0
- data/lib/cf/cli/domain/unmap.rb +56 -0
- data/lib/cf/cli/help.rb +15 -0
- data/lib/cf/cli/interactive.rb +104 -0
- data/lib/cf/cli/login_requirements.rb +13 -0
- data/lib/cf/cli/organization/base.rb +12 -0
- data/lib/cf/cli/organization/create.rb +36 -0
- data/lib/cf/cli/organization/delete.rb +61 -0
- data/lib/cf/cli/organization/org.rb +45 -0
- data/lib/cf/cli/organization/orgs.rb +30 -0
- data/lib/cf/cli/organization/rename.rb +36 -0
- data/lib/cf/cli/populators/base.rb +16 -0
- data/lib/cf/cli/populators/organization.rb +32 -0
- data/lib/cf/cli/populators/populator_methods.rb +64 -0
- data/lib/cf/cli/populators/space.rb +33 -0
- data/lib/cf/cli/populators/target.rb +14 -0
- data/lib/cf/cli/route/base.rb +9 -0
- data/lib/cf/cli/route/delete.rb +28 -0
- data/lib/cf/cli/route/map.rb +68 -0
- data/lib/cf/cli/route/routes.rb +26 -0
- data/lib/cf/cli/route/unmap.rb +56 -0
- data/lib/cf/cli/service/base.rb +9 -0
- data/lib/cf/cli/service/bind.rb +43 -0
- data/lib/cf/cli/service/create.rb +158 -0
- data/lib/cf/cli/service/delete.rb +82 -0
- data/lib/cf/cli/service/rename.rb +35 -0
- data/lib/cf/cli/service/service.rb +40 -0
- data/lib/cf/cli/service/service_helper.rb +25 -0
- data/lib/cf/cli/service/service_instance_helper.rb +100 -0
- data/lib/cf/cli/service/services.rb +110 -0
- data/lib/cf/cli/service/unbind.rb +36 -0
- data/lib/cf/cli/space/base.rb +27 -0
- data/lib/cf/cli/space/create.rb +66 -0
- data/lib/cf/cli/space/delete.rb +55 -0
- data/lib/cf/cli/space/rename.rb +38 -0
- data/lib/cf/cli/space/space.rb +66 -0
- data/lib/cf/cli/space/spaces.rb +57 -0
- data/lib/cf/cli/space/switch.rb +18 -0
- data/lib/cf/cli/start/base.rb +35 -0
- data/lib/cf/cli/start/colors.rb +13 -0
- data/lib/cf/cli/start/login.rb +104 -0
- data/lib/cf/cli/start/logout.rb +17 -0
- data/lib/cf/cli/start/target.rb +50 -0
- data/lib/cf/cli/start/target_prettifier.rb +35 -0
- data/lib/cf/cli/start/targets.rb +16 -0
- data/lib/cf/cli/user/base.rb +29 -0
- data/lib/cf/cli/user/create.rb +51 -0
- data/lib/cf/cli/user/passwd.rb +36 -0
- data/lib/cf/cli/user/register.rb +42 -0
- data/lib/cf/cli/user/users.rb +32 -0
- data/lib/cf/constants.rb +10 -0
- data/lib/cf/errors.rb +19 -0
- data/lib/cf/plugin.rb +56 -0
- data/lib/cf/spacing.rb +89 -0
- data/lib/cf/spec_helper.rb +1 -0
- data/lib/cf/test_support.rb +6 -0
- data/lib/cf/version.rb +3 -0
- data/lib/console/README.md +16 -0
- data/lib/console/console.rb +187 -0
- data/lib/console/plugin.rb +32 -0
- data/lib/manifests/errors.rb +35 -0
- data/lib/manifests/loader.rb +31 -0
- data/lib/manifests/loader/builder.rb +39 -0
- data/lib/manifests/loader/normalizer.rb +145 -0
- data/lib/manifests/loader/resolver.rb +79 -0
- data/lib/manifests/manifests.rb +343 -0
- data/lib/manifests/plugin.rb +140 -0
- data/lib/micro/README.md +25 -0
- data/lib/micro/errors.rb +4 -0
- data/lib/micro/micro.rb +56 -0
- data/lib/micro/plugin.rb +197 -0
- data/lib/micro/switcher/base.rb +79 -0
- data/lib/micro/switcher/darwin.rb +21 -0
- data/lib/micro/switcher/dummy.rb +15 -0
- data/lib/micro/switcher/linux.rb +16 -0
- data/lib/micro/switcher/windows.rb +31 -0
- data/lib/micro/vmrun.rb +175 -0
- data/lib/tasks/gem_release.rake +56 -0
- data/lib/tasks/windows_build.rake +14 -0
- data/lib/tunnel/README.md +29 -0
- data/lib/tunnel/config/clients.yml +17 -0
- data/lib/tunnel/helper-app/Gemfile +10 -0
- data/lib/tunnel/helper-app/Gemfile.lock +48 -0
- data/lib/tunnel/helper-app/server.rb +43 -0
- data/lib/tunnel/plugin.rb +183 -0
- data/lib/tunnel/tunnel.rb +295 -0
- data/spec/admin/curl_spec.rb +52 -0
- data/spec/admin/guid_spec.rb +85 -0
- data/spec/admin/service_broker/add_spec.rb +64 -0
- data/spec/admin/service_broker/remove_spec.rb +46 -0
- data/spec/admin/service_broker/service_brokers_spec.rb +34 -0
- data/spec/admin/service_broker/update_spec.rb +51 -0
- data/spec/admin/set_quota_spec.rb +89 -0
- data/spec/assets/env/Gemfile +4 -0
- data/spec/assets/env/Gemfile.lock +20 -0
- data/spec/assets/env/env_test.rb +58 -0
- data/spec/assets/hello-sinatra/Gemfile +3 -0
- data/spec/assets/hello-sinatra/Gemfile.lock +17 -0
- data/spec/assets/hello-sinatra/config.ru +3 -0
- data/spec/assets/hello-sinatra/fat-cat-makes-app-larger.png +0 -0
- data/spec/assets/hello-sinatra/main.rb +8 -0
- data/spec/assets/rails328_ruby187_app/Gemfile +39 -0
- data/spec/assets/rails328_ruby187_app/README.rdoc +261 -0
- data/spec/assets/rails328_ruby187_app/Rakefile +7 -0
- data/spec/assets/rails328_ruby187_app/app/assets/images/rails.png +0 -0
- data/spec/assets/rails328_ruby187_app/app/assets/javascripts/application.js +15 -0
- data/spec/assets/rails328_ruby187_app/app/assets/stylesheets/application.css +13 -0
- data/spec/assets/rails328_ruby187_app/app/controllers/application_controller.rb +3 -0
- data/spec/assets/rails328_ruby187_app/app/helpers/application_helper.rb +2 -0
- data/spec/assets/rails328_ruby187_app/app/views/layouts/application.html.erb +14 -0
- data/spec/assets/rails328_ruby187_app/config.ru +4 -0
- data/spec/assets/rails328_ruby187_app/config/application.rb +62 -0
- data/spec/assets/rails328_ruby187_app/config/boot.rb +6 -0
- data/spec/assets/rails328_ruby187_app/config/database.yml +25 -0
- data/spec/assets/rails328_ruby187_app/config/environment.rb +5 -0
- data/spec/assets/rails328_ruby187_app/config/environments/development.rb +37 -0
- data/spec/assets/rails328_ruby187_app/config/environments/production.rb +67 -0
- data/spec/assets/rails328_ruby187_app/config/environments/test.rb +37 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/inflections.rb +15 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/mime_types.rb +5 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/secret_token.rb +7 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/session_store.rb +8 -0
- data/spec/assets/rails328_ruby187_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/assets/rails328_ruby187_app/config/locales/en.yml +5 -0
- data/spec/assets/rails328_ruby187_app/config/routes.rb +58 -0
- data/spec/assets/rails328_ruby187_app/db/seeds.rb +7 -0
- data/spec/assets/rails328_ruby187_app/doc/README_FOR_APP +2 -0
- data/spec/assets/rails328_ruby187_app/manifest.yml +7 -0
- data/spec/assets/rails328_ruby187_app/public/404.html +26 -0
- data/spec/assets/rails328_ruby187_app/public/422.html +26 -0
- data/spec/assets/rails328_ruby187_app/public/500.html +25 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js +17 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.css +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.css.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.js +17 -0
- data/spec/assets/rails328_ruby187_app/public/assets/application.js.gz +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/manifest.yml +4 -0
- data/spec/assets/rails328_ruby187_app/public/assets/rails-be8732dac73d845ac5b142c8fb5f9fb0.png +0 -0
- data/spec/assets/rails328_ruby187_app/public/assets/rails.png +0 -0
- data/spec/assets/rails328_ruby187_app/public/favicon.ico +0 -0
- data/spec/assets/rails328_ruby187_app/public/index.html +241 -0
- data/spec/assets/rails328_ruby187_app/public/robots.txt +5 -0
- data/spec/assets/rails328_ruby187_app/script/rails +6 -0
- data/spec/assets/rails328_ruby187_app/test/performance/browsing_test.rb +12 -0
- data/spec/assets/rails328_ruby187_app/test/test_helper.rb +13 -0
- data/spec/cf/cli/app/base_spec.rb +17 -0
- data/spec/cf/cli/app/delete_spec.rb +197 -0
- data/spec/cf/cli/app/env_spec.rb +261 -0
- data/spec/cf/cli/app/events_spec.rb +72 -0
- data/spec/cf/cli/app/help_spec.rb +39 -0
- data/spec/cf/cli/app/instances_spec.rb +69 -0
- data/spec/cf/cli/app/push/create_spec.rb +444 -0
- data/spec/cf/cli/app/push/interactions_spec.rb +32 -0
- data/spec/cf/cli/app/push_spec.rb +332 -0
- data/spec/cf/cli/app/rename_spec.rb +108 -0
- data/spec/cf/cli/app/restart_spec.rb +47 -0
- data/spec/cf/cli/app/scale_spec.rb +63 -0
- data/spec/cf/cli/app/start_spec.rb +255 -0
- data/spec/cf/cli/app/stats_spec.rb +66 -0
- data/spec/cf/cli/domain/help_spec.rb +39 -0
- data/spec/cf/cli/domain/map_spec.rb +140 -0
- data/spec/cf/cli/domain/unmap_spec.rb +77 -0
- data/spec/cf/cli/help_spec.rb +21 -0
- data/spec/cf/cli/organization/create_spec.rb +121 -0
- data/spec/cf/cli/organization/delete_spec.rb +105 -0
- data/spec/cf/cli/organization/help_spec.rb +39 -0
- data/spec/cf/cli/organization/orgs_spec.rb +116 -0
- data/spec/cf/cli/organization/rename_spec.rb +116 -0
- data/spec/cf/cli/populators/organization_spec.rb +179 -0
- data/spec/cf/cli/populators/space_spec.rb +156 -0
- data/spec/cf/cli/populators/target_spec.rb +39 -0
- data/spec/cf/cli/route/delete_spec.rb +92 -0
- data/spec/cf/cli/route/help_spec.rb +32 -0
- data/spec/cf/cli/route/map_spec.rb +148 -0
- data/spec/cf/cli/route/unmap_spec.rb +114 -0
- data/spec/cf/cli/service/bind_spec.rb +25 -0
- data/spec/cf/cli/service/create_spec.rb +147 -0
- data/spec/cf/cli/service/delete_spec.rb +22 -0
- data/spec/cf/cli/service/help_spec.rb +39 -0
- data/spec/cf/cli/service/rename_spec.rb +103 -0
- data/spec/cf/cli/service/service_helper_spec.rb +66 -0
- data/spec/cf/cli/service/service_instance_helper_spec.rb +155 -0
- data/spec/cf/cli/service/service_spec.rb +23 -0
- data/spec/cf/cli/service/services_spec.rb +156 -0
- data/spec/cf/cli/service/unbind_spec.rb +25 -0
- data/spec/cf/cli/space/base_spec.rb +49 -0
- data/spec/cf/cli/space/create_spec.rb +144 -0
- data/spec/cf/cli/space/delete_spec.rb +109 -0
- data/spec/cf/cli/space/help_spec.rb +39 -0
- data/spec/cf/cli/space/rename_spec.rb +110 -0
- data/spec/cf/cli/space/space_spec.rb +80 -0
- data/spec/cf/cli/space/spaces_spec.rb +107 -0
- data/spec/cf/cli/space/switch_space_spec.rb +57 -0
- data/spec/cf/cli/start/help_spec.rb +39 -0
- data/spec/cf/cli/start/login_spec.rb +142 -0
- data/spec/cf/cli/start/logout_spec.rb +49 -0
- data/spec/cf/cli/start/target_prettifier_spec.rb +78 -0
- data/spec/cf/cli/start/target_spec.rb +123 -0
- data/spec/cf/cli/user/create_spec.rb +98 -0
- data/spec/cf/cli/user/help_spec.rb +32 -0
- data/spec/cf/cli/user/passwd_spec.rb +94 -0
- data/spec/cf/cli/user/register_spec.rb +145 -0
- data/spec/cf/cli_spec.rb +474 -0
- data/spec/console/console_spec.rb +189 -0
- data/spec/factories/cfoundry/v2/apps_factory.rb +12 -0
- data/spec/factories/cfoundry/v2/clients_factory.rb +7 -0
- data/spec/factories/cfoundry/v2/domains_factory.rb +8 -0
- data/spec/factories/cfoundry/v2/managed_service_instances_factory.rb +13 -0
- data/spec/factories/cfoundry/v2/organizations_factory.rb +14 -0
- data/spec/factories/cfoundry/v2/quota_definitions.rb +13 -0
- data/spec/factories/cfoundry/v2/routes_factory.rb +8 -0
- data/spec/factories/cfoundry/v2/service_bindings_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/service_brokers_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/service_plans_factory.rb +17 -0
- data/spec/factories/cfoundry/v2/services_factory.rb +14 -0
- data/spec/factories/cfoundry/v2/spaces_factory.rb +13 -0
- data/spec/factories/cfoundry/v2/stacks_factory.rb +11 -0
- data/spec/factories/cfoundry/v2/user_provided_service_instances_factory.rb +12 -0
- data/spec/factories/cfoundry/v2/users_factory.rb +7 -0
- data/spec/features/backspace_spec.rb +46 -0
- data/spec/features/create_user_spec.rb +74 -0
- data/spec/features/delete_orphaned_service_spec.rb +64 -0
- data/spec/features/login_spec.rb +65 -0
- data/spec/features/manifests_spec.rb +86 -0
- data/spec/features/org_spec.rb +50 -0
- data/spec/features/push_flow_spec.rb +169 -0
- data/spec/features/service_brokers_spec.rb +173 -0
- data/spec/features/services_spec.rb +122 -0
- data/spec/features/space_spec.rb +107 -0
- data/spec/features/switching_targets_spec.rb +70 -0
- data/spec/manifests/errors_spec.rb +43 -0
- data/spec/manifests/loader/builder_spec.rb +80 -0
- data/spec/manifests/loader/normalizer_spec.rb +158 -0
- data/spec/manifests/manifests_spec.rb +335 -0
- data/spec/manifests/plugin_spec.rb +410 -0
- data/spec/micro/plugin_spec.rb +64 -0
- data/spec/spec_helper.rb +69 -0
- data/spec/support/cli_helper.rb +87 -0
- data/spec/support/config_helper.rb +15 -0
- data/spec/support/factory_girl.rb +6 -0
- data/spec/support/fake_home_dir.rb +55 -0
- data/spec/support/features_helper.rb +99 -0
- data/spec/support/interact_helper.rb +27 -0
- data/spec/support/matchers.rb +16 -0
- data/spec/support/mock_commands/mock_restart.rb +16 -0
- data/spec/support/mock_commands/mock_start.rb +17 -0
- data/spec/support/shared_examples/errors.rb +40 -0
- data/spec/support/shared_examples/input.rb +14 -0
- data/spec/tunnel/plugin_spec.rb +31 -0
- data/spec/tunnel/tunnel_spec.rb +54 -0
- metadata +814 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module CF
|
4
|
+
module Organization
|
5
|
+
describe "Help" do
|
6
|
+
let(:global) { {} }
|
7
|
+
let(:given) { {} }
|
8
|
+
|
9
|
+
subject do
|
10
|
+
capture_output { Mothership.new.invoke(:help, :command => "org") }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "describes the command" do
|
14
|
+
subject
|
15
|
+
stdout.rewind
|
16
|
+
expect(stdout.readlines.first).to match /Show organization information/
|
17
|
+
end
|
18
|
+
|
19
|
+
it "prints the options" do
|
20
|
+
subject
|
21
|
+
stdout.rewind
|
22
|
+
expect(stdout.readlines.any? {|line| line =~ /Options:/ }).to be_true
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when the user is not logged in" do
|
27
|
+
before do
|
28
|
+
capture_output { Mothership.new.invoke(:logout) }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "does not require login" do
|
32
|
+
subject
|
33
|
+
stdout.rewind
|
34
|
+
expect(stdout.readlines.first).to_not match /Please log in first to proceed/
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module CF
|
4
|
+
module Organization
|
5
|
+
describe Orgs do
|
6
|
+
let(:global) { {:color => false} }
|
7
|
+
let(:inputs) { {} }
|
8
|
+
let(:given) { {} }
|
9
|
+
let(:output) { StringIO.new }
|
10
|
+
|
11
|
+
let(:client) { build(:client) }
|
12
|
+
let(:space) { build(:space) }
|
13
|
+
let(:domain) { build(:domain) }
|
14
|
+
let!(:org_1) { build(:organization, :name => "bb_second", :spaces => [space], :domains => [domain]) }
|
15
|
+
let!(:org_2) { build(:organization, :name => "aa_first", :spaces => [space], :domains => [domain]) }
|
16
|
+
let!(:org_3) { build(:organization, :name => "cc_last", :spaces => [space], :domains => [domain]) }
|
17
|
+
let(:organizations) { [org_1, org_2, org_3] }
|
18
|
+
|
19
|
+
before do
|
20
|
+
CF::CLI.any_instance.stub(:client) { client }
|
21
|
+
CF::CLI.any_instance.stub(:precondition) { nil }
|
22
|
+
|
23
|
+
client.stub(:organizations).and_return(organizations)
|
24
|
+
end
|
25
|
+
|
26
|
+
subject do
|
27
|
+
capture_output { Mothership.new.invoke(:orgs, inputs, given, global) }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "metadata" do
|
31
|
+
let(:command) { Mothership.commands[:orgs] }
|
32
|
+
|
33
|
+
describe "command" do
|
34
|
+
subject { command }
|
35
|
+
its(:description) { should eq "List available organizations" }
|
36
|
+
it { expect(Mothership::Help.group(:organizations)).to include(subject) }
|
37
|
+
end
|
38
|
+
|
39
|
+
include_examples "inputs must have descriptions"
|
40
|
+
|
41
|
+
describe "arguments" do
|
42
|
+
subject { command.arguments }
|
43
|
+
it "has no arguments" do
|
44
|
+
should be_empty
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should have the correct first two lines" do
|
50
|
+
subject
|
51
|
+
stdout.rewind
|
52
|
+
expect(stdout.readline).to match /Getting organizations.*OK/
|
53
|
+
expect(stdout.readline).to eq "\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when there are no organizations" do
|
57
|
+
let(:organizations) { [] }
|
58
|
+
|
59
|
+
context "and the full flag is given" do
|
60
|
+
let(:inputs) { {:full => true} }
|
61
|
+
|
62
|
+
it "displays yaml-style output with all organization details" do
|
63
|
+
CF::Organization::Orgs.any_instance.should_not_receive(:invoke)
|
64
|
+
subject
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "and the full flag is not given (default is false)" do
|
69
|
+
it "should show only the progress" do
|
70
|
+
subject
|
71
|
+
|
72
|
+
stdout.rewind
|
73
|
+
expect(stdout.readline).to match /Getting organizations.*OK/
|
74
|
+
expect(stdout).to be_eof
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when there are organizations" do
|
80
|
+
context "and the full flag is given" do
|
81
|
+
let(:inputs) { {:full => true} }
|
82
|
+
|
83
|
+
it "displays yaml-style output with all organization details" do
|
84
|
+
CF::Organization::Orgs.any_instance.should_receive(:invoke).with(:org, :organization => org_2, :full => true)
|
85
|
+
CF::Organization::Orgs.any_instance.should_receive(:invoke).with(:org, :organization => org_1, :full => true)
|
86
|
+
CF::Organization::Orgs.any_instance.should_receive(:invoke).with(:org, :organization => org_3, :full => true)
|
87
|
+
subject
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "and the full flag is not given (default is false)" do
|
92
|
+
|
93
|
+
before do
|
94
|
+
org_1.stub(:spaces).and_return([space])
|
95
|
+
org_2.stub(:spaces).and_return([space])
|
96
|
+
org_3.stub(:spaces).and_return([space])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "displays tabular output with names, spaces and domains" do
|
100
|
+
subject
|
101
|
+
|
102
|
+
stdout.rewind
|
103
|
+
stdout.readline
|
104
|
+
stdout.readline
|
105
|
+
|
106
|
+
expect(stdout.readline).to match /name/
|
107
|
+
organizations.sort_by(&:name).each do |org|
|
108
|
+
expect(stdout.readline).to match /#{org.name}/
|
109
|
+
end
|
110
|
+
expect(stdout).to be_eof
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module CF
|
4
|
+
module Organization
|
5
|
+
describe Rename do
|
6
|
+
let(:global) { {:color => false, :quiet => true} }
|
7
|
+
let(:inputs) { {} }
|
8
|
+
let(:given) { {} }
|
9
|
+
|
10
|
+
let(:new_name) { "some-new-name" }
|
11
|
+
let(:organizations) { [build(:organization)] }
|
12
|
+
let(:client) { build(:client) }
|
13
|
+
|
14
|
+
before do
|
15
|
+
CF::CLI.any_instance.stub(:client).and_return(client)
|
16
|
+
CF::CLI.any_instance.stub(:precondition).and_return(nil)
|
17
|
+
client.stub(:organizations).and_return(organizations)
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { Mothership.new.invoke(:rename_org, inputs, given, global) }
|
21
|
+
|
22
|
+
describe "metadata" do
|
23
|
+
let(:command) { Mothership.commands[:rename_org] }
|
24
|
+
|
25
|
+
describe "command" do
|
26
|
+
subject { command }
|
27
|
+
its(:description) { should eq "Rename an organization" }
|
28
|
+
it { expect(Mothership::Help.group(:organizations)).to include(subject) }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "inputs" do
|
32
|
+
subject { command.inputs }
|
33
|
+
|
34
|
+
it "is not missing any descriptions" do
|
35
|
+
subject.each do |input, attrs|
|
36
|
+
expect(attrs[:description]).to be
|
37
|
+
expect(attrs[:description].strip).to_not be_empty
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "arguments" do
|
43
|
+
subject { command.arguments }
|
44
|
+
it "has the correct argument order" do
|
45
|
+
should eq([
|
46
|
+
{:type => :optional, :value => nil, :name => :organization},
|
47
|
+
{:type => :optional, :value => nil, :name => :name}
|
48
|
+
])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when there are no organizations" do
|
54
|
+
let(:organizations) { [] }
|
55
|
+
|
56
|
+
context "and an organization is given" do
|
57
|
+
let(:given) { {:organization => "some-invalid-organization"} }
|
58
|
+
it { expect { subject }.to raise_error(CF::UserError, "Unknown organization 'some-invalid-organization'.") }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "and an organization is not given" do
|
62
|
+
it { expect { subject }.to raise_error(CF::UserError, "No organizations.") }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when there are organizations" do
|
67
|
+
let(:renamed_organization) { organizations.first }
|
68
|
+
|
69
|
+
context "when the defaults are used" do
|
70
|
+
it "asks for the organization and new name and renames" do
|
71
|
+
should_ask("Rename which organization?", anything) { renamed_organization }
|
72
|
+
should_ask("New name") { new_name }
|
73
|
+
renamed_organization.should_receive(:name=).with(new_name)
|
74
|
+
renamed_organization.should_receive(:update!)
|
75
|
+
subject
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when no name is provided, but an organization is" do
|
80
|
+
let(:given) { {:organization => renamed_organization.name} }
|
81
|
+
|
82
|
+
it "asks for the new name and renames" do
|
83
|
+
dont_allow_ask("Rename which organization?", anything)
|
84
|
+
should_ask("New name") { new_name }
|
85
|
+
renamed_organization.should_receive(:name=).with(new_name)
|
86
|
+
renamed_organization.should_receive(:update!)
|
87
|
+
subject
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "when an organization is provided and a name" do
|
92
|
+
let(:inputs) { {:organization => renamed_organization, :name => new_name} }
|
93
|
+
|
94
|
+
it "renames the organization" do
|
95
|
+
renamed_organization.should_receive(:update!)
|
96
|
+
subject
|
97
|
+
end
|
98
|
+
|
99
|
+
it "displays the progress" do
|
100
|
+
mock_with_progress("Renaming to #{new_name}")
|
101
|
+
renamed_organization.should_receive(:update!)
|
102
|
+
|
103
|
+
subject
|
104
|
+
end
|
105
|
+
|
106
|
+
context "and the name already exists" do
|
107
|
+
it "fails" do
|
108
|
+
renamed_organization.should_receive(:update!) { raise CFoundry::OrganizationNameTaken.new("Bad error", 200) }
|
109
|
+
expect { subject }.to raise_error(CFoundry::OrganizationNameTaken)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module CF
|
4
|
+
module Populators
|
5
|
+
describe 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_FILE }
|
10
|
+
let(:user) { build(:user) }
|
11
|
+
let(:client) { build(:client) }
|
12
|
+
let(:organizations) do
|
13
|
+
[
|
14
|
+
build(:organization, :name => "My Org", :guid => "organization-id-1", :users => [user]),
|
15
|
+
build(:organization, :name => "Other Org", :guid => "organization-id-2")
|
16
|
+
]
|
17
|
+
end
|
18
|
+
let(:organization) { organizations.first }
|
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
|
+
client.stub(:current_user).and_return(user)
|
26
|
+
client.stub(:organization).and_return(organization)
|
27
|
+
client.stub(:current_organization).and_return(organization)
|
28
|
+
client.stub(:target).and_return('https://api.some-domain.com')
|
29
|
+
described_class.any_instance.stub(:client).and_return(client)
|
30
|
+
|
31
|
+
write_token_file({:organization => "organization-id-1"})
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute_populate_and_save
|
35
|
+
capture_output { populator.populate_and_save! }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "updates the client with the new organization" do
|
39
|
+
write_token_file({:organization => "organization-id-2"})
|
40
|
+
described_class.any_instance.unstub(:client)
|
41
|
+
populator.client.current_organization.guid.should == "organization-id-2"
|
42
|
+
|
43
|
+
execute_populate_and_save
|
44
|
+
|
45
|
+
populator.client.current_organization.guid.should == "organization-id-1"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns the organization" do
|
49
|
+
execute_populate_and_save.should == organization
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with an organization in the input" do
|
53
|
+
let(:input) { {:organization => organization} }
|
54
|
+
before { write_token_file({:organization => "organization-id-2"}) }
|
55
|
+
|
56
|
+
it "uses that organization" do
|
57
|
+
execute_populate_and_save.should == organization
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not reprompt for organization" do
|
61
|
+
dont_allow_ask("Organization", anything)
|
62
|
+
execute_populate_and_save
|
63
|
+
end
|
64
|
+
|
65
|
+
it "sets the organization in the token file" do
|
66
|
+
execute_populate_and_save
|
67
|
+
expect(tokens_yaml["https://api.some-domain.com"][:organization]).to be == "organization-id-1"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "prints out that it is switching to that organization" do
|
71
|
+
execute_populate_and_save
|
72
|
+
expect(output).to say("Switching to organization #{organization.name}")
|
73
|
+
end
|
74
|
+
|
75
|
+
context "and a different organization and space in the token file" do
|
76
|
+
let(:input) { {:organization => organizations.last} }
|
77
|
+
|
78
|
+
before do
|
79
|
+
write_token_file({:organization => "organization-id-1", :space => "should-be-removed"})
|
80
|
+
end
|
81
|
+
|
82
|
+
it "removes the space from the token file" do
|
83
|
+
execute_populate_and_save
|
84
|
+
refreshed_tokens = YAML.load_file(File.expand_path(tokens_file_path))
|
85
|
+
expect(refreshed_tokens["https://api.some-domain.com"][:space]).to be_nil
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
context "and the same organization and a space in the token file" do
|
91
|
+
before do
|
92
|
+
write_token_file({:organization => "organization-id-1", :space => "should-not-be-removed"})
|
93
|
+
end
|
94
|
+
|
95
|
+
it "does not remove the space from the token file" do
|
96
|
+
execute_populate_and_save
|
97
|
+
expect(tokens_yaml["https://api.some-domain.com"][:space]).to be == "should-not-be-removed"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context "without an organization in the input" do
|
104
|
+
let(:input) { {} }
|
105
|
+
|
106
|
+
context "with an organization in the config file" do
|
107
|
+
it "should not reprompt for organization" do
|
108
|
+
dont_allow_ask("Organization", anything)
|
109
|
+
execute_populate_and_save
|
110
|
+
end
|
111
|
+
|
112
|
+
it "sets the organization in the token file" do
|
113
|
+
execute_populate_and_save
|
114
|
+
expect(tokens_yaml["https://api.some-domain.com"][:organization]).to be == "organization-id-1"
|
115
|
+
end
|
116
|
+
|
117
|
+
context "but that organization doesn't exist anymore (not valid)" do
|
118
|
+
before do
|
119
|
+
client.stub(:organizations_first_page).and_return({:results => organizations})
|
120
|
+
organization.stub(:users).and_raise(CFoundry::APIError)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "asks the user for an organization" do
|
124
|
+
should_ask("Organization", anything) { organization }
|
125
|
+
execute_populate_and_save
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "without an organization in the config file" do
|
131
|
+
context "when the user has organizations" do
|
132
|
+
before do
|
133
|
+
client.stub(:organizations_first_page).and_return({:results => organizations})
|
134
|
+
write_token_file({})
|
135
|
+
end
|
136
|
+
|
137
|
+
it "prompts for the organization" do
|
138
|
+
should_ask("Organization", anything) { organization }
|
139
|
+
execute_populate_and_save
|
140
|
+
|
141
|
+
expect(output).to say("Switching to organization #{organization.name}")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "sets the organization in the token file" do
|
145
|
+
should_ask("Organization", anything) { organization }
|
146
|
+
|
147
|
+
execute_populate_and_save
|
148
|
+
expect(tokens_yaml["https://api.some-domain.com"][:organization]).to be == "organization-id-1"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "when the user has no organizations" do
|
153
|
+
before do
|
154
|
+
client.stub(:organizations_first_page).and_return({:results => []})
|
155
|
+
write_token_file({})
|
156
|
+
end
|
157
|
+
|
158
|
+
it "warns the user they should create one" do
|
159
|
+
execute_populate_and_save
|
160
|
+
expect(output).to say("There are no organizations. You may want to create one with create-org.")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when the user has too many organizations" do
|
165
|
+
before do
|
166
|
+
client.stub(:organizations_first_page).and_return({:results => organizations, :next_page => true})
|
167
|
+
write_token_file({})
|
168
|
+
end
|
169
|
+
|
170
|
+
it "tells the user to set their target" do
|
171
|
+
expect { execute_populate_and_save }.to raise_error(CF::UserFriendlyError, "Login successful. Too many organizations (>50) to list. Remember to set your target organization using 'target -o [ORGANIZATION]'.")
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|