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,108 @@
1
+ require 'test_helper'
2
+
3
+ describe CfScript::Output::Parser::Table do
4
+ attr_accessor :parser
5
+
6
+ attr_accessor :text_buffer
7
+
8
+ class TableParserTest
9
+ include CfScript::Utils
10
+ include CfScript::Output::Parser::Attributes
11
+ include CfScript::Output::Parser::Table
12
+ end
13
+
14
+ def setup
15
+ @parser = TableParserTest.new
16
+
17
+ @text_buffer = "Something\n\n" +
18
+ " value another value final value \n"+
19
+ "one 123 A bit long Last one\n" +
20
+ "two 234 Short \n" +
21
+ "tre 345 Third End\n" +
22
+ "\n"
23
+ end
24
+
25
+ describe "parse_columns" do
26
+ it "returns an Array with the column names" do
27
+ cols = parser.parse_columns(text_buffer.lines[2])
28
+
29
+ assert_instance_of Array, cols
30
+ assert_equal 4, cols.length
31
+ end
32
+
33
+ it "strips white space before/after column names" do
34
+ cols = parser.parse_columns(text_buffer.lines[2])
35
+
36
+ assert_equal [
37
+ '',
38
+ 'value',
39
+ 'another value',
40
+ 'final value'
41
+ ], cols
42
+ end
43
+ end
44
+
45
+ describe "parse_row" do
46
+ it "returns an AttributeList object" do
47
+ cols = parser.parse_columns(text_buffer.lines[2])
48
+ row = parser.parse_row(text_buffer.lines[3], cols)
49
+
50
+ assert_instance_of CfScript::AttributeList, row
51
+ end
52
+
53
+ it "symbolizes attribute names" do
54
+ cols = parser.parse_columns(text_buffer.lines[2])
55
+ row = parser.parse_row(text_buffer.lines[3], cols)
56
+
57
+ assert_equal [
58
+ :index, :value, :another_value, :final_value
59
+ ], row.names
60
+ end
61
+
62
+ it "strips whitespace surrounding values" do
63
+ cols = parser.parse_columns(text_buffer.lines[2])
64
+ row = parser.parse_row(text_buffer.lines[4], cols)
65
+
66
+ assert_equal [
67
+ "two", "234", "Short", ""
68
+ ], row.values
69
+ end
70
+ end
71
+
72
+ describe "parse_rows" do
73
+ it "returns an Array of AttributeList objects" do
74
+ rows = parser.parse_rows(text_buffer.lines)
75
+
76
+ assert_instance_of Array, rows
77
+ rows.each do |row|
78
+ assert_instance_of CfScript::AttributeList, row
79
+ end
80
+ end
81
+
82
+ it "returns an empty Array if no table is found" do
83
+ rows = parser.parse_rows([''])
84
+
85
+ assert_instance_of Array, rows
86
+ assert_equal [], rows
87
+ end
88
+ end
89
+
90
+ describe "parse_table" do
91
+ it "returns an Array of AttributeList objects" do
92
+ rows = parser.parse_table(text_buffer, [
93
+ '', 'value', 'another value', 'final value'
94
+ ])
95
+
96
+ assert_instance_of Array, rows
97
+ rows.each do |row|
98
+ assert_instance_of CfScript::AttributeList, row
99
+ end
100
+ end
101
+
102
+ it "returns nil of nothing matched" do
103
+ rows = parser.parse_table(text_buffer, ['foo'])
104
+
105
+ assert_equal nil, rows
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,91 @@
1
+ require 'test_helper'
2
+
3
+ describe CfScript::Output::Tests do
4
+ include MockExecution
5
+
6
+ it "defines matches? and calls the out buffer matches?" do
7
+ output = fake_output
8
+
9
+ output.out.stub :matches?, 'called' do
10
+ assert_equal 'called', output.matches?('a')
11
+ end
12
+ end
13
+
14
+ it "defines contains? and calls the out buffer matches?" do
15
+ output = fake_output
16
+
17
+ output.out.stub :contains?, 'called' do
18
+ assert_equal 'called', output.contains?('a')
19
+ end
20
+ end
21
+
22
+ it "defines ok?, calls the out buffer last_line_matches?" do
23
+ output = fake_output('OK')
24
+
25
+ assert output.ok?
26
+ refute fake_output('KO').ok?
27
+ end
28
+
29
+ it "defines authenticated? and calls matches?" do
30
+ output = fake_output("Authenticating...\nOK")
31
+
32
+ assert output.authenticated?
33
+ refute fake_output('NOPE').authenticated?
34
+ end
35
+
36
+ it "defines failed? and calls contains?" do
37
+ output = fake_output("FAILED")
38
+
39
+ assert output.failed?
40
+ refute fake_output('OK').failed?
41
+ end
42
+
43
+ it "defines no_api_endpoint? and calls contains?" do
44
+ output = fake_output("No API endpoint set.")
45
+
46
+ assert output.no_api_endpoint?
47
+ refute fake_output('API endpoint set').no_api_endpoint?
48
+ end
49
+
50
+ it "defines not_logged_in? and calls contains?" do
51
+ output = fake_output("Not logged in")
52
+
53
+ assert output.not_logged_in?
54
+ refute fake_output('logged in').not_logged_in?
55
+ end
56
+
57
+ it "defines not_authorized? and calls contains?" do
58
+ output = fake_output("You are not authorized")
59
+
60
+ assert output.not_authorized?
61
+ refute fake_output('You are authorized').not_authorized?
62
+ end
63
+
64
+ it "defines credentials_rejected? and calls contains?" do
65
+ output = fake_output("Credentials were rejected")
66
+
67
+ assert output.credentials_rejected?
68
+ refute fake_output('Credentials accepted').credentials_rejected?
69
+ end
70
+
71
+ it "defines not_found? and calls out buffer's last_line_matches?" do
72
+ output = fake_output("App api not found")
73
+
74
+ assert output.not_found?('App', 'api')
75
+ refute fake_output('Found').not_found?('App', 'api')
76
+ end
77
+
78
+ it "defines is_already? and calls out buffer's last_line_matches?" do
79
+ output = fake_output("app is already started")
80
+
81
+ assert output.is_already?('app', 'started')
82
+ refute fake_output('app not started').is_already?('app', 'started')
83
+ end
84
+
85
+ it "defines already_exists? and calls out buffer's last_line_matches?" do
86
+ output = fake_output("App api already exists")
87
+
88
+ assert output.already_exists?('App', 'api')
89
+ refute fake_output('App api does not exist').already_exists?('App', 'api')
90
+ end
91
+ end
@@ -0,0 +1,134 @@
1
+ require 'test_helper'
2
+
3
+ describe CfScript::Output do
4
+ include MockExecution
5
+
6
+ attr_accessor :output
7
+
8
+ def setup
9
+ @output = fake_output(
10
+ "one: first\n" +
11
+ "two: second, place: middle\n" +
12
+ "third: last\n\n" +
13
+ "col1 col2\n" +
14
+ "val1 val2\n" +
15
+ "val3 val4\n",
16
+
17
+ "stderr",
18
+
19
+ 0
20
+ )
21
+ end
22
+
23
+ it "responds to good? and returns true if exit status == 0" do
24
+ assert output.respond_to?(:good?)
25
+ assert output.good?
26
+ end
27
+
28
+ it "responds to good? and returns false if exit status != 0" do
29
+ refute fake_output('', '', 1).good?
30
+ end
31
+
32
+ it "responds to out and returns a Buffer object" do
33
+ assert_instance_of CfScript::Output::Buffer, output.out
34
+ end
35
+
36
+ it "responds to err and returns a Buffer object" do
37
+ assert_instance_of CfScript::Output::Buffer, output.err
38
+ end
39
+
40
+ it "responds to last_line and returns last line of stdout" do
41
+ assert_equal 'val3 val4', output.last_line
42
+ end
43
+
44
+ describe "attributes" do
45
+ it "calls parse_attribute_list" do
46
+ assert output.respond_to?(:attributes)
47
+
48
+ output.stub :parse_attribute_list, 'called' do
49
+ assert_equal 'called', output.attributes
50
+ end
51
+ end
52
+
53
+ it "returns an AttributeList object" do
54
+ assert_instance_of CfScript::AttributeList, output.attributes
55
+ assert_equal 3, output.attributes.length
56
+ end
57
+ end
58
+
59
+ describe "line_attributes" do
60
+ it "calls parse_line_attributes" do
61
+ assert output.respond_to?(:line_attributes)
62
+
63
+ output.stub :parse_line_attributes, 'called' do
64
+ assert_equal 'called', output.line_attributes(/a/)
65
+ end
66
+ end
67
+
68
+ it "returns an AttributeList object" do
69
+ regex = /two: (?<position>[^,]+), place: (?<index>.+)/
70
+ attrs = output.line_attributes(regex)
71
+
72
+ assert_instance_of CfScript::AttributeList, attrs
73
+ assert_equal 2, attrs.length
74
+
75
+ assert_equal 'second', attrs[:position].value
76
+ assert_equal 'middle', attrs[:index].value
77
+ end
78
+ end
79
+
80
+ describe "attributes_from" do
81
+ it "calls from on out buffer" do
82
+ expected = { from: 'called' }
83
+
84
+ output.out.stub :from, 'from: called' do
85
+ assert_equal expected, output.attributes_from('foo').to_h
86
+ end
87
+ end
88
+
89
+ it "calls parse_attribute_list" do
90
+ assert output.respond_to?(:attributes_from)
91
+
92
+ output.stub :parse_attribute_list, 'called' do
93
+ assert_equal 'called', output.attributes_from('two')
94
+ end
95
+ end
96
+
97
+ it "returns an AttributeList object" do
98
+ attrs = output.attributes_from('third')
99
+
100
+ assert_instance_of CfScript::AttributeList, attrs
101
+ assert_equal 1, attrs.length
102
+
103
+ assert_equal 'last', attrs[:third].value
104
+ end
105
+ end
106
+
107
+ describe "table" do
108
+ it "calls parse_table" do
109
+ assert output.respond_to?(:table)
110
+
111
+ output.stub :parse_table, 'called' do
112
+ assert_equal 'called', output.table([])
113
+ end
114
+ end
115
+
116
+ it "returns an Array of AttributeList objects" do
117
+ rows = output.table(['col1', 'col2'])
118
+
119
+ assert_instance_of Array, rows
120
+ assert_instance_of CfScript::AttributeList, rows.first
121
+ assert_equal 2, rows.length
122
+ end
123
+ end
124
+
125
+ describe "section_attributes" do
126
+ it "calls parse_section_attributes" do
127
+ assert output.respond_to?(:section_attributes)
128
+
129
+ output.stub :parse_section_attributes, 'called' do
130
+ assert_equal 'called', output.section_attributes('header')
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ describe CfScript::Scope::App::State do
4
+ include MockExecution
5
+
6
+ let(:target) { CfScript::Target.new('API', 'ORG', 'staging') }
7
+
8
+ def create_app(name)
9
+ app = nil
10
+ fake_cf { app = CfScript::Scope::App.new(:api, target) }
11
+ app
12
+ end
13
+
14
+ it "defines a start method that calls Command.start with the app name" do
15
+ app = create_app(:api)
16
+
17
+ arg_catcher = lambda do |command, *args, &block|
18
+ assert_equal :start, command
19
+ assert_equal [:api], args
20
+
21
+ return :called
22
+ end
23
+
24
+ CfScript::Command.stub :run, arg_catcher do
25
+ assert_equal :called, app.start
26
+ end
27
+ end
28
+
29
+ it "defines a stop method that calls Command.stop with the app name" do
30
+ app = create_app(:api)
31
+
32
+ arg_catcher = lambda do |command, *args, &block|
33
+ assert_equal :stop, command
34
+ assert_equal [:api], args
35
+
36
+ return :called
37
+ end
38
+
39
+ app.stub :cf_self, true do
40
+ CfScript::Command.stub :run, arg_catcher do
41
+ assert_equal :called, app.stop
42
+ end
43
+ end
44
+ end
45
+
46
+ it "defines a push method that calls Command.push with the app name and options" do
47
+ app = create_app(:api)
48
+
49
+ arg_catcher = lambda do |command, *args, &block|
50
+ assert_equal :push, command
51
+ assert_equal :api, args.first
52
+ assert_equal({ memory: '128MB' }, args.last)
53
+
54
+ return :called
55
+ end
56
+
57
+ CfScript::Command.stub :run, arg_catcher do
58
+ assert_equal :called, app.push({ memory: '128MB' })
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,101 @@
1
+ require 'test_helper'
2
+
3
+ describe CfScript::Scope::App do
4
+ include MockExecution
5
+
6
+ let(:target) { CfScript::Target.new('API', 'ORG', 'staging') }
7
+
8
+ subject { fake_cf { CfScript::Scope::App.new(:api, target) } }
9
+
10
+ it "subclasses Scope::Base" do
11
+ assert_kind_of CfScript::Scope::Base, subject
12
+ end
13
+
14
+ it "sets current_target" do
15
+ assert subject.current_target, "Expected current_target to be set"
16
+ end
17
+
18
+ it "calls cf_self (which sets app_info) when initialized by name" do
19
+ assert subject.app_info, "Expected app_info not to be nil"
20
+ assert_instance_of CfScript::AppInfo, subject.app_info
21
+ end
22
+
23
+ it "calls cf_self (which completes the app_info) when initialized by AppInfo" do
24
+ app = nil
25
+
26
+ fake_cf do
27
+ app_info = CfScript::AppInfo.new(:api, {})
28
+ app = CfScript::Scope::App.new(app_info, target)
29
+ end
30
+
31
+ assert_equal 'stopped', subject.app_info.requested_state
32
+ assert_equal '0/1', subject.app_info.instances
33
+ assert_equal [], subject.app_info.urls
34
+ end
35
+
36
+ it "raises if initialized with anything other than a name or AppInfo" do
37
+ assert_raises(RuntimeError) {
38
+ fake_cf do
39
+ app = CfScript::Scope::App.new([], target)
40
+ end
41
+ }
42
+ end
43
+
44
+ it "responds to current_space and returns it" do
45
+ assert_equal 'staging', subject.current_space
46
+ end
47
+
48
+ it "reponds to name_tag and returns space:name" do
49
+ assert_equal 'staging:api', subject.name_tag
50
+ end
51
+
52
+ it "reponds to tag_color and returns state" do
53
+ subject.app_info.stub :state, 'started' do
54
+ assert_equal :active, subject.tag_color
55
+ end
56
+
57
+ subject.app_info.stub :state, 'stopped' do
58
+ assert_equal :inactive, subject.tag_color
59
+ end
60
+ end
61
+
62
+ it "delegates to app_info for all data attributes" do
63
+ assert_respond_to subject, :requested_state
64
+ assert_respond_to subject, :instances
65
+ assert_respond_to subject, :urls
66
+ assert_respond_to subject, :usage
67
+ assert_respond_to subject, :last_uploaded
68
+ assert_respond_to subject, :stack
69
+ assert_respond_to subject, :buildpack
70
+ assert_respond_to subject, :memory
71
+ assert_respond_to subject, :disk
72
+ assert_respond_to subject, :state
73
+ assert_respond_to subject, :started?
74
+ assert_respond_to subject, :hot?
75
+ assert_respond_to subject, :stopped?
76
+ assert_respond_to subject, :cold?
77
+ end
78
+
79
+ it "includes the App::State module" do
80
+ assert_respond_to subject, :start
81
+ assert_respond_to subject, :stop
82
+ assert_respond_to subject, :push
83
+ end
84
+
85
+ it "includes the App::Env module" do
86
+ assert_respond_to subject, :env
87
+ assert_respond_to subject, :set_env
88
+ assert_respond_to subject, :unset_env
89
+ end
90
+
91
+ it "includes the App::Routes module" do
92
+ assert_respond_to subject, :has_route?
93
+ assert_respond_to subject, :map_route
94
+ assert_respond_to subject, :unmap_route
95
+ end
96
+
97
+ it "includes the App::Utils module" do
98
+ assert_respond_to subject, :dump
99
+ assert_respond_to subject, :show
100
+ end
101
+ end
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+
3
+ describe CfScript::Scope::Script do
4
+ include MockExecution
5
+
6
+ it "behaves like a subclass of Scope::Target" do
7
+ script = nil
8
+
9
+ fake_cf target: :production do
10
+ script = CfScript::Scope::Script.new
11
+ end
12
+
13
+ assert_kind_of CfScript::Scope::Target, script
14
+ assert_equal 'production', script.current_space
15
+ end
16
+
17
+ it "responds to run and calls exec_in with self and the block" do
18
+ script = nil
19
+
20
+ fake_cf target: :staging do
21
+ script = CfScript::Scope::Script.new
22
+ end
23
+
24
+ assert script.respond_to?(:run)
25
+
26
+ arg_catcher = lambda do |scope, args, &block|
27
+ assert_same script, scope
28
+ end
29
+
30
+ script.stub :exec_in, arg_catcher do
31
+ assert script.run { nil }
32
+ end
33
+ end
34
+
35
+ it "calls the api command when the api option is given without login options" do
36
+ script = nil
37
+
38
+ fake_cf do
39
+ script = CfScript::Scope::Script.new({ api: :ipa })
40
+
41
+ arg_catcher = lambda do |command, args, &block|
42
+ assert_equal :api, command
43
+ assert_equal :ipa, args
44
+ end
45
+
46
+ CfScript::Command.stub :run, arg_catcher do
47
+ script.apply_options()
48
+ end
49
+ end
50
+ end
51
+
52
+ it "calls the login command when the user/pass options are given" do
53
+ script = nil
54
+ options = { api: :skip, username: :name, password: :word, space: :skip }
55
+
56
+ fake_cf do
57
+ script = CfScript::Scope::Script.new(options)
58
+
59
+ arg_catcher = lambda do |command, *args, &block|
60
+ assert_equal :login, command
61
+ assert_equal :name, args[0]
62
+ assert_equal :word, args[1]
63
+ assert_equal options, args[2]
64
+ end
65
+
66
+ CfScript::Command.stub :run, arg_catcher do
67
+ script.apply_options()
68
+ end
69
+ end
70
+ end
71
+
72
+ it "calls the target command when the space option is given without login options" do
73
+ script = nil
74
+
75
+ fake_cf do
76
+ script = CfScript::Scope::Script.new({ space: :staging })
77
+
78
+ arg_catcher = lambda do |command, args, &block|
79
+ assert_equal :target, command
80
+ assert_equal :staging, args
81
+ end
82
+
83
+ CfScript::Command.stub :run, arg_catcher do
84
+ script.apply_options()
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ describe CfScript::Scope::Space do
4
+ include MockExecution
5
+
6
+ it "behaves like a subclass of Scope::Target" do
7
+ space = nil
8
+
9
+ fake_cf target: :staging do
10
+ space = CfScript::Scope::Space.new
11
+ end
12
+
13
+ assert_kind_of CfScript::Scope::Target, space
14
+
15
+ assert_equal 'staging', space.current_space
16
+ end
17
+
18
+ it "calls target when initialized with a space name" do
19
+ space = nil
20
+
21
+ fake_cf target: :staging do
22
+ space = CfScript::Scope::Space.new(:production)
23
+ end
24
+
25
+ assert_equal 'production', space.current_space
26
+ end
27
+ end