trucker-cli 0.0.1

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.
Files changed (294) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE +1277 -0
  3. data/Rakefile +13 -0
  4. data/bin/truck +18 -0
  5. data/lib/admin/README.md +30 -0
  6. data/lib/admin/curl.rb +59 -0
  7. data/lib/admin/guid.rb +89 -0
  8. data/lib/admin/plugin.rb +8 -0
  9. data/lib/admin/service_auth_token.rb +93 -0
  10. data/lib/admin/service_broker/add.rb +54 -0
  11. data/lib/admin/service_broker/remove.rb +33 -0
  12. data/lib/admin/service_broker/service_brokers.rb +29 -0
  13. data/lib/admin/service_broker/update.rb +60 -0
  14. data/lib/admin/set_quota.rb +44 -0
  15. data/lib/cf.rb +14 -0
  16. data/lib/cf/cli.rb +495 -0
  17. data/lib/cf/cli/app/app.rb +43 -0
  18. data/lib/cf/cli/app/apps.rb +87 -0
  19. data/lib/cf/cli/app/base.rb +72 -0
  20. data/lib/cf/cli/app/delete.rb +95 -0
  21. data/lib/cf/cli/app/deprecated.rb +11 -0
  22. data/lib/cf/cli/app/env.rb +99 -0
  23. data/lib/cf/cli/app/events.rb +45 -0
  24. data/lib/cf/cli/app/files.rb +137 -0
  25. data/lib/cf/cli/app/health.rb +26 -0
  26. data/lib/cf/cli/app/instances.rb +53 -0
  27. data/lib/cf/cli/app/logs.rb +76 -0
  28. data/lib/cf/cli/app/push.rb +104 -0
  29. data/lib/cf/cli/app/push/create.rb +108 -0
  30. data/lib/cf/cli/app/push/interactions.rb +90 -0
  31. data/lib/cf/cli/app/push/sync.rb +57 -0
  32. data/lib/cf/cli/app/rename.rb +35 -0
  33. data/lib/cf/cli/app/restart.rb +31 -0
  34. data/lib/cf/cli/app/scale.rb +63 -0
  35. data/lib/cf/cli/app/start.rb +175 -0
  36. data/lib/cf/cli/app/stats.rb +66 -0
  37. data/lib/cf/cli/app/stop.rb +27 -0
  38. data/lib/cf/cli/domain/base.rb +9 -0
  39. data/lib/cf/cli/domain/domains.rb +40 -0
  40. data/lib/cf/cli/domain/map.rb +55 -0
  41. data/lib/cf/cli/domain/unmap.rb +56 -0
  42. data/lib/cf/cli/help.rb +15 -0
  43. data/lib/cf/cli/interactive.rb +104 -0
  44. data/lib/cf/cli/login_requirements.rb +13 -0
  45. data/lib/cf/cli/organization/base.rb +12 -0
  46. data/lib/cf/cli/organization/create.rb +36 -0
  47. data/lib/cf/cli/organization/delete.rb +61 -0
  48. data/lib/cf/cli/organization/org.rb +45 -0
  49. data/lib/cf/cli/organization/orgs.rb +30 -0
  50. data/lib/cf/cli/organization/rename.rb +36 -0
  51. data/lib/cf/cli/populators/base.rb +16 -0
  52. data/lib/cf/cli/populators/organization.rb +32 -0
  53. data/lib/cf/cli/populators/populator_methods.rb +64 -0
  54. data/lib/cf/cli/populators/space.rb +33 -0
  55. data/lib/cf/cli/populators/target.rb +14 -0
  56. data/lib/cf/cli/route/base.rb +9 -0
  57. data/lib/cf/cli/route/delete.rb +28 -0
  58. data/lib/cf/cli/route/map.rb +68 -0
  59. data/lib/cf/cli/route/routes.rb +26 -0
  60. data/lib/cf/cli/route/unmap.rb +56 -0
  61. data/lib/cf/cli/service/base.rb +9 -0
  62. data/lib/cf/cli/service/bind.rb +43 -0
  63. data/lib/cf/cli/service/create.rb +158 -0
  64. data/lib/cf/cli/service/delete.rb +82 -0
  65. data/lib/cf/cli/service/rename.rb +35 -0
  66. data/lib/cf/cli/service/service.rb +40 -0
  67. data/lib/cf/cli/service/service_helper.rb +25 -0
  68. data/lib/cf/cli/service/service_instance_helper.rb +100 -0
  69. data/lib/cf/cli/service/services.rb +110 -0
  70. data/lib/cf/cli/service/unbind.rb +36 -0
  71. data/lib/cf/cli/space/base.rb +27 -0
  72. data/lib/cf/cli/space/create.rb +66 -0
  73. data/lib/cf/cli/space/delete.rb +55 -0
  74. data/lib/cf/cli/space/rename.rb +38 -0
  75. data/lib/cf/cli/space/space.rb +66 -0
  76. data/lib/cf/cli/space/spaces.rb +57 -0
  77. data/lib/cf/cli/space/switch.rb +18 -0
  78. data/lib/cf/cli/start/base.rb +35 -0
  79. data/lib/cf/cli/start/colors.rb +13 -0
  80. data/lib/cf/cli/start/login.rb +104 -0
  81. data/lib/cf/cli/start/logout.rb +17 -0
  82. data/lib/cf/cli/start/target.rb +50 -0
  83. data/lib/cf/cli/start/target_prettifier.rb +35 -0
  84. data/lib/cf/cli/start/targets.rb +16 -0
  85. data/lib/cf/cli/user/base.rb +29 -0
  86. data/lib/cf/cli/user/create.rb +51 -0
  87. data/lib/cf/cli/user/passwd.rb +36 -0
  88. data/lib/cf/cli/user/register.rb +42 -0
  89. data/lib/cf/cli/user/users.rb +32 -0
  90. data/lib/cf/constants.rb +10 -0
  91. data/lib/cf/errors.rb +19 -0
  92. data/lib/cf/plugin.rb +56 -0
  93. data/lib/cf/spacing.rb +89 -0
  94. data/lib/cf/spec_helper.rb +1 -0
  95. data/lib/cf/test_support.rb +6 -0
  96. data/lib/cf/version.rb +3 -0
  97. data/lib/console/README.md +16 -0
  98. data/lib/console/console.rb +187 -0
  99. data/lib/console/plugin.rb +32 -0
  100. data/lib/manifests/errors.rb +35 -0
  101. data/lib/manifests/loader.rb +31 -0
  102. data/lib/manifests/loader/builder.rb +39 -0
  103. data/lib/manifests/loader/normalizer.rb +145 -0
  104. data/lib/manifests/loader/resolver.rb +79 -0
  105. data/lib/manifests/manifests.rb +343 -0
  106. data/lib/manifests/plugin.rb +140 -0
  107. data/lib/micro/README.md +25 -0
  108. data/lib/micro/errors.rb +4 -0
  109. data/lib/micro/micro.rb +56 -0
  110. data/lib/micro/plugin.rb +197 -0
  111. data/lib/micro/switcher/base.rb +79 -0
  112. data/lib/micro/switcher/darwin.rb +21 -0
  113. data/lib/micro/switcher/dummy.rb +15 -0
  114. data/lib/micro/switcher/linux.rb +16 -0
  115. data/lib/micro/switcher/windows.rb +31 -0
  116. data/lib/micro/vmrun.rb +175 -0
  117. data/lib/tasks/gem_release.rake +56 -0
  118. data/lib/tasks/windows_build.rake +14 -0
  119. data/lib/tunnel/README.md +29 -0
  120. data/lib/tunnel/config/clients.yml +17 -0
  121. data/lib/tunnel/helper-app/Gemfile +10 -0
  122. data/lib/tunnel/helper-app/Gemfile.lock +48 -0
  123. data/lib/tunnel/helper-app/server.rb +43 -0
  124. data/lib/tunnel/plugin.rb +183 -0
  125. data/lib/tunnel/tunnel.rb +295 -0
  126. data/spec/admin/curl_spec.rb +52 -0
  127. data/spec/admin/guid_spec.rb +85 -0
  128. data/spec/admin/service_broker/add_spec.rb +64 -0
  129. data/spec/admin/service_broker/remove_spec.rb +46 -0
  130. data/spec/admin/service_broker/service_brokers_spec.rb +34 -0
  131. data/spec/admin/service_broker/update_spec.rb +51 -0
  132. data/spec/admin/set_quota_spec.rb +89 -0
  133. data/spec/assets/env/Gemfile +4 -0
  134. data/spec/assets/env/Gemfile.lock +20 -0
  135. data/spec/assets/env/env_test.rb +58 -0
  136. data/spec/assets/hello-sinatra/Gemfile +3 -0
  137. data/spec/assets/hello-sinatra/Gemfile.lock +17 -0
  138. data/spec/assets/hello-sinatra/config.ru +3 -0
  139. data/spec/assets/hello-sinatra/fat-cat-makes-app-larger.png +0 -0
  140. data/spec/assets/hello-sinatra/main.rb +8 -0
  141. data/spec/assets/rails328_ruby187_app/Gemfile +39 -0
  142. data/spec/assets/rails328_ruby187_app/README.rdoc +261 -0
  143. data/spec/assets/rails328_ruby187_app/Rakefile +7 -0
  144. data/spec/assets/rails328_ruby187_app/app/assets/images/rails.png +0 -0
  145. data/spec/assets/rails328_ruby187_app/app/assets/javascripts/application.js +15 -0
  146. data/spec/assets/rails328_ruby187_app/app/assets/stylesheets/application.css +13 -0
  147. data/spec/assets/rails328_ruby187_app/app/controllers/application_controller.rb +3 -0
  148. data/spec/assets/rails328_ruby187_app/app/helpers/application_helper.rb +2 -0
  149. data/spec/assets/rails328_ruby187_app/app/views/layouts/application.html.erb +14 -0
  150. data/spec/assets/rails328_ruby187_app/config.ru +4 -0
  151. data/spec/assets/rails328_ruby187_app/config/application.rb +62 -0
  152. data/spec/assets/rails328_ruby187_app/config/boot.rb +6 -0
  153. data/spec/assets/rails328_ruby187_app/config/database.yml +25 -0
  154. data/spec/assets/rails328_ruby187_app/config/environment.rb +5 -0
  155. data/spec/assets/rails328_ruby187_app/config/environments/development.rb +37 -0
  156. data/spec/assets/rails328_ruby187_app/config/environments/production.rb +67 -0
  157. data/spec/assets/rails328_ruby187_app/config/environments/test.rb +37 -0
  158. data/spec/assets/rails328_ruby187_app/config/initializers/backtrace_silencers.rb +7 -0
  159. data/spec/assets/rails328_ruby187_app/config/initializers/inflections.rb +15 -0
  160. data/spec/assets/rails328_ruby187_app/config/initializers/mime_types.rb +5 -0
  161. data/spec/assets/rails328_ruby187_app/config/initializers/secret_token.rb +7 -0
  162. data/spec/assets/rails328_ruby187_app/config/initializers/session_store.rb +8 -0
  163. data/spec/assets/rails328_ruby187_app/config/initializers/wrap_parameters.rb +14 -0
  164. data/spec/assets/rails328_ruby187_app/config/locales/en.yml +5 -0
  165. data/spec/assets/rails328_ruby187_app/config/routes.rb +58 -0
  166. data/spec/assets/rails328_ruby187_app/db/seeds.rb +7 -0
  167. data/spec/assets/rails328_ruby187_app/doc/README_FOR_APP +2 -0
  168. data/spec/assets/rails328_ruby187_app/manifest.yml +7 -0
  169. data/spec/assets/rails328_ruby187_app/public/404.html +26 -0
  170. data/spec/assets/rails328_ruby187_app/public/422.html +26 -0
  171. data/spec/assets/rails328_ruby187_app/public/500.html +25 -0
  172. data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css +0 -0
  173. data/spec/assets/rails328_ruby187_app/public/assets/application-7270767b2a9e9fff880aa5de378ca791.css.gz +0 -0
  174. data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js +17 -0
  175. data/spec/assets/rails328_ruby187_app/public/assets/application-ccab98dc1abdf097c0af693e20aed861.js.gz +0 -0
  176. data/spec/assets/rails328_ruby187_app/public/assets/application.css +0 -0
  177. data/spec/assets/rails328_ruby187_app/public/assets/application.css.gz +0 -0
  178. data/spec/assets/rails328_ruby187_app/public/assets/application.js +17 -0
  179. data/spec/assets/rails328_ruby187_app/public/assets/application.js.gz +0 -0
  180. data/spec/assets/rails328_ruby187_app/public/assets/manifest.yml +4 -0
  181. data/spec/assets/rails328_ruby187_app/public/assets/rails-be8732dac73d845ac5b142c8fb5f9fb0.png +0 -0
  182. data/spec/assets/rails328_ruby187_app/public/assets/rails.png +0 -0
  183. data/spec/assets/rails328_ruby187_app/public/favicon.ico +0 -0
  184. data/spec/assets/rails328_ruby187_app/public/index.html +241 -0
  185. data/spec/assets/rails328_ruby187_app/public/robots.txt +5 -0
  186. data/spec/assets/rails328_ruby187_app/script/rails +6 -0
  187. data/spec/assets/rails328_ruby187_app/test/performance/browsing_test.rb +12 -0
  188. data/spec/assets/rails328_ruby187_app/test/test_helper.rb +13 -0
  189. data/spec/cf/cli/app/base_spec.rb +17 -0
  190. data/spec/cf/cli/app/delete_spec.rb +197 -0
  191. data/spec/cf/cli/app/env_spec.rb +261 -0
  192. data/spec/cf/cli/app/events_spec.rb +72 -0
  193. data/spec/cf/cli/app/help_spec.rb +39 -0
  194. data/spec/cf/cli/app/instances_spec.rb +69 -0
  195. data/spec/cf/cli/app/push/create_spec.rb +444 -0
  196. data/spec/cf/cli/app/push/interactions_spec.rb +32 -0
  197. data/spec/cf/cli/app/push_spec.rb +332 -0
  198. data/spec/cf/cli/app/rename_spec.rb +108 -0
  199. data/spec/cf/cli/app/restart_spec.rb +47 -0
  200. data/spec/cf/cli/app/scale_spec.rb +63 -0
  201. data/spec/cf/cli/app/start_spec.rb +255 -0
  202. data/spec/cf/cli/app/stats_spec.rb +66 -0
  203. data/spec/cf/cli/domain/help_spec.rb +39 -0
  204. data/spec/cf/cli/domain/map_spec.rb +140 -0
  205. data/spec/cf/cli/domain/unmap_spec.rb +77 -0
  206. data/spec/cf/cli/help_spec.rb +21 -0
  207. data/spec/cf/cli/organization/create_spec.rb +121 -0
  208. data/spec/cf/cli/organization/delete_spec.rb +105 -0
  209. data/spec/cf/cli/organization/help_spec.rb +39 -0
  210. data/spec/cf/cli/organization/orgs_spec.rb +116 -0
  211. data/spec/cf/cli/organization/rename_spec.rb +116 -0
  212. data/spec/cf/cli/populators/organization_spec.rb +179 -0
  213. data/spec/cf/cli/populators/space_spec.rb +156 -0
  214. data/spec/cf/cli/populators/target_spec.rb +39 -0
  215. data/spec/cf/cli/route/delete_spec.rb +92 -0
  216. data/spec/cf/cli/route/help_spec.rb +32 -0
  217. data/spec/cf/cli/route/map_spec.rb +148 -0
  218. data/spec/cf/cli/route/unmap_spec.rb +114 -0
  219. data/spec/cf/cli/service/bind_spec.rb +25 -0
  220. data/spec/cf/cli/service/create_spec.rb +147 -0
  221. data/spec/cf/cli/service/delete_spec.rb +22 -0
  222. data/spec/cf/cli/service/help_spec.rb +39 -0
  223. data/spec/cf/cli/service/rename_spec.rb +103 -0
  224. data/spec/cf/cli/service/service_helper_spec.rb +66 -0
  225. data/spec/cf/cli/service/service_instance_helper_spec.rb +155 -0
  226. data/spec/cf/cli/service/service_spec.rb +23 -0
  227. data/spec/cf/cli/service/services_spec.rb +156 -0
  228. data/spec/cf/cli/service/unbind_spec.rb +25 -0
  229. data/spec/cf/cli/space/base_spec.rb +49 -0
  230. data/spec/cf/cli/space/create_spec.rb +144 -0
  231. data/spec/cf/cli/space/delete_spec.rb +109 -0
  232. data/spec/cf/cli/space/help_spec.rb +39 -0
  233. data/spec/cf/cli/space/rename_spec.rb +110 -0
  234. data/spec/cf/cli/space/space_spec.rb +80 -0
  235. data/spec/cf/cli/space/spaces_spec.rb +107 -0
  236. data/spec/cf/cli/space/switch_space_spec.rb +57 -0
  237. data/spec/cf/cli/start/help_spec.rb +39 -0
  238. data/spec/cf/cli/start/login_spec.rb +142 -0
  239. data/spec/cf/cli/start/logout_spec.rb +49 -0
  240. data/spec/cf/cli/start/target_prettifier_spec.rb +78 -0
  241. data/spec/cf/cli/start/target_spec.rb +123 -0
  242. data/spec/cf/cli/user/create_spec.rb +98 -0
  243. data/spec/cf/cli/user/help_spec.rb +32 -0
  244. data/spec/cf/cli/user/passwd_spec.rb +94 -0
  245. data/spec/cf/cli/user/register_spec.rb +145 -0
  246. data/spec/cf/cli_spec.rb +474 -0
  247. data/spec/console/console_spec.rb +189 -0
  248. data/spec/factories/cfoundry/v2/apps_factory.rb +12 -0
  249. data/spec/factories/cfoundry/v2/clients_factory.rb +7 -0
  250. data/spec/factories/cfoundry/v2/domains_factory.rb +8 -0
  251. data/spec/factories/cfoundry/v2/managed_service_instances_factory.rb +13 -0
  252. data/spec/factories/cfoundry/v2/organizations_factory.rb +14 -0
  253. data/spec/factories/cfoundry/v2/quota_definitions.rb +13 -0
  254. data/spec/factories/cfoundry/v2/routes_factory.rb +8 -0
  255. data/spec/factories/cfoundry/v2/service_bindings_factory.rb +11 -0
  256. data/spec/factories/cfoundry/v2/service_brokers_factory.rb +11 -0
  257. data/spec/factories/cfoundry/v2/service_plans_factory.rb +17 -0
  258. data/spec/factories/cfoundry/v2/services_factory.rb +14 -0
  259. data/spec/factories/cfoundry/v2/spaces_factory.rb +13 -0
  260. data/spec/factories/cfoundry/v2/stacks_factory.rb +11 -0
  261. data/spec/factories/cfoundry/v2/user_provided_service_instances_factory.rb +12 -0
  262. data/spec/factories/cfoundry/v2/users_factory.rb +7 -0
  263. data/spec/features/backspace_spec.rb +46 -0
  264. data/spec/features/create_user_spec.rb +74 -0
  265. data/spec/features/delete_orphaned_service_spec.rb +64 -0
  266. data/spec/features/login_spec.rb +65 -0
  267. data/spec/features/manifests_spec.rb +86 -0
  268. data/spec/features/org_spec.rb +50 -0
  269. data/spec/features/push_flow_spec.rb +169 -0
  270. data/spec/features/service_brokers_spec.rb +173 -0
  271. data/spec/features/services_spec.rb +122 -0
  272. data/spec/features/space_spec.rb +107 -0
  273. data/spec/features/switching_targets_spec.rb +70 -0
  274. data/spec/manifests/errors_spec.rb +43 -0
  275. data/spec/manifests/loader/builder_spec.rb +80 -0
  276. data/spec/manifests/loader/normalizer_spec.rb +158 -0
  277. data/spec/manifests/manifests_spec.rb +335 -0
  278. data/spec/manifests/plugin_spec.rb +410 -0
  279. data/spec/micro/plugin_spec.rb +64 -0
  280. data/spec/spec_helper.rb +69 -0
  281. data/spec/support/cli_helper.rb +87 -0
  282. data/spec/support/config_helper.rb +15 -0
  283. data/spec/support/factory_girl.rb +6 -0
  284. data/spec/support/fake_home_dir.rb +55 -0
  285. data/spec/support/features_helper.rb +99 -0
  286. data/spec/support/interact_helper.rb +27 -0
  287. data/spec/support/matchers.rb +16 -0
  288. data/spec/support/mock_commands/mock_restart.rb +16 -0
  289. data/spec/support/mock_commands/mock_start.rb +17 -0
  290. data/spec/support/shared_examples/errors.rb +40 -0
  291. data/spec/support/shared_examples/input.rb +14 -0
  292. data/spec/tunnel/plugin_spec.rb +31 -0
  293. data/spec/tunnel/tunnel_spec.rb +54 -0
  294. metadata +814 -0
@@ -0,0 +1,107 @@
1
+ require "spec_helper"
2
+
3
+ module CF
4
+ module Space
5
+ describe Spaces do
6
+ let(:full) { false }
7
+ let(:app) { build(:app) }
8
+ let!(:space_1) { build(:space, :name => "bb_second", :apps => [app], :service_instances => [build(:managed_service_instance)]) }
9
+ let!(:space_2) { build(:space, :name => "aa_first", :apps => [app], :service_instances => [build(:managed_service_instance)], :domains => [build(:domain)]) }
10
+ let!(:space_3) { build(:space, :name => "cc_last", :apps => [app], :service_instances => [build(:managed_service_instance)], :domains => [build(:domain)]) }
11
+ let(:spaces) { [space_1, space_2, space_3] }
12
+ let(:organization) { build(:organization, :spaces => spaces, :name => "foo") }
13
+ let(:client) do
14
+ build(:client).tap do |client|
15
+ client.stub(:spaces => spaces, :current_organization => organization)
16
+ end
17
+ end
18
+
19
+ before do
20
+ stub_client_and_precondition
21
+ CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
22
+ organization.stub(:spaces).and_return(spaces)
23
+ end
24
+
25
+ describe "metadata" do
26
+ let(:command) { Mothership.commands[:spaces] }
27
+
28
+ describe "command" do
29
+ subject { command }
30
+ its(:description) { should eq "List spaces in an organization" }
31
+ it { expect(Mothership::Help.group(:spaces)).to include(subject) }
32
+ end
33
+
34
+ include_examples "inputs must have descriptions"
35
+
36
+ describe "arguments" do
37
+ subject { command.arguments }
38
+ it "has the correct argument order" do
39
+ should eq([{:type => :optional, :value => nil, :name => :organization}])
40
+ end
41
+ end
42
+ end
43
+
44
+ subject { cf %W[spaces --#{bool_flag(:full)} --no-quiet] }
45
+
46
+ it "outputs that it is getting spaces" do
47
+ subject
48
+
49
+ stdout.rewind
50
+ expect(stdout.readline).to match /Getting spaces.*OK/
51
+ expect(stdout.readline).to eq "\n"
52
+ end
53
+
54
+ context "when there are no spaces" do
55
+ let(:spaces) { [] }
56
+
57
+ context "and the full flag is given" do
58
+ let(:full) { true }
59
+
60
+ it "displays yaml-style output with all space details" do
61
+ CF::Space::Spaces.any_instance.should_not_receive(:invoke)
62
+ subject
63
+ end
64
+ end
65
+
66
+ context "and the full flag is not given (default is false)" do
67
+ it "should show only the progress" do
68
+ subject
69
+
70
+ stdout.rewind
71
+ expect(stdout.readline).to match /Getting spaces.*OK/
72
+ expect(stdout).to be_eof
73
+ end
74
+ end
75
+ end
76
+
77
+ context "when there are spaces" do
78
+ context "and the full flag is given" do
79
+ let(:full) { true }
80
+
81
+ it "displays yaml-style output with all space details" do
82
+ CF::Space::Spaces.any_instance.should_receive(:invoke).with(:space, :space => space_2, :full => true)
83
+ CF::Space::Spaces.any_instance.should_receive(:invoke).with(:space, :space => space_1, :full => true)
84
+ CF::Space::Spaces.any_instance.should_receive(:invoke).with(:space, :space => space_3, :full => true)
85
+ subject
86
+ end
87
+ end
88
+
89
+ context "and the full flag is not given (default is false)" do
90
+ it "displays tabular output with names, spaces and domains" do
91
+ subject
92
+
93
+ stdout.rewind
94
+ stdout.readline
95
+ stdout.readline
96
+
97
+ expect(stdout.readline).to match /name\s+apps\s+services/
98
+ spaces.sort_by(&:name).each do |space|
99
+ expect(stdout.readline).to match /#{space.name}\s+#{name_list(space.apps)}\s+#{name_list(space.service_instances)}/
100
+ end
101
+ expect(stdout).to be_eof
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,57 @@
1
+ require "spec_helper"
2
+
3
+ module CF
4
+ module Space
5
+ describe Switch do
6
+ let(:space_to_switch_to) { spaces.last }
7
+ let(:spaces) { Array.new(3) { build(:space) } }
8
+ let(:organization) { build(:organization, :spaces => spaces) }
9
+ let(:client) { build(:client) }
10
+
11
+ before do
12
+ stub_client_and_precondition
13
+ CF::Populators::Organization.any_instance.stub(:populate_and_save!).and_return(organization)
14
+ end
15
+
16
+ describe "metadata" do
17
+ let(:command) { Mothership.commands[:switch_space] }
18
+
19
+ describe "command" do
20
+ subject { command }
21
+ its(:description) { should eq "Switch to a space" }
22
+ it { expect(Mothership::Help.group(:spaces)).to include(subject) }
23
+ end
24
+
25
+ include_examples "inputs must have descriptions"
26
+
27
+ describe "arguments" do
28
+ subject { command.arguments }
29
+ it "has the correct argument order" do
30
+ should eq([{:type => :normal, :value => nil, :name => :name}])
31
+ end
32
+ end
33
+ end
34
+
35
+ subject { cf %W[--no-quiet switch-space #{space_to_switch_to.name} --no-color] }
36
+
37
+ context "when the space exists" do
38
+ before do
39
+ Mothership.any_instance.should_receive(:invoke).with(:target, {:space => space_to_switch_to})
40
+ client.stub(:spaces_by_name).with(space_to_switch_to.name).and_return([space_to_switch_to])
41
+ end
42
+
43
+ it "switches to that space" do
44
+ subject
45
+ end
46
+ end
47
+
48
+ context "when the space does not exist" do
49
+ before { client.stub(:spaces_by_name).with(space_to_switch_to.name).and_return([]) }
50
+
51
+ it_behaves_like "an error that gets passed through",
52
+ :with_exception => CF::UserError,
53
+ :with_message => /The space .* does not exist, please create the space first/
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ module CF
4
+ module Space
5
+ describe "Help" do
6
+ let(:global) { {} }
7
+ let(:given) { {} }
8
+
9
+ subject do
10
+ capture_output { Mothership.new.invoke(:help, :command => "start") }
11
+ end
12
+
13
+ it "describes the command" do
14
+ subject
15
+ stdout.rewind
16
+ expect(stdout.readlines.first).to match /Start an application/
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,142 @@
1
+ require "spec_helper"
2
+
3
+ describe CF::Start::Login do
4
+ let(:client) { build(:client) }
5
+
6
+ describe "metadata" do
7
+ before do
8
+ stub_client_and_precondition
9
+ end
10
+
11
+ let(:command) { Mothership.commands[:login] }
12
+
13
+ describe "command" do
14
+ subject { command }
15
+ its(:description) { should eq "Authenticate with the target" }
16
+ specify { expect(Mothership::Help.group(:start)).to include(subject) }
17
+ end
18
+
19
+ include_examples "inputs must have descriptions"
20
+
21
+ describe "flags" do
22
+ subject { command.flags }
23
+
24
+ its(["-o"]) { should eq :organization }
25
+ its(["--org"]) { should eq :organization }
26
+ its(["--email"]) { should eq :username }
27
+ its(["-s"]) { should eq :space }
28
+ end
29
+
30
+ describe "arguments" do
31
+ subject { command.arguments }
32
+
33
+ it "have the correct commands" do
34
+ expect(subject).to eq [{
35
+ :type => :optional,
36
+ :value => :email,
37
+ :name => :username
38
+ }]
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "running the command" do
44
+ before { stub_client }
45
+
46
+ stub_home_dir_with { "#{SPEC_ROOT}/fixtures/fake_home_dirs/new" }
47
+
48
+ before do
49
+ client.stub(:login_prompts).and_return(
50
+ :username => ["text", "username-prompt"],
51
+ :password => ["password", "password-prompt"],
52
+ :passcode => ["password", "passcode-prompt"]
53
+ )
54
+ end
55
+
56
+ def self.it_logs_in_user_with_credentials(expected_credentials)
57
+ context "when there is a target" do
58
+ before { stub_precondition }
59
+
60
+ context "when user is successfully authenticated" do
61
+ before { client.stub(:login).with(expected_credentials) { auth_token } }
62
+ before { CF::Populators::Target.any_instance.stub(:populate_and_save!) }
63
+ let(:auth_token) { CFoundry::AuthToken.new("bearer some-new-access-token", "some-new-refresh-token") }
64
+
65
+ it "logs in with the provided credentials and saves the token data to the YAML file" do
66
+ subject
67
+ expect(tokens_yaml["https://api.some-domain.com"][:token]).to eq("bearer some-new-access-token")
68
+ expect(tokens_yaml["https://api.some-domain.com"][:refresh_token]).to eq("some-new-refresh-token")
69
+ end
70
+
71
+ it "calls use a PopulateTarget to ensure that an organization and space is set" do
72
+ CF::Populators::Target.should_receive(:new) { double(:target, :populate_and_save! => true) }
73
+ subject
74
+ end
75
+ end
76
+
77
+ context "when the user logs in with invalid credentials" do
78
+ before do
79
+ client
80
+ .should_receive(:login)
81
+ .with(expected_credentials)
82
+ .exactly(3).times
83
+ .and_raise(CFoundry::Denied)
84
+ end
85
+
86
+ it "informs the user gracefully about authentication failure" do
87
+ subject
88
+ expect(output).to say("Authenticating... FAILED")
89
+ end
90
+
91
+ it "does not save token data" do
92
+ expect {
93
+ subject
94
+ }.to_not change { tokens_yaml["https://api.some-domain.com"] }
95
+ end
96
+
97
+ it "does not call PopulateTarget" do
98
+ CF::Populators::Target.should_not_receive(:new)
99
+ subject
100
+ end
101
+ end
102
+
103
+ def tokens_yaml
104
+ YAML.load_file(File.expand_path("~/.truck/tokens.yml"))
105
+ end
106
+ end
107
+
108
+ context "when there is no target" do
109
+ before { client.stub(:target) { nil } }
110
+
111
+ it "tells the user to select a target" do
112
+ subject
113
+ expect(error_output).to say("Please select a target with 'truck target'.")
114
+ end
115
+ end
116
+ end
117
+
118
+ context "when user is trying to log in with username/password" do
119
+ subject { cf ["login"] }
120
+
121
+ before do
122
+ stub_ask("username-prompt", {}) { "my-username" }
123
+ stub_ask("password-prompt", {:echo => "*", :forget => true}) { "my-password" }
124
+ end
125
+
126
+ it_logs_in_user_with_credentials(
127
+ :username => "my-username", :password => "my-password")
128
+ end
129
+
130
+ context "when user is trying to log in via sso" do
131
+ subject { cf ["login", "--sso"] }
132
+
133
+ before do
134
+ stub_ask("username-prompt", {}) { "my-username" }
135
+ stub_ask("passcode-prompt", {:echo => "*", :forget => true}) { "my-passcode" }
136
+ end
137
+
138
+ it_logs_in_user_with_credentials(
139
+ :username => "my-username", :passcode => "my-passcode")
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ module CF
4
+ module Start
5
+ describe Logout do
6
+ let(:client) { build(:client) }
7
+
8
+ before do
9
+ described_class.any_instance.stub(:client) { client }
10
+ end
11
+
12
+ describe "metadata" do
13
+ let(:command) { Mothership.commands[:logout] }
14
+
15
+ describe "command" do
16
+ subject { command }
17
+ its(:description) { should eq "Log out from the target" }
18
+ it { expect(Mothership::Help.group(:start)).to include(subject) }
19
+ end
20
+ end
21
+
22
+ describe "running the command" do
23
+ subject { cf ["logout"] }
24
+
25
+ context "when there is a target" do
26
+ let(:info) { {client.target => "x", "abc" => "x"} }
27
+
28
+ before do
29
+ CF::CLI.any_instance.stub(:targets_info) { info }
30
+ CF::CLI.any_instance.stub(:client_target) { client.target }
31
+ end
32
+
33
+ it "removes the target info from the tokens file" do
34
+ expect {
35
+ subject
36
+ }.to change { info }.to("abc" => "x")
37
+ end
38
+ end
39
+
40
+ context "when there is no target" do
41
+ let(:client) { nil }
42
+ it_behaves_like "an error that gets passed through",
43
+ :with_exception => CF::UserError,
44
+ :with_message => "Please select a target with 'truck target'."
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,78 @@
1
+ require "spec_helper"
2
+
3
+ module CF::Start
4
+ describe TargetPrettifier do
5
+ let(:user) do
6
+ build(:user).tap { |u| u.stub(:email => 'user@example.com') }
7
+ end
8
+ let(:space) { build(:space) }
9
+ let(:organization) { build(:organization) }
10
+ let(:target) { "http://example.com" }
11
+ let(:client) do
12
+ double(:client,
13
+ target: target,
14
+ current_user: user,
15
+ current_organization: organization,
16
+ current_space: space,
17
+ version: 2
18
+ )
19
+ end
20
+ let(:outputter) { double(:outputter, line: nil, fail: nil) }
21
+
22
+ before do
23
+ outputter.stub(:c) { |to_colorize| to_colorize }
24
+ end
25
+
26
+ describe "displaying the target (no args)" do
27
+ it "prints things nicely" do
28
+ TargetPrettifier.prettify(client, outputter)
29
+ desired_result = <<-STR
30
+ Target Information (where will apps be pushed):
31
+ CF instance: #{client.target} (API version: 2)
32
+ user: #{user.email}
33
+ target app space: #{space.name} (org: #{organization.name})
34
+ STR
35
+ desired_result.each_line do |line|
36
+ outputter.should have_received(:line).with(line.chomp)
37
+ end
38
+ end
39
+
40
+ context "when there is no target" do
41
+ let(:target) { nil }
42
+ it "displays 'N/A' as the value of the target" do
43
+ desired_result = <<-STR
44
+ Target Information (where will apps be pushed):
45
+ CF instance: N/A (API version: 2)
46
+ user: #{user.email}
47
+ target app space: #{space.name} (org: #{organization.name})
48
+ STR
49
+
50
+ desired_result.each_line do |line|
51
+ outputter.should_receive(:line).with(line.chomp)
52
+ end
53
+
54
+ TargetPrettifier.prettify(client, outputter)
55
+ end
56
+ end
57
+
58
+ context "when nothing is specified" do
59
+ let(:user) { nil }
60
+ let(:space) { nil }
61
+ let(:organization) { nil }
62
+
63
+ it "prints things nicely" do
64
+ TargetPrettifier.prettify(client, outputter)
65
+ desired_result = <<-STR
66
+ Target Information (where will apps be pushed):
67
+ CF instance: http://example.com (API version: 2)
68
+ user: N/A
69
+ target app space: N/A (org: N/A)
70
+ STR
71
+ desired_result.each_line do |line|
72
+ outputter.should have_received(:line).with(line.chomp)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end