cf_script 0.0.1.beta.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 (205) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/CHANGELOG.md +0 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +22 -0
  6. data/README.md +84 -0
  7. data/Rakefile +33 -0
  8. data/cf_script.gemspec +34 -0
  9. data/lib/cf_script/callbacks.rb +43 -0
  10. data/lib/cf_script/command/base.rb +57 -0
  11. data/lib/cf_script/command/cf/apps/app.rb +19 -0
  12. data/lib/cf_script/command/cf/apps/apps.rb +44 -0
  13. data/lib/cf_script/command/cf/apps/env.rb +20 -0
  14. data/lib/cf_script/command/cf/apps/push.rb +47 -0
  15. data/lib/cf_script/command/cf/apps/restage.rb +19 -0
  16. data/lib/cf_script/command/cf/apps/restart.rb +19 -0
  17. data/lib/cf_script/command/cf/apps/set_env.rb +18 -0
  18. data/lib/cf_script/command/cf/apps/start.rb +19 -0
  19. data/lib/cf_script/command/cf/apps/stop.rb +19 -0
  20. data/lib/cf_script/command/cf/apps/unset_env.rb +18 -0
  21. data/lib/cf_script/command/cf/apps.rb +55 -0
  22. data/lib/cf_script/command/cf/general/api.rb +36 -0
  23. data/lib/cf_script/command/cf/general/auth.rb +28 -0
  24. data/lib/cf_script/command/cf/general/login.rb +42 -0
  25. data/lib/cf_script/command/cf/general/logout.rb +15 -0
  26. data/lib/cf_script/command/cf/general/target.rb +64 -0
  27. data/lib/cf_script/command/cf/general.rb +15 -0
  28. data/lib/cf_script/command/cf/routes/check_route.rb +17 -0
  29. data/lib/cf_script/command/cf/routes/create_route.rb +19 -0
  30. data/lib/cf_script/command/cf/routes/delete_route.rb +19 -0
  31. data/lib/cf_script/command/cf/routes/map_route.rb +30 -0
  32. data/lib/cf_script/command/cf/routes/routes.rb +40 -0
  33. data/lib/cf_script/command/cf/routes/unmap_route.rb +30 -0
  34. data/lib/cf_script/command/cf/routes.rb +17 -0
  35. data/lib/cf_script/command/cf/spaces/space.rb +36 -0
  36. data/lib/cf_script/command/cf/spaces/spaces.rb +23 -0
  37. data/lib/cf_script/command/cf/spaces.rb +9 -0
  38. data/lib/cf_script/command/error.rb +5 -0
  39. data/lib/cf_script/command/line.rb +105 -0
  40. data/lib/cf_script/command/registry.rb +50 -0
  41. data/lib/cf_script/command/runner.rb +97 -0
  42. data/lib/cf_script/command.rb +44 -0
  43. data/lib/cf_script/config.rb +60 -0
  44. data/lib/cf_script/executor/non_blocking.rb +107 -0
  45. data/lib/cf_script/executor/recorder.rb +16 -0
  46. data/lib/cf_script/executor/simple.rb +17 -0
  47. data/lib/cf_script/executor.rb +5 -0
  48. data/lib/cf_script/manifest.rb +38 -0
  49. data/lib/cf_script/object/api_endpoint.rb +10 -0
  50. data/lib/cf_script/object/app_info.rb +69 -0
  51. data/lib/cf_script/object/app_list.rb +24 -0
  52. data/lib/cf_script/object/app_spec.rb +55 -0
  53. data/lib/cf_script/object/attribute.rb +18 -0
  54. data/lib/cf_script/object/attribute_list.rb +40 -0
  55. data/lib/cf_script/object/instance_status.rb +29 -0
  56. data/lib/cf_script/object/route_info.rb +14 -0
  57. data/lib/cf_script/object/space.rb +17 -0
  58. data/lib/cf_script/object/target.rb +23 -0
  59. data/lib/cf_script/object.rb +24 -0
  60. data/lib/cf_script/output/buffer.rb +74 -0
  61. data/lib/cf_script/output/parser/attributes.rb +44 -0
  62. data/lib/cf_script/output/parser/section.rb +15 -0
  63. data/lib/cf_script/output/parser/table.rb +46 -0
  64. data/lib/cf_script/output/parser.rb +15 -0
  65. data/lib/cf_script/output/tests.rb +51 -0
  66. data/lib/cf_script/output/utils.rb +13 -0
  67. data/lib/cf_script/output.rb +62 -0
  68. data/lib/cf_script/scope/app/env.rb +15 -0
  69. data/lib/cf_script/scope/app/routes.rb +21 -0
  70. data/lib/cf_script/scope/app/state.rb +33 -0
  71. data/lib/cf_script/scope/app/utils.rb +32 -0
  72. data/lib/cf_script/scope/app.rb +94 -0
  73. data/lib/cf_script/scope/proxy.rb +36 -0
  74. data/lib/cf_script/scope/script.rb +59 -0
  75. data/lib/cf_script/scope/space.rb +9 -0
  76. data/lib/cf_script/scope/target.rb +90 -0
  77. data/lib/cf_script/scope.rb +68 -0
  78. data/lib/cf_script/ui.rb +261 -0
  79. data/lib/cf_script/utils.rb +19 -0
  80. data/lib/cf_script/version.rb +3 -0
  81. data/lib/cf_script.rb +105 -0
  82. data/test/fixtures/commands/apps/app/good.yml +18 -0
  83. data/test/fixtures/commands/apps/app/not_found.yml +8 -0
  84. data/test/fixtures/commands/apps/app/running.yml +19 -0
  85. data/test/fixtures/commands/apps/apps/good.yml +14 -0
  86. data/test/fixtures/commands/apps/apps/no_apps.yml +10 -0
  87. data/test/fixtures/commands/apps/env/empty.yml +37 -0
  88. data/test/fixtures/commands/apps/env/good.yml +41 -0
  89. data/test/fixtures/commands/apps/push/good.yml +60 -0
  90. data/test/fixtures/commands/apps/restage/good.yml +48 -0
  91. data/test/fixtures/commands/apps/restage/not_found.yml +8 -0
  92. data/test/fixtures/commands/apps/restart/good.yml +35 -0
  93. data/test/fixtures/commands/apps/restart/not_found.yml +8 -0
  94. data/test/fixtures/commands/apps/set_env/empty.yml +5 -0
  95. data/test/fixtures/commands/apps/set_env/good.yml +9 -0
  96. data/test/fixtures/commands/apps/set_env/not_found.yml +8 -0
  97. data/test/fixtures/commands/apps/start/good.yml +32 -0
  98. data/test/fixtures/commands/apps/start/not_found.yml +8 -0
  99. data/test/fixtures/commands/apps/start/with_container.yml +98 -0
  100. data/test/fixtures/commands/apps/stop/good.yml +8 -0
  101. data/test/fixtures/commands/apps/stop/not_found.yml +8 -0
  102. data/test/fixtures/commands/apps/unset_env/empty.yml +5 -0
  103. data/test/fixtures/commands/apps/unset_env/good.yml +9 -0
  104. data/test/fixtures/commands/apps/unset_env/not_found.yml +8 -0
  105. data/test/fixtures/commands/common/fail.yml +5 -0
  106. data/test/fixtures/commands/common/no_endpoint.yml +11 -0
  107. data/test/fixtures/commands/common/no_login.yml +8 -0
  108. data/test/fixtures/commands/general/api/bad_argument.yml +9 -0
  109. data/test/fixtures/commands/general/api/bad_endpoint.yml +9 -0
  110. data/test/fixtures/commands/general/api/good.yml +7 -0
  111. data/test/fixtures/commands/general/api/not_set.yml +7 -0
  112. data/test/fixtures/commands/general/api/set.yml +7 -0
  113. data/test/fixtures/commands/general/auth/empty.yml +5 -0
  114. data/test/fixtures/commands/general/auth/good.yml +10 -0
  115. data/test/fixtures/commands/general/auth/rejected.yml +10 -0
  116. data/test/fixtures/commands/general/login/good.yml +8 -0
  117. data/test/fixtures/commands/general/login/rejected.yml +23 -0
  118. data/test/fixtures/commands/general/logout/good.yml +8 -0
  119. data/test/fixtures/commands/general/target/empty.yml +5 -0
  120. data/test/fixtures/commands/general/target/good.yml +11 -0
  121. data/test/fixtures/commands/general/target/no_space.yml +10 -0
  122. data/test/fixtures/commands/general/target/not_found.yml +9 -0
  123. data/test/fixtures/commands/general/target/production.yml +11 -0
  124. data/test/fixtures/commands/general/target/staging.yml +11 -0
  125. data/test/fixtures/commands/general/target/staging_org.yml +11 -0
  126. data/test/fixtures/commands/general/target/test.yml +11 -0
  127. data/test/fixtures/commands/routes/check_route/good.yml +9 -0
  128. data/test/fixtures/commands/routes/check_route/no_domain.yml +9 -0
  129. data/test/fixtures/commands/routes/check_route/no_route.yml +9 -0
  130. data/test/fixtures/commands/routes/create_route/exists.yml +9 -0
  131. data/test/fixtures/commands/routes/create_route/good.yml +8 -0
  132. data/test/fixtures/commands/routes/delete_route/good.yml +8 -0
  133. data/test/fixtures/commands/routes/delete_route/not_exist.yml +8 -0
  134. data/test/fixtures/commands/routes/map_route/good.yml +10 -0
  135. data/test/fixtures/commands/routes/map_route/host_taken.yml +10 -0
  136. data/test/fixtures/commands/routes/map_route/invalid.yml +9 -0
  137. data/test/fixtures/commands/routes/map_route/no_app.yml +8 -0
  138. data/test/fixtures/commands/routes/map_route/no_domain.yml +9 -0
  139. data/test/fixtures/commands/routes/routes/good.yml +14 -0
  140. data/test/fixtures/commands/routes/unmap_route/good.yml +8 -0
  141. data/test/fixtures/commands/routes/unmap_route/no_app.yml +8 -0
  142. data/test/fixtures/commands/routes/unmap_route/no_domain.yml +9 -0
  143. data/test/fixtures/commands/spaces/space/empty.yml +5 -0
  144. data/test/fixtures/commands/spaces/space/good.yml +16 -0
  145. data/test/fixtures/commands/spaces/space/staging.yml +16 -0
  146. data/test/fixtures/commands/spaces/spaces/empty.yml +5 -0
  147. data/test/fixtures/commands/spaces/spaces/good.yml +12 -0
  148. data/test/lib/cf_script/command/base_test.rb +21 -0
  149. data/test/lib/cf_script/command/cf/apps/app_test.rb +56 -0
  150. data/test/lib/cf_script/command/cf/apps/apps_test.rb +81 -0
  151. data/test/lib/cf_script/command/cf/apps/env_test.rb +55 -0
  152. data/test/lib/cf_script/command/cf/apps/push_test.rb +46 -0
  153. data/test/lib/cf_script/command/cf/apps/restage_test.rb +47 -0
  154. data/test/lib/cf_script/command/cf/apps/restart_test.rb +47 -0
  155. data/test/lib/cf_script/command/cf/apps/set_env_test.rb +38 -0
  156. data/test/lib/cf_script/command/cf/apps/start_test.rb +55 -0
  157. data/test/lib/cf_script/command/cf/apps/stop_test.rb +35 -0
  158. data/test/lib/cf_script/command/cf/apps/unset_env_test.rb +38 -0
  159. data/test/lib/cf_script/command/cf/general/api_test.rb +55 -0
  160. data/test/lib/cf_script/command/cf/general/auth_test.rb +76 -0
  161. data/test/lib/cf_script/command/cf/general/login_test.rb +80 -0
  162. data/test/lib/cf_script/command/cf/general/logout_test.rb +34 -0
  163. data/test/lib/cf_script/command/cf/general/target_test.rb +110 -0
  164. data/test/lib/cf_script/command/cf/routes/check_route_test.rb +31 -0
  165. data/test/lib/cf_script/command/cf/routes/create_route_test.rb +19 -0
  166. data/test/lib/cf_script/command/cf/routes/delete_route_test.rb +19 -0
  167. data/test/lib/cf_script/command/cf/routes/map_route_test.rb +56 -0
  168. data/test/lib/cf_script/command/cf/routes/routes_test.rb +24 -0
  169. data/test/lib/cf_script/command/cf/routes/unmap_route_test.rb +36 -0
  170. data/test/lib/cf_script/command/cf/spaces/space_test.rb +55 -0
  171. data/test/lib/cf_script/command/cf/spaces/spaces_test.rb +47 -0
  172. data/test/lib/cf_script/command/line_test.rb +59 -0
  173. data/test/lib/cf_script/object/api_endpoint_test.rb +19 -0
  174. data/test/lib/cf_script/object/app_info_test.rb +127 -0
  175. data/test/lib/cf_script/object/app_list_test.rb +51 -0
  176. data/test/lib/cf_script/object/attribute_list_test.rb +42 -0
  177. data/test/lib/cf_script/object/attribute_test.rb +29 -0
  178. data/test/lib/cf_script/object/instance_status_test.rb +37 -0
  179. data/test/lib/cf_script/object/space_test.rb +31 -0
  180. data/test/lib/cf_script/object/target_test.rb +41 -0
  181. data/test/lib/cf_script/output/buffer_test.rb +73 -0
  182. data/test/lib/cf_script/output/parser/attributes_test.rb +102 -0
  183. data/test/lib/cf_script/output/parser/section_test.rb +60 -0
  184. data/test/lib/cf_script/output/parser/table_test.rb +108 -0
  185. data/test/lib/cf_script/output/tests_test.rb +91 -0
  186. data/test/lib/cf_script/output_test.rb +134 -0
  187. data/test/lib/cf_script/scope/app/state_test.rb +61 -0
  188. data/test/lib/cf_script/scope/app_test.rb +101 -0
  189. data/test/lib/cf_script/scope/script_test.rb +88 -0
  190. data/test/lib/cf_script/scope/space_test.rb +27 -0
  191. data/test/lib/cf_script/scope/target_test.rb +158 -0
  192. data/test/lib/cf_script/scope_test.rb +41 -0
  193. data/test/lib/cf_script/utils_test.rb +20 -0
  194. data/test/lib/cf_script_test.rb +73 -0
  195. data/test/support/assertions.rb +14 -0
  196. data/test/support/helpers/config_context.rb +19 -0
  197. data/test/support/helpers/fixture_executor.rb +79 -0
  198. data/test/support/helpers/mock_execution.rb +58 -0
  199. data/test/support/helpers/object_helpers.rb +29 -0
  200. data/test/support/helpers/output_sink.rb +25 -0
  201. data/test/support/helpers.rb +3 -0
  202. data/test/support/shared_examples/command_object.rb +38 -0
  203. data/test/support/shared_examples.rb +30 -0
  204. data/test/test_helper.rb +34 -0
  205. metadata +321 -0
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ describe 'ApiCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::General::ApiCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :general,
10
+ has_name: :api,
11
+ fails_with: nil
12
+ }
13
+
14
+ describe "without an argument" do
15
+ it "returns the current api endpoint" do
16
+ fake_cf api: :good do |stdout, stderr|
17
+ endpoint = command.run
18
+
19
+ assert_instance_of CfScript::ApiEndpoint, endpoint
20
+ assert_equal 'https://api.cf.io', endpoint.url
21
+ assert_equal '1.0.0', endpoint.version
22
+ end
23
+ end
24
+
25
+ it "returns nil when the api endpoint is not set" do
26
+ fake_cf api: :not_set do |stdout, stderr|
27
+ assert_equal nil, command.run
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "with an argument" do
33
+ it "sets the current api endpoint and returns its object" do
34
+ fake_cf api: :set do |stdout, stderr|
35
+ endpoint = command.run 'https://api.test.com'
36
+
37
+ assert_instance_of CfScript::ApiEndpoint, endpoint
38
+ assert_equal 'https://api.test.com', endpoint.url
39
+ assert_equal '1.2.3', endpoint.version
40
+ end
41
+ end
42
+
43
+ it "returns nil when the argument is invalid" do
44
+ fake_cf api: :bad_argument do |stdout, stderr|
45
+ assert_equal nil, command.run('')
46
+ end
47
+ end
48
+
49
+ it "returns nil when the endpoint is invalid" do
50
+ fake_cf api: :bad_endpoint do |stdout, stderr|
51
+ assert_equal nil, command.run('https://api.example.com')
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,76 @@
1
+ require 'test_helper'
2
+
3
+ describe 'AuthCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::General::AuthCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :general,
10
+ has_name: :auth,
11
+ fails_with: false
12
+ }
13
+
14
+ it "returns true on success" do
15
+ fake_cf do
16
+ assert_equal true, command.run('user', 'pass')
17
+ end
18
+ end
19
+
20
+ it "returns false when credentials get rejected" do
21
+ fake_cf auth: :rejected do
22
+ assert_equal false, command.run('user', 'pass')
23
+ end
24
+ end
25
+
26
+ it "returns false if the output is empty" do
27
+ fake_cf auth: :empty do
28
+ result = command.run('name', 'word')
29
+
30
+ assert_equal false, result
31
+ end
32
+ end
33
+
34
+ it "hides the password in trace messages" do
35
+ fake_cf do |stdout, stderr|
36
+ command.run('user', 'pass')
37
+
38
+ assert_includes stdout, "<running> cf auth user [PASSWORD HIDDEN]\n"
39
+ end
40
+ end
41
+
42
+ it "prints an error when credentials get rejected" do
43
+ fake_cf auth: :rejected do |stdout, stderr|
44
+ command.run('user', 'pass')
45
+
46
+ assert_includes stderr.lines, "{auth} Credentials were rejected\n"
47
+ end
48
+ end
49
+
50
+ describe "with a block" do
51
+ it "yields true on success" do
52
+ fake_cf do
53
+ called = false
54
+
55
+ command.run 'user', 'pass' do |logged_in|
56
+ assert_equal true, logged_in
57
+ called = true
58
+ end
59
+
60
+ assert called, "Expected block to have been called"
61
+ end
62
+ end
63
+
64
+ it "does not yield on failure" do
65
+ fake_cf auth: :fail do
66
+ called = false
67
+
68
+ command.run 'user', 'pass' do |logged_in|
69
+ called = true
70
+ end
71
+
72
+ refute called, "Expected block to not have been called"
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+
3
+ describe 'LoginCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::General::LoginCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :general,
10
+ has_name: :login,
11
+ fails_with: false
12
+ }
13
+
14
+ it "returns true on success" do
15
+ fake_cf do
16
+ assert_equal true, command.run('user', 'pass')
17
+ end
18
+ end
19
+
20
+ it "include api, org, and space options" do
21
+ options = {
22
+ api: 'https://api.example.io',
23
+ org: 'ACME',
24
+ space: 'staging'
25
+ }
26
+
27
+ fake_cf do |stdout, stderr|
28
+ command.run('user', 'pass', options)
29
+
30
+ trace = stdout.lines.last
31
+ assert_match /cf login/, trace
32
+ assert_match /-u user -p \[PASSWORD HIDDEN\]/, trace
33
+ assert_match /-a https:\/\/api.example.io/, trace
34
+ assert_match /-o ACME/, trace
35
+ assert_match /-s staging/, trace
36
+ end
37
+ end
38
+
39
+ it "returns false when credentials get rejected" do
40
+ fake_cf login: :rejected do
41
+ assert_equal false, command.run('user', 'pass')
42
+ end
43
+ end
44
+
45
+ it "prints an error when credentials get rejected" do
46
+ fake_cf login: :rejected do |stdout, stderr|
47
+ command.run('user', 'pass')
48
+
49
+ assert_includes stdout.lines, "<running> cf login -u user -p [PASSWORD HIDDEN]\n"
50
+ assert_includes stderr.lines, "{login} Credentials were rejected\n"
51
+ end
52
+ end
53
+
54
+ describe "with a block" do
55
+ it "yields true on success" do
56
+ fake_cf do
57
+ called = false
58
+
59
+ command.run 'user', 'pass' do |logged_in|
60
+ assert_equal true, logged_in
61
+ called = true
62
+ end
63
+
64
+ assert called, "Expected block to have been called"
65
+ end
66
+ end
67
+
68
+ it "does not yield on failure" do
69
+ fake_cf login: :fail do
70
+ called = false
71
+
72
+ command.run 'user', 'pass' do |logged_in|
73
+ called = true
74
+ end
75
+
76
+ refute called, "Expected block to not have been called"
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ describe 'LogoutCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::General::LogoutCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :general,
10
+ has_name: :logout,
11
+ fails_with: false
12
+ }
13
+
14
+ it "returns true on success" do
15
+ fake_cf do
16
+ assert_equal true, command.run
17
+ end
18
+ end
19
+
20
+ describe "with a block" do
21
+ it "yields true" do
22
+ fake_cf do
23
+ called = false
24
+
25
+ command.run do |logged_out|
26
+ assert_equal true, logged_out
27
+ called = true
28
+ end
29
+
30
+ assert called, "Expected block to have been called"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,110 @@
1
+ require 'test_helper'
2
+
3
+ describe 'TargetCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::General::TargetCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :general,
10
+ has_name: :target,
11
+ fails_with: nil
12
+ }
13
+
14
+ it "returns nil and prints an error on parsing failure" do
15
+ fake_cf target: :empty do |stdout, stderr|
16
+ assert_equal nil, command.run
17
+
18
+ assert_includes stderr.lines, "{target} object is nil\n"
19
+ end
20
+ end
21
+
22
+ describe "without an argument" do
23
+ it "returns the current target's attributes" do
24
+ expected = {
25
+ api_endpoint: 'https://api.cf.io (API version: 1.0.0)',
26
+ org: 'ACME',
27
+ user: 'user@example.com',
28
+ space: 'development'
29
+ }
30
+
31
+ fake_cf target: :good do
32
+ target = command.run
33
+
34
+ expected.keys.each do |key|
35
+ assert_equal expected[key], target.send(key)
36
+ end
37
+ end
38
+ end
39
+
40
+ it "returns a blank space name when there isn't a current one targeted" do
41
+ expected = {
42
+ api_endpoint: 'https://api.cf.io (API version: 1.0.0)',
43
+ org: 'ACME',
44
+ user: 'user@example.com',
45
+ space: ''
46
+ }
47
+
48
+ fake_cf target: :no_space do |stdout, stderr|
49
+ target = command.run
50
+
51
+ expected.keys.each do |key|
52
+ assert_equal expected[key], target.send(key)
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "with an argument" do
59
+ it "returns the target attributes for the given space" do
60
+ expected = {
61
+ api_endpoint: 'https://api.cf.io (API version: 1.0.0)',
62
+ org: 'ACME',
63
+ user: 'user@example.com',
64
+ space: 'staging'
65
+ }
66
+
67
+ fake_cf target: :staging do
68
+ target = command.run(:staging)
69
+
70
+ expected.keys.each do |key|
71
+ assert_equal expected[key], target.send(key)
72
+ end
73
+ end
74
+ end
75
+
76
+ it "returns nil and prints an error when the space is not found" do
77
+ fake_cf do |stdout, stderr|
78
+ assert_equal nil, command.run(:not_found)
79
+
80
+ assert_includes stderr.lines, "{target} Space not_found not found\n"
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "without a block" do
86
+ it "returns an object with the target's attributes" do
87
+ fake_cf target: :good do
88
+ target = command.run
89
+
90
+ assert_respond_to target, :api_endpoint
91
+ assert_respond_to target, :org
92
+ assert_respond_to target, :user
93
+ assert_respond_to target, :space
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "with a block" do
99
+ it "yields an object with the target's attributes" do
100
+ fake_cf target: :good do |stdout, stderr|
101
+ command.run do |target|
102
+ assert_respond_to target, :api_endpoint
103
+ assert_respond_to target, :org
104
+ assert_respond_to target, :user
105
+ assert_respond_to target, :space
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ describe 'CheckRouteCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::Routes::CheckRouteCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :routes,
10
+ has_name: :check_route,
11
+ fails_with: false
12
+ }
13
+
14
+ it "returns true on success" do
15
+ fake_cf do
16
+ assert_equal true, command.run('api', 'example.com')
17
+ end
18
+ end
19
+
20
+ it "returns false when the route does not exist" do
21
+ fake_cf check_route: :no_route do
22
+ assert_equal false, command.run('api', 'example.com')
23
+ end
24
+ end
25
+
26
+ it "returns false when the domain does not exist" do
27
+ fake_cf check_route: :no_domain do
28
+ assert_equal false, command.run('api', 'example.com')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ describe 'CreateRouteCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::Routes::CreateRouteCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :routes,
10
+ has_name: :create_route,
11
+ fails_with: false
12
+ }
13
+
14
+ it "returns true on success" do
15
+ fake_cf do
16
+ assert_equal true, command.run(:staging, :api, 'example.com')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ describe 'DeleteRouteCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::Routes::DeleteRouteCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :routes,
10
+ has_name: :delete_route,
11
+ fails_with: false
12
+ }
13
+
14
+ it "returns true on success" do
15
+ fake_cf do
16
+ assert_equal true, command.run('example.com', :api)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ describe 'MapRouteCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::Routes::MapRouteCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :routes,
10
+ has_name: :map_route,
11
+ fails_with: false
12
+ }
13
+
14
+ it "returns true on success" do
15
+ fake_cf do
16
+ assert_equal true, command.run(:api, 'example.com')
17
+ assert_equal true, command.run(:api, 'example.com', 'api')
18
+ end
19
+ end
20
+
21
+ it "prints an error and returns false when the route is invalid" do
22
+ fake_cf map_route: :invalid do |stdout, stderr|
23
+ assert_equal false, command.run(:api, 'example.com')
24
+
25
+ assert_match /\{map_route\}/, stderr.lines.last
26
+ assert_match /Server error/, stderr.lines.last
27
+ assert_match /route is invalid/, stderr.lines.last
28
+ end
29
+ end
30
+
31
+ it "prints an error and returns false when the app can not be found" do
32
+ fake_cf map_route: :no_app do |stdout, stderr|
33
+ assert_equal false, command.run(:api, 'example.com')
34
+
35
+ assert_includes stderr.lines, "{map_route} App api not found\n"
36
+ end
37
+ end
38
+
39
+ it "prints an error and returns false when the domain can not be found" do
40
+ fake_cf map_route: :no_domain do |stdout, stderr|
41
+ assert_equal false, command.run(:api, 'example.com')
42
+
43
+ assert_includes stderr.lines, "{map_route} Domain example.com not found\n"
44
+ end
45
+ end
46
+
47
+ it "prints an error and returns false when the hostname is taken" do
48
+ fake_cf map_route: :host_taken do |stdout, stderr|
49
+ assert_equal false, command.run(:api, 'example.com')
50
+
51
+ assert_match /\{map_route\}/, stderr.lines.last
52
+ assert_match /Server error/, stderr.lines.last
53
+ assert_match /The host is taken: api/, stderr.lines.last
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ describe 'RoutesCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::Routes::RoutesCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :routes,
10
+ has_name: :routes,
11
+ fails_with: nil
12
+ }
13
+
14
+ it "returns an Array of RouteInfo objects on success" do
15
+ fake_cf do
16
+ routes = command.run
17
+
18
+ assert_instance_of Array, routes
19
+ routes.each do |route|
20
+ assert_instance_of CfScript::RouteInfo, route
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ describe 'UnmapRouteCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::Routes::UnmapRouteCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :routes,
10
+ has_name: :unmap_route,
11
+ fails_with: false
12
+ }
13
+
14
+ it "returns true on success" do
15
+ fake_cf do
16
+ assert_equal true, command.run(:api, 'example.com')
17
+ assert_equal true, command.run(:api, 'example.com', 'api')
18
+ end
19
+ end
20
+
21
+ it "prints an error and returns false when the app can not be found" do
22
+ fake_cf unmap_route: :no_app do |stdout, stderr|
23
+ assert_equal false, command.run(:api, 'example.com')
24
+
25
+ assert_includes stderr.lines, "{unmap_route} App api not found\n"
26
+ end
27
+ end
28
+
29
+ it "prints an error and returns false when the domain can not be found" do
30
+ fake_cf unmap_route: :no_domain do |stdout, stderr|
31
+ assert_equal false, command.run(:api, 'example.com')
32
+
33
+ assert_includes stderr.lines, "{unmap_route} Domain example.com not found\n"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ describe 'SpaceCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::Spaces::SpaceCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :spaces,
10
+ has_name: :space,
11
+ fails_with: nil
12
+ }
13
+
14
+ it "returns a space object" do
15
+ expected = {
16
+ name: :staging,
17
+ org: 'ACME',
18
+ apps: ['org-frontend-staging', 'org-backend-staging'],
19
+ domains: ['cf.io', 'example.com'],
20
+ services: ['org-db', 'org-cache'],
21
+ security_groups: ['ssh', 'dns', 'log'],
22
+ }
23
+
24
+ fake_cf do
25
+ space = command.run(:staging)
26
+
27
+ expected.keys.each do |key|
28
+ assert_equal expected[key], space.send(key)
29
+ end
30
+ end
31
+ end
32
+
33
+ it "returns nil if the output was empty" do
34
+ fake_cf space: :empty do
35
+ space = command.run(:space)
36
+
37
+ assert_equal nil, space
38
+ end
39
+ end
40
+
41
+ describe "with a block" do
42
+ it "yields a space object" do
43
+ fake_cf space: :good do
44
+ command.run(:staging) do |space|
45
+ assert_respond_to space, :name
46
+ assert_respond_to space, :org
47
+ assert_respond_to space, :apps
48
+ assert_respond_to space, :domains
49
+ assert_respond_to space, :services
50
+ assert_respond_to space, :security_groups
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ describe 'SpacesCommand' do
4
+ include MockExecution
5
+
6
+ let(:command) { CfScript::Command::Spaces::SpacesCommand.instance }
7
+
8
+ it_behaves_like 'a command object that', {
9
+ has_type: :spaces,
10
+ has_name: :spaces,
11
+ fails_with: nil
12
+ }
13
+
14
+ it "returns an Array of space names" do
15
+ fake_cf spaces: :good do
16
+ spaces = command.run
17
+
18
+ assert_kind_of Array, spaces
19
+ assert_equal ['development', 'staging', 'production'], spaces
20
+ end
21
+ end
22
+
23
+ it "returns nil if the spaces table was not found" do
24
+ fake_cf spaces: :empty do
25
+ spaces = command.run
26
+
27
+ assert_equal nil, spaces
28
+ end
29
+ end
30
+
31
+ it "yields an Array of space names when a block is given" do
32
+ fake_cf do
33
+ called = false
34
+
35
+ command.run do |spaces|
36
+ called = true
37
+
38
+ assert_kind_of Array, spaces
39
+ spaces.each do |space_name|
40
+ assert_includes ['development', 'staging', 'production'], space_name
41
+ end
42
+ end
43
+
44
+ assert called, "Expected block to have been called"
45
+ end
46
+ end
47
+ end