ncfoundry 4.9.2

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 (268) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +11 -0
  8. data/Checkfile +2 -0
  9. data/Gemfile +3 -0
  10. data/LICENSE +987 -0
  11. data/NOTICE +10 -0
  12. data/README.md +9 -0
  13. data/Rakefile +14 -0
  14. data/VERSION +1 -0
  15. data/cfoundry.gemspec +41 -0
  16. data/config/locales/en.yml +168 -0
  17. data/lib/cc_api_stub/app_usage_events.rb +11 -0
  18. data/lib/cc_api_stub/applications.rb +57 -0
  19. data/lib/cc_api_stub/domains.rb +32 -0
  20. data/lib/cc_api_stub/events.rb +11 -0
  21. data/lib/cc_api_stub/frameworks.rb +22 -0
  22. data/lib/cc_api_stub/helper.rb +148 -0
  23. data/lib/cc_api_stub/login.rb +21 -0
  24. data/lib/cc_api_stub/organization_users.rb +27 -0
  25. data/lib/cc_api_stub/organizations.rb +82 -0
  26. data/lib/cc_api_stub/routes.rb +26 -0
  27. data/lib/cc_api_stub/runtimes.rb +22 -0
  28. data/lib/cc_api_stub/service_bindings.rb +22 -0
  29. data/lib/cc_api_stub/service_instances.rb +22 -0
  30. data/lib/cc_api_stub/services.rb +21 -0
  31. data/lib/cc_api_stub/space_users.rb +27 -0
  32. data/lib/cc_api_stub/spaces.rb +58 -0
  33. data/lib/cc_api_stub/users.rb +85 -0
  34. data/lib/cc_api_stub.rb +20 -0
  35. data/lib/cfoundry/auth_token.rb +62 -0
  36. data/lib/cfoundry/baseclient.rb +220 -0
  37. data/lib/cfoundry/chatty_hash.rb +46 -0
  38. data/lib/cfoundry/client.rb +42 -0
  39. data/lib/cfoundry/concerns/login_helpers.rb +14 -0
  40. data/lib/cfoundry/concerns/proxy_options.rb +14 -0
  41. data/lib/cfoundry/errors.rb +163 -0
  42. data/lib/cfoundry/rest_client.rb +316 -0
  43. data/lib/cfoundry/test_support.rb +3 -0
  44. data/lib/cfoundry/trace_helpers.rb +64 -0
  45. data/lib/cfoundry/uaaclient.rb +151 -0
  46. data/lib/cfoundry/upload_helpers.rb +222 -0
  47. data/lib/cfoundry/v2/app.rb +313 -0
  48. data/lib/cfoundry/v2/app_event.rb +13 -0
  49. data/lib/cfoundry/v2/app_instance.rb +74 -0
  50. data/lib/cfoundry/v2/app_usage_event.rb +14 -0
  51. data/lib/cfoundry/v2/base.rb +112 -0
  52. data/lib/cfoundry/v2/client.rb +104 -0
  53. data/lib/cfoundry/v2/domain.rb +20 -0
  54. data/lib/cfoundry/v2/event.rb +17 -0
  55. data/lib/cfoundry/v2/helper.rb +11 -0
  56. data/lib/cfoundry/v2/managed_service_instance.rb +13 -0
  57. data/lib/cfoundry/v2/model.rb +213 -0
  58. data/lib/cfoundry/v2/model_magic/attribute.rb +49 -0
  59. data/lib/cfoundry/v2/model_magic/client_extensions.rb +170 -0
  60. data/lib/cfoundry/v2/model_magic/has_summary.rb +49 -0
  61. data/lib/cfoundry/v2/model_magic/query_multi_value_helper.rb +21 -0
  62. data/lib/cfoundry/v2/model_magic/query_value_helper.rb +33 -0
  63. data/lib/cfoundry/v2/model_magic/queryable_by.rb +39 -0
  64. data/lib/cfoundry/v2/model_magic/to_many.rb +145 -0
  65. data/lib/cfoundry/v2/model_magic/to_one.rb +81 -0
  66. data/lib/cfoundry/v2/model_magic.rb +134 -0
  67. data/lib/cfoundry/v2/organization.rb +44 -0
  68. data/lib/cfoundry/v2/quota_definition.rb +12 -0
  69. data/lib/cfoundry/v2/route.rb +25 -0
  70. data/lib/cfoundry/v2/service.rb +22 -0
  71. data/lib/cfoundry/v2/service_auth_token.rb +9 -0
  72. data/lib/cfoundry/v2/service_binding.rb +10 -0
  73. data/lib/cfoundry/v2/service_broker.rb +12 -0
  74. data/lib/cfoundry/v2/service_instance.rb +14 -0
  75. data/lib/cfoundry/v2/service_plan.rb +16 -0
  76. data/lib/cfoundry/v2/space.rb +31 -0
  77. data/lib/cfoundry/v2/stack.rb +10 -0
  78. data/lib/cfoundry/v2/user.rb +97 -0
  79. data/lib/cfoundry/v2/user_provided_service_instance.rb +16 -0
  80. data/lib/cfoundry/validator.rb +41 -0
  81. data/lib/cfoundry/version.rb +4 -0
  82. data/lib/cfoundry/zip.rb +56 -0
  83. data/lib/cfoundry.rb +6 -0
  84. data/release_notes/release_1_5_3.md +177 -0
  85. data/release_notes/release_2.3.1.md +14 -0
  86. data/release_notes/release_2.3.3.md +38 -0
  87. data/release_notes/release_2.3.4.md +16 -0
  88. data/release_notes/release_2.3.5.md +14 -0
  89. data/release_notes/release_2.3.6.md +14 -0
  90. data/release_notes/release_2.3.6.rc1.md +29 -0
  91. data/release_notes/release_2.3.6.rc2.md +19 -0
  92. data/release_notes/release_2.3.7.rc1.md +14 -0
  93. data/release_notes/release_2.4.0.md +41 -0
  94. data/release_notes/release_2.4.1.rc1.md +58 -0
  95. data/release_notes/release_3.0.0.md +21 -0
  96. data/release_notes/release_3.0.1.md +16 -0
  97. data/release_notes/release_3.0.2.rc1.md +19 -0
  98. data/release_notes/release_4.0.0.md +19 -0
  99. data/release_notes/release_4.0.1.md +14 -0
  100. data/release_notes/release_4.0.2.rc1.md +14 -0
  101. data/release_notes/release_4.0.2.rc2.md +11 -0
  102. data/release_notes/release_4.0.2.rc3.md +11 -0
  103. data/release_notes/release_4.0.2.rc4.md +19 -0
  104. data/release_notes/release_4.0.2.rc5.md +14 -0
  105. data/release_notes/release_4.0.3.md +19 -0
  106. data/release_notes/release_4.0.4.rc1.md +14 -0
  107. data/release_notes/release_4.0.4.rc2.md +14 -0
  108. data/release_notes/release_4.1.0.md +19 -0
  109. data/release_notes/release_4.2.0.rc.md +24 -0
  110. data/release_notes/release_4.3.0.md +22 -0
  111. data/release_notes/release_4.3.1.md +14 -0
  112. data/release_notes/release_4.3.10.md +14 -0
  113. data/release_notes/release_4.3.11.md +14 -0
  114. data/release_notes/release_4.3.12.md +14 -0
  115. data/release_notes/release_4.3.2.rc1.md +21 -0
  116. data/release_notes/release_4.3.3.md +24 -0
  117. data/release_notes/release_4.3.4.md +11 -0
  118. data/release_notes/release_4.3.4.rc1.md +24 -0
  119. data/release_notes/release_4.3.5.md +36 -0
  120. data/release_notes/release_4.3.5.rc1.md +21 -0
  121. data/release_notes/release_4.3.6.md +14 -0
  122. data/release_notes/release_4.3.7.md +50 -0
  123. data/release_notes/release_4.3.8.md +19 -0
  124. data/release_notes/release_4.3.9.md +14 -0
  125. data/release_notes/release_4.4.0.md +16 -0
  126. data/release_notes/release_4.5.1.md +11 -0
  127. data/release_notes/release_4.5.2.md +14 -0
  128. data/release_notes/release_4.5.3.md +29 -0
  129. data/release_notes/release_4.6.0.md +24 -0
  130. data/release_notes/release_4.6.1.md +14 -0
  131. data/release_notes/release_4.6.2.md +16 -0
  132. data/release_notes/release_4.6.3.rc1.md +14 -0
  133. data/release_notes/release_4.6.3.rc2.md +14 -0
  134. data/release_notes/release_4.6.3.rc3.md +17 -0
  135. data/release_notes/release_4.7.0.md +11 -0
  136. data/release_notes/release_4.7.1.md +14 -0
  137. data/release_notes/release_4.7.1.rc.1.md +14 -0
  138. data/release_notes/release_4.7.1.rc1.md +19 -0
  139. data/script/gpp +3 -0
  140. data/spec/cc_api_stub/app_usage_events_spec.rb +12 -0
  141. data/spec/cc_api_stub/applications_spec.rb +69 -0
  142. data/spec/cc_api_stub/domains_spec.rb +40 -0
  143. data/spec/cc_api_stub/events_spec.rb +12 -0
  144. data/spec/cc_api_stub/frameworks_spec.rb +19 -0
  145. data/spec/cc_api_stub/login_spec.rb +20 -0
  146. data/spec/cc_api_stub/organization_users_spec.rb +35 -0
  147. data/spec/cc_api_stub/organizations_spec.rb +118 -0
  148. data/spec/cc_api_stub/routes_spec.rb +19 -0
  149. data/spec/cc_api_stub/runtimes_spec.rb +19 -0
  150. data/spec/cc_api_stub/service_bindings_spec.rb +13 -0
  151. data/spec/cc_api_stub/service_instances_spec.rb +19 -0
  152. data/spec/cc_api_stub/services_spec.rb +11 -0
  153. data/spec/cc_api_stub/space_users_spec.rb +35 -0
  154. data/spec/cc_api_stub/spaces_spec.rb +38 -0
  155. data/spec/cc_api_stub/users_spec.rb +107 -0
  156. data/spec/cfoundry/auth_token_spec.rb +153 -0
  157. data/spec/cfoundry/baseclient_spec.rb +284 -0
  158. data/spec/cfoundry/client_spec.rb +13 -0
  159. data/spec/cfoundry/errors_spec.rb +117 -0
  160. data/spec/cfoundry/rest_client_spec.rb +367 -0
  161. data/spec/cfoundry/trace_helpers_spec.rb +91 -0
  162. data/spec/cfoundry/uaaclient_spec.rb +421 -0
  163. data/spec/cfoundry/upload_helpers_spec.rb +182 -0
  164. data/spec/cfoundry/v2/app_event_spec.rb +97 -0
  165. data/spec/cfoundry/v2/app_instance_spec.rb +31 -0
  166. data/spec/cfoundry/v2/app_spec.rb +354 -0
  167. data/spec/cfoundry/v2/app_usage_event_spec.rb +15 -0
  168. data/spec/cfoundry/v2/base_spec.rb +375 -0
  169. data/spec/cfoundry/v2/client_spec.rb +121 -0
  170. data/spec/cfoundry/v2/domain_spec.rb +63 -0
  171. data/spec/cfoundry/v2/event_spec.rb +15 -0
  172. data/spec/cfoundry/v2/managed_service_instance_spec.rb +149 -0
  173. data/spec/cfoundry/v2/model_magic/attribute_spec.rb +123 -0
  174. data/spec/cfoundry/v2/model_magic/has_summary_spec.rb +17 -0
  175. data/spec/cfoundry/v2/model_magic/to_many_spec.rb +53 -0
  176. data/spec/cfoundry/v2/model_magic/to_one_spec.rb +106 -0
  177. data/spec/cfoundry/v2/model_magic_spec.rb +43 -0
  178. data/spec/cfoundry/v2/model_spec.rb +472 -0
  179. data/spec/cfoundry/v2/organization_spec.rb +282 -0
  180. data/spec/cfoundry/v2/quota_definition_spec.rb +50 -0
  181. data/spec/cfoundry/v2/route_spec.rb +42 -0
  182. data/spec/cfoundry/v2/service_plan_spec.rb +53 -0
  183. data/spec/cfoundry/v2/service_spec.rb +58 -0
  184. data/spec/cfoundry/v2/space_spec.rb +160 -0
  185. data/spec/cfoundry/v2/user_provided_service_instance_spec.rb +57 -0
  186. data/spec/cfoundry/v2/user_spec.rb +206 -0
  187. data/spec/cfoundry/validator_spec.rb +94 -0
  188. data/spec/factories/app_events_factory.rb +7 -0
  189. data/spec/factories/app_usage_events_factory.rb +32 -0
  190. data/spec/factories/apps_factory.rb +11 -0
  191. data/spec/factories/clients_factory.rb +7 -0
  192. data/spec/factories/domains_factory.rb +10 -0
  193. data/spec/factories/events_factory.rb +50 -0
  194. data/spec/factories/organizations_factory.rb +12 -0
  195. data/spec/factories/quota_definitions_factory.rb +8 -0
  196. data/spec/factories/routes_factory.rb +10 -0
  197. data/spec/factories/service_instances_factory.rb +10 -0
  198. data/spec/factories/service_plans_factory.rb +10 -0
  199. data/spec/factories/services_factory.rb +10 -0
  200. data/spec/factories/spaces_factory.rb +10 -0
  201. data/spec/factories/user_provided_service_instances_factory.rb +10 -0
  202. data/spec/factories/users_factory.rb +10 -0
  203. data/spec/fixtures/apps/with_cfignore/.cfignore +4 -0
  204. data/spec/fixtures/apps/with_cfignore/.hidden_file +1 -0
  205. data/spec/fixtures/apps/with_cfignore/ambiguous_ignored +0 -0
  206. data/spec/fixtures/apps/with_cfignore/ignored_dir/file_in_ignored_dir.txt +1 -0
  207. data/spec/fixtures/apps/with_cfignore/ignored_file.txt +1 -0
  208. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/file_in_non_ignored_dir.txt +1 -0
  209. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/ignored_file.txt +1 -0
  210. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/toplevel_ignored.txt +0 -0
  211. data/spec/fixtures/apps/with_cfignore/non_ignored_file.txt +1 -0
  212. data/spec/fixtures/apps/with_cfignore/toplevel_ignored.txt +0 -0
  213. data/spec/fixtures/apps/with_dotfiles/.dotfile +1 -0
  214. data/spec/fixtures/apps/with_dotfiles/xyz +1 -0
  215. data/spec/fixtures/apps/with_external_symlink/foo +1 -0
  216. data/spec/fixtures/apps/with_ignored_external_symlink/.cfignore +1 -0
  217. data/spec/fixtures/apps/with_ignored_external_symlink/foo +1 -0
  218. data/spec/fixtures/apps/with_nested_directories/foo/bar/baz/fizz +0 -0
  219. data/spec/fixtures/apps/with_nested_directories/xyz +0 -0
  220. data/spec/fixtures/empty_file +0 -0
  221. data/spec/fixtures/fake_cc_app_usage_events.json +152 -0
  222. data/spec/fixtures/fake_cc_application.json +20 -0
  223. data/spec/fixtures/fake_cc_application_summary.json +56 -0
  224. data/spec/fixtures/fake_cc_created_application.json +11 -0
  225. data/spec/fixtures/fake_cc_created_domain.json +15 -0
  226. data/spec/fixtures/fake_cc_created_organization.json +11 -0
  227. data/spec/fixtures/fake_cc_created_route.json +13 -0
  228. data/spec/fixtures/fake_cc_created_service_instance.json +11 -0
  229. data/spec/fixtures/fake_cc_created_space.json +11 -0
  230. data/spec/fixtures/fake_cc_created_user.json +11 -0
  231. data/spec/fixtures/fake_cc_domain.json +55 -0
  232. data/spec/fixtures/fake_cc_domain_spaces.json +27 -0
  233. data/spec/fixtures/fake_cc_empty_search.json +7 -0
  234. data/spec/fixtures/fake_cc_events.json +419 -0
  235. data/spec/fixtures/fake_cc_frameworks.json +20 -0
  236. data/spec/fixtures/fake_cc_managed_service_instance.json +83 -0
  237. data/spec/fixtures/fake_cc_organization.json +161 -0
  238. data/spec/fixtures/fake_cc_organization_domains.json +59 -0
  239. data/spec/fixtures/fake_cc_organization_search.json +37 -0
  240. data/spec/fixtures/fake_cc_organization_spaces.json +99 -0
  241. data/spec/fixtures/fake_cc_organization_summary.json +20 -0
  242. data/spec/fixtures/fake_cc_organization_users.json +81 -0
  243. data/spec/fixtures/fake_cc_route.json +16 -0
  244. data/spec/fixtures/fake_cc_runtimes.json +20 -0
  245. data/spec/fixtures/fake_cc_service_binding.json +22 -0
  246. data/spec/fixtures/fake_cc_service_bindings.json +24 -0
  247. data/spec/fixtures/fake_cc_service_instance.json +83 -0
  248. data/spec/fixtures/fake_cc_service_instances.json +72 -0
  249. data/spec/fixtures/fake_cc_services.json +160 -0
  250. data/spec/fixtures/fake_cc_space.json +45 -0
  251. data/spec/fixtures/fake_cc_space_apps.json +49 -0
  252. data/spec/fixtures/fake_cc_space_summary.json +84 -0
  253. data/spec/fixtures/fake_cc_spaces.json +92 -0
  254. data/spec/fixtures/fake_cc_stats.json +29 -0
  255. data/spec/fixtures/fake_cc_user.json +139 -0
  256. data/spec/fixtures/fake_cc_user_organizations.json +92 -0
  257. data/spec/fixtures/fake_cc_user_provided_service_instance.json +51 -0
  258. data/spec/fixtures/fake_cc_user_with_managers.json +85 -0
  259. data/spec/integration/client_spec.rb +38 -0
  260. data/spec/spec_helper.rb +22 -0
  261. data/spec/support/factory_girl.rb +6 -0
  262. data/spec/support/shared_examples/cc_api_stub_request_examples.rb +79 -0
  263. data/spec/support/shared_examples/client_login_examples.rb +46 -0
  264. data/spec/support/shared_examples/model_summary_examples.rb +34 -0
  265. data/spec/support/test_model_builder.rb +10 -0
  266. data/vendor/errors/v1.yml +189 -0
  267. data/vendor/errors/v2.yml +845 -0
  268. metadata +712 -0
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ module CFoundry::V2
4
+ describe AppInstance do
5
+ let(:client) { double }
6
+ let(:guid) { 'a snowflake' }
7
+ let(:name) { 'test-app' }
8
+ let(:instance_json) {
9
+ {
10
+ :state => "RUNNING",
11
+ :since => 1383588787.1809542,
12
+ :debug_ip => nil,
13
+ :debug_port => nil,
14
+ :console_ip => nil,
15
+ :console_port => nil
16
+ }
17
+ }
18
+ describe '.for_app' do
19
+ before do
20
+ instances_json = {:"0" => instance_json}
21
+ client.stub_chain(:base, :instances).and_return instances_json
22
+ end
23
+
24
+ it 'returns instances' do
25
+ instances = AppInstance.for_app(name, guid, client)
26
+ expect(instances.count).to eq 1
27
+ expect(instances.first.inspect).to eq "#<App::Instance '#{name}' \#0>"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,354 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe App do
6
+ let(:client) { build(:client) }
7
+
8
+ subject { build(:app, :client => client, :name => 'foo-app') }
9
+
10
+ describe "#events" do
11
+ let(:events) { [build(:app_event)] }
12
+
13
+ it "has events" do
14
+ subject.events = events
15
+ expect(subject.events).to eq(events)
16
+ end
17
+
18
+ context "when an invalid value is assigned" do
19
+ it "raises a Mismatch exception" do
20
+ expect {
21
+ subject.events = [build(:organization)]
22
+ }.to raise_error(CFoundry::Mismatch)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "environment" do
28
+ let(:app) { build(:app, :env => {"FOO" => "1"}) }
29
+
30
+ it "returns a hash-like object" do
31
+ expect(app.env["FOO"]).to eq "1"
32
+ end
33
+
34
+ describe "converting keys and values to strings" do
35
+ let(:app) { build(:app, :env => {:FOO => 1}) }
36
+
37
+ it "converts keys and values to strings" do
38
+ expect(app.env.to_hash).to eq("FOO" => "1")
39
+ end
40
+ end
41
+
42
+ context "when changes are made to the hash-like object" do
43
+ it "reflects the changes in .env" do
44
+ expect {
45
+ app.env["BAR"] = "2"
46
+ }.to change { app.env.to_hash }.from("FOO" => "1").to("FOO" => "1", "BAR" => "2")
47
+ end
48
+ end
49
+
50
+ context "when the env is set to something else" do
51
+ it "reflects the changes in .env" do
52
+ expect {
53
+ app.env = {"BAR" => "2"}
54
+ }.to change { app.env.to_hash }.from("FOO" => "1").to("BAR" => "2")
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "#summarize!" do
60
+ let(:app) { build(:app) }
61
+
62
+ it "assigns :instances as #total_instances" do
63
+ allow(app).to receive(:summary) { {:instances => 4} }
64
+
65
+ app.summarize!
66
+
67
+ expect(app.total_instances).to eq(4)
68
+ end
69
+ end
70
+
71
+ shared_examples_for "something may stage the app" do
72
+ subject { build(:app, :client => client) }
73
+ let(:response) { {:body => '{ "foo": "bar" }'} }
74
+
75
+ before do
76
+ allow(client.base).to receive(:put).with("v2", "apps", subject.guid, anything) do
77
+ response
78
+ end
79
+ end
80
+
81
+ it "sends the PUT request" do
82
+ expect(client.base).to receive(:put).with(
83
+ "v2", "apps", subject.guid,
84
+ hash_including(
85
+ :return_response => true)) do
86
+ response
87
+ end
88
+
89
+ update
90
+ end
91
+
92
+ context "and a block is given" do
93
+ let(:response) do
94
+ { :headers => { "x-app-staging-log" => "http://app/staging/log" },
95
+ :body => "{}"
96
+ }
97
+ end
98
+
99
+ it "yields the URL for the logs" do
100
+ yielded_url = nil
101
+ update do |url|
102
+ yielded_url = url
103
+ end
104
+
105
+ expect(yielded_url).to eq "http://app/staging/log"
106
+ end
107
+
108
+ context "and no staging header is returned" do
109
+ let(:response) do
110
+ { :headers => {},
111
+ :body => "{}"
112
+ }
113
+ end
114
+
115
+ it "yields nil" do
116
+ yielded_url = :something
117
+ update do |url|
118
+ yielded_url = url
119
+ end
120
+
121
+ expect(yielded_url).to be_nil
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+ describe "#start!" do
128
+ it_should_behave_like "something may stage the app" do
129
+ def update(&blk)
130
+ subject.start!(&blk)
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "#restart!" do
136
+ it_should_behave_like "something may stage the app" do
137
+ def update(&blk)
138
+ subject.restart!(&blk)
139
+ end
140
+ end
141
+ end
142
+
143
+ describe "#update!" do
144
+ describe "changes" do
145
+ subject { build(:app, :client => client) }
146
+ let(:response) { {:body => {"foo" => "bar"}.to_json} }
147
+
148
+ before do
149
+ allow(client.base).to receive(:put).with("v2", "apps", subject.guid, anything) do
150
+ response
151
+ end
152
+ end
153
+
154
+ it "applies the changes from the response JSON" do
155
+ expect {
156
+ subject.update!
157
+ }.to change { subject.manifest }.to(:foo => "bar")
158
+ end
159
+ end
160
+
161
+ it_should_behave_like "something may stage the app" do
162
+ def update(&blk)
163
+ subject.update!(&blk)
164
+ end
165
+ end
166
+ end
167
+
168
+ describe "#stream_update_log" do
169
+ let(:base_url) { "http://example.com/log" }
170
+
171
+ def mock_log(url = anything)
172
+ expect(client).to receive(:stream_url).with(url) { |_, &blk|
173
+ blk.call(yield)
174
+ }.ordered
175
+ end
176
+
177
+ def stub_log(url = anything)
178
+ allow(client).to receive(:stream_url).with(url) do |_, blk|
179
+ blk.call(yield)
180
+ end.ordered
181
+ end
182
+
183
+ it "yields chunks from the response to the block" do
184
+ mock_log { "a" }
185
+ mock_log { "b" }
186
+ mock_log { raise CFoundry::NotFound }
187
+
188
+ chunks = []
189
+ subject.stream_update_log(base_url) do |chunk|
190
+ chunks << chunk
191
+ end
192
+
193
+ expect(chunks).to eq(%w(a b))
194
+ end
195
+
196
+ it "retries when the connection times out" do
197
+ mock_log { raise ::Timeout::Error }
198
+ mock_log { "a" }
199
+ mock_log { raise ::Timeout::Error }
200
+ mock_log { "b" }
201
+ mock_log { raise ::Timeout::Error }
202
+ mock_log { raise CFoundry::NotFound }
203
+
204
+ chunks = []
205
+ subject.stream_update_log(base_url) do |chunk|
206
+ chunks << chunk
207
+ end
208
+
209
+ expect(chunks).to eq(%w(a b))
210
+ end
211
+
212
+ it "tracks the offset to stream from" do
213
+ url = "#{base_url}&tail&tail_offset="
214
+
215
+ mock_log("#{url}0") { "a" }
216
+ mock_log("#{url}1") { raise ::Timeout::Error }
217
+ mock_log("#{url}1") { "b" }
218
+ mock_log("#{url}2") { raise CFoundry::NotFound }
219
+
220
+ chunks = []
221
+ subject.stream_update_log(base_url) do |chunk|
222
+ chunks << chunk
223
+ end
224
+
225
+ expect(chunks).to eq(%w(a b))
226
+ end
227
+
228
+ it "stops when the endpoint disappears" do
229
+ mock_log { "a" }
230
+ mock_log { "b" }
231
+ mock_log { raise CFoundry::NotFound }
232
+ stub_log { "c" }
233
+
234
+ chunks = []
235
+ subject.stream_update_log(base_url) do |chunk|
236
+ chunks << chunk
237
+ end
238
+
239
+ expect(chunks).to eq(%w(a b))
240
+ end
241
+ end
242
+
243
+ describe "delete!" do
244
+ it "defaults to recursive" do
245
+ expect(client.base).to receive(:delete).with("v2", :apps, subject.guid, {:params => {:recursive => true}})
246
+
247
+ subject.delete!
248
+ end
249
+ end
250
+
251
+ it "accepts and ignores an options hash" do
252
+ expect(client.base).to receive(:delete).with("v2", :apps, subject.guid, {:params => {:recursive => true}})
253
+
254
+ subject.delete!(:recursive => false)
255
+ end
256
+
257
+ describe "#health" do
258
+ describe "when staging failed for an app" do
259
+ it "returns 'STAGING FAILED' as state" do
260
+ allow(AppInstance).to receive(:for_app) { raise CFoundry::StagingError }
261
+ allow(subject).to receive(:state) { "STARTED" }
262
+
263
+ expect(subject.health).to eq("STAGING FAILED")
264
+ end
265
+ end
266
+ end
267
+
268
+ describe "#percent_running" do
269
+ before do
270
+ allow(subject).to receive(:state) { "STARTED" }
271
+ subject.total_instances = instances.count
272
+ allow(AppInstance).to receive(:for_app).with(subject.name, subject.guid, client) { instances }
273
+ end
274
+
275
+ let(:instances) do
276
+ (1..3).map { double(AppInstance, state: "RUNNING") }
277
+ end
278
+
279
+ it "returns the percent of instances running as an integer" do
280
+ expect(subject.percent_running).to eq(100)
281
+ end
282
+
283
+ context "when half the instances are running" do
284
+ let(:instances) { [double(AppInstance, state: "RUNNING"), double(AppInstance, state: "STOPPED")] }
285
+
286
+ it "returns 50" do
287
+ expect(subject.percent_running).to eq(50)
288
+ end
289
+ end
290
+
291
+ context "when staging has failed" do
292
+ before { allow(AppInstance).to receive(:for_app) { raise CFoundry::StagingError } }
293
+
294
+ it "returns 0" do
295
+ expect(subject.percent_running).to eq(0)
296
+ end
297
+ end
298
+ end
299
+
300
+ describe "#host" do
301
+ let(:route) { build(:route, :host => "my-host") }
302
+ let(:app) { build(:app) }
303
+
304
+ context "when at least one route exists" do
305
+ it "returns the host that the user has specified" do
306
+ allow(app).to receive(:routes).and_return([route])
307
+ expect(app.host).to eq("my-host")
308
+ end
309
+ end
310
+
311
+ context "when no routes exists" do
312
+ it "returns the host that the user has specified" do
313
+ allow(app).to receive(:routes).and_return([])
314
+ expect(app.host).to be_nil
315
+ end
316
+ end
317
+ end
318
+
319
+ describe "#domain" do
320
+ let(:domain) { build(:domain, :name => "my-domain") }
321
+ let(:route) { build(:route, :domain => domain) }
322
+ let(:app) { build(:app) }
323
+
324
+ context "when at least one route exists" do
325
+ it "returns the domain that the user has specified" do
326
+ allow(app).to receive(:routes).and_return([route])
327
+ expect(app.domain).to eq("my-domain")
328
+ end
329
+ end
330
+
331
+ context "when no routes exists" do
332
+ it "returns the domain that the user has specified" do
333
+ allow(app).to receive(:routes).and_return([])
334
+ expect(app.domain).to be_nil
335
+ end
336
+ end
337
+ end
338
+
339
+ describe "#uri" do
340
+ context "when there are one or more routes" do
341
+ let(:domain) { build(:domain, :name => "example.com") }
342
+ let(:route) { build(:route, :host => "my-host", :domain => domain) }
343
+ let(:other_route) { build(:route, :host => "other-host", :domain => domain) }
344
+ let(:app) { build(:app) }
345
+
346
+ it "return the first one" do
347
+ allow(app).to receive(:routes).and_return([route, other_route])
348
+ expect(app.uri).to eq("#{route.host}.#{route.domain.name}")
349
+ end
350
+ end
351
+ end
352
+ end
353
+ end
354
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe AppUsageEvent do
6
+ let(:app_usage_event) { build(:app_usage_event, state: 'STOPPED') }
7
+
8
+ describe "#state" do
9
+ it "returns the state" do
10
+ expect(app_usage_event.state).to eq('STOPPED')
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end