cfoundry 0.5.1.rc2 → 0.5.1.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/lib/cc_api_stub.rb +17 -0
  2. data/lib/cc_api_stub/applications.rb +53 -0
  3. data/lib/cc_api_stub/domains.rb +16 -0
  4. data/lib/cc_api_stub/frameworks.rb +22 -0
  5. data/lib/cc_api_stub/helper.rb +131 -0
  6. data/lib/cc_api_stub/login.rb +21 -0
  7. data/lib/cc_api_stub/organization_users.rb +21 -0
  8. data/lib/cc_api_stub/organizations.rb +70 -0
  9. data/lib/cc_api_stub/routes.rb +26 -0
  10. data/lib/cc_api_stub/runtimes.rb +22 -0
  11. data/lib/cc_api_stub/service_bindings.rb +22 -0
  12. data/lib/cc_api_stub/service_instances.rb +22 -0
  13. data/lib/cc_api_stub/services.rb +25 -0
  14. data/lib/cc_api_stub/spaces.rb +49 -0
  15. data/lib/cc_api_stub/users.rb +84 -0
  16. data/lib/cfoundry/baseclient.rb +24 -0
  17. data/lib/cfoundry/errors.rb +16 -133
  18. data/lib/cfoundry/v1/app.rb +6 -2
  19. data/lib/cfoundry/v2/app.rb +16 -4
  20. data/lib/cfoundry/v2/base.rb +10 -11
  21. data/lib/cfoundry/v2/client.rb +4 -0
  22. data/lib/cfoundry/version.rb +1 -1
  23. data/spec/cc_api_stub/applications_spec.rb +69 -0
  24. data/spec/cc_api_stub/domains_spec.rb +19 -0
  25. data/spec/cc_api_stub/frameworks_spec.rb +19 -0
  26. data/spec/cc_api_stub/login_spec.rb +20 -0
  27. data/spec/cc_api_stub/organization_users_spec.rb +19 -0
  28. data/spec/cc_api_stub/organizations_spec.rb +103 -0
  29. data/spec/cc_api_stub/routes_spec.rb +19 -0
  30. data/spec/cc_api_stub/runtimes_spec.rb +19 -0
  31. data/spec/cc_api_stub/service_bindings_spec.rb +13 -0
  32. data/spec/cc_api_stub/service_instances_spec.rb +19 -0
  33. data/spec/cc_api_stub/services_spec.rb +12 -0
  34. data/spec/cc_api_stub/spaces_spec.rb +38 -0
  35. data/spec/cc_api_stub/users_spec.rb +107 -0
  36. data/spec/cfoundry/baseclient_spec.rb +42 -2
  37. data/spec/cfoundry/v2/app_spec.rb +95 -0
  38. data/spec/fixtures/fake_cc_application.json +24 -0
  39. data/spec/fixtures/fake_cc_application_summary.json +57 -0
  40. data/spec/fixtures/fake_cc_created_application.json +11 -0
  41. data/spec/fixtures/fake_cc_created_domain.json +10 -0
  42. data/spec/fixtures/fake_cc_created_organization.json +11 -0
  43. data/spec/fixtures/fake_cc_created_route.json +13 -0
  44. data/spec/fixtures/fake_cc_created_service_instance.json +11 -0
  45. data/spec/fixtures/fake_cc_created_space.json +11 -0
  46. data/spec/fixtures/fake_cc_created_user.json +11 -0
  47. data/spec/fixtures/fake_cc_empty_search.json +7 -0
  48. data/spec/fixtures/fake_cc_frameworks.json +20 -0
  49. data/spec/fixtures/fake_cc_organization.json +144 -0
  50. data/spec/fixtures/fake_cc_organization_domains.json +34 -0
  51. data/spec/fixtures/fake_cc_organization_search.json +37 -0
  52. data/spec/fixtures/fake_cc_organization_summary.json +19 -0
  53. data/spec/fixtures/fake_cc_organization_users.json +81 -0
  54. data/spec/fixtures/fake_cc_runtimes.json +20 -0
  55. data/spec/fixtures/fake_cc_service_binding.json +22 -0
  56. data/spec/fixtures/fake_cc_service_bindings.json +24 -0
  57. data/spec/fixtures/fake_cc_service_instance.json +81 -0
  58. data/spec/fixtures/fake_cc_service_instances.json +0 -0
  59. data/spec/fixtures/fake_cc_service_types.json +124 -0
  60. data/spec/fixtures/fake_cc_space.json +45 -0
  61. data/spec/fixtures/fake_cc_space_summary.json +86 -0
  62. data/spec/fixtures/fake_cc_stats.json +29 -0
  63. data/spec/fixtures/fake_cc_user.json +112 -0
  64. data/spec/fixtures/fake_cc_user_organizations.json +92 -0
  65. data/spec/fixtures/fake_cc_user_with_managers.json +85 -0
  66. data/spec/spec_helper.rb +3 -0
  67. data/spec/support/fake_helper.rb +0 -36
  68. data/spec/support/shared_examples/cc_api_stub_request_examples.rb +79 -0
  69. metadata +254 -144
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CFoundry::BaseClient do
4
- subject { CFoundry::BaseClient.new }
5
-
6
4
  describe "#request" do
7
5
  before do
8
6
  stub(subject).handle_response(anything, anything, anything)
@@ -182,4 +180,46 @@ describe CFoundry::BaseClient do
182
180
  end
183
181
  end
184
182
  end
183
+
184
+ describe "#stream_url" do
185
+ it "handles a chunked response by yielding chunks as they come in" do
186
+ stub_request(:get, "http://example.com/something").to_return(
187
+ :headers => { "Transfer-Encoding" => "chunked" },
188
+ :body => "result")
189
+
190
+ chunks = []
191
+ subject.stream_url("http://example.com/something") do |chunk|
192
+ chunks << chunk
193
+ end
194
+
195
+ expect(chunks).to eq(["result"])
196
+ end
197
+
198
+ it "raises NotFound if response is 404" do
199
+ stub_request(:get, "http://example.com/something").to_return(
200
+ :status => 404, :body => "result")
201
+
202
+ expect {
203
+ subject.stream_url("http://example.com/something")
204
+ }.to raise_error(CFoundry::NotFound, /result/)
205
+ end
206
+
207
+ it "raises NotFound if response is 403" do
208
+ stub_request(:get, "http://example.com/something").to_return(
209
+ :status => 403, :body => "result")
210
+
211
+ expect {
212
+ subject.stream_url("http://example.com/something")
213
+ }.to raise_error(CFoundry::Denied, /result/)
214
+ end
215
+
216
+ it "raises BadRespones if response is unexpected" do
217
+ stub_request(:get, "http://example.com/something").to_return(
218
+ :status => 344, :body => "result")
219
+
220
+ expect {
221
+ subject.stream_url("http://example.com/something")
222
+ }.to raise_error(CFoundry::BadResponse, /result/)
223
+ end
224
+ end
185
225
  end
@@ -46,4 +46,99 @@ describe CFoundry::V2::App do
46
46
  expect(app.total_instances).to eq(4)
47
47
  end
48
48
  end
49
+
50
+ shared_examples_for "something may stage the app" do
51
+ subject { fake :app, :client => client }
52
+ let(:response) { { :body => '{ "foo": "bar" }' } }
53
+
54
+ before do
55
+ stub(client.base).put("v2", "apps", subject.guid, anything) do
56
+ response
57
+ end
58
+ end
59
+
60
+ context "when asynchronous is true" do
61
+ it "sends the PUT request with &stage_async=true" do
62
+ mock(client.base).put(
63
+ "v2", "apps", subject.guid,
64
+ hash_including(
65
+ :params => { :stage_async => true },
66
+ :return_response => true )) do
67
+ response
68
+ end
69
+
70
+ update(true)
71
+ end
72
+
73
+ context "and a block is given" do
74
+ let(:response) do
75
+ { :headers => { "x-app-staging-log" => "http://app/staging/log" },
76
+ :body => "{}"
77
+ }
78
+ end
79
+
80
+ it "yields the URL for the logs" do
81
+ yielded_url = nil
82
+ update(true) do |url|
83
+ yielded_url = url
84
+ end
85
+
86
+ expect(yielded_url).to eq "http://app/staging/log"
87
+ end
88
+ end
89
+ end
90
+
91
+ context "when asynchronous is false" do
92
+ it "sends the PUT request with &stage_async=false" do
93
+ mock(client.base).put(
94
+ "v2", "apps", subject.guid,
95
+ hash_including(:params => { :stage_async => false})) do
96
+ response
97
+ end
98
+
99
+ update(false)
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "#start!" do
105
+ it_should_behave_like "something may stage the app" do
106
+ def update(async, &blk)
107
+ subject.start!(async, &blk)
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "#restart!" do
113
+ it_should_behave_like "something may stage the app" do
114
+ def update(async, &blk)
115
+ subject.restart!(async, &blk)
116
+ end
117
+ end
118
+ end
119
+
120
+ describe "#update!" do
121
+ describe "changes" do
122
+ subject { fake :app, :client => client }
123
+ let(:response) { { :body => '{ "foo": "bar" }' } }
124
+
125
+ before do
126
+ stub(client.base).put("v2", "apps", subject.guid, anything) do
127
+ response
128
+ end
129
+ end
130
+
131
+ it "applies the changes from the response JSON" do
132
+ expect {
133
+ subject.update!
134
+ }.to change { subject.manifest }.to(:foo => "bar")
135
+ end
136
+ end
137
+
138
+ it_should_behave_like "something may stage the app" do
139
+ def update(async, &blk)
140
+ subject.update!(async, &blk)
141
+ end
142
+ end
143
+ end
49
144
  end
@@ -0,0 +1,24 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "d336bafe-13dd-4efd-a425-1729f6191d91",
4
+ "url": "/v2/apps/d336bafe-13dd-4efd-a425-1729f6191d91",
5
+ "created_at": "2012-08-13 12:48:41 -0700",
6
+ "updated_at": "2012-08-13 12:55:10 -0700"
7
+ },
8
+ "entity": {
9
+ "name": "newapp",
10
+ "space_guid": "6eb251ee-1ddc-4947-b2b3-942c5fdf0742",
11
+ "framework_guid": "9cb7dfa5-7a90-4526-9458-c3380f67c505",
12
+ "runtime_guid": "3cbd5d44-932b-43c7-9654-1c69ebe597ce",
13
+ "environment_json": null,
14
+ "memory": 2048,
15
+ "instances": 1,
16
+ "file_descriptors": 100,
17
+ "disk_quota": 500,
18
+ "state": "STARTED",
19
+ "service_bindings_url": "/v2/service_bindings?q=app_guid:d336bafe-13dd-4efd-a425-1729f6191d91",
20
+ "space_url": "/v2/spaces/6eb251ee-1ddc-4947-b2b3-942c5fdf0742",
21
+ "runtime_url": "/v2/runtimes/3cbd5d44-932b-43c7-9654-1c69ebe597ce",
22
+ "framework_url": "/v2/frameworks/9cb7dfa5-7a90-4526-9458-c3380f67c505"
23
+ }
24
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "guid":"application-id-1",
3
+ "name":"application-name-1",
4
+ "state":"STARTED",
5
+ "memory":128,
6
+ "instances":1,
7
+ "routes":[
8
+ { "guid": "route-id",
9
+ "host": "host",
10
+ "domain": { "guid": "domain-id", "name": "app-domain.com", "owning_organization_guid": "organization-id"}
11
+ },
12
+ { "guid": "route-id-2",
13
+ "host": null,
14
+ "domain": { "guid": "domain-id", "name": "app-domain.com", "owning_organization_guid": "organization-id"}
15
+ },
16
+ { "guid": "route-id-3",
17
+ "host": "host-3",
18
+ "domain": { "guid": "domain-id-3", "name": "vcap.me", "owning_organization_guid": null}
19
+ }
20
+ ],
21
+ "framework":{
22
+ "guid":"framework-id-1",
23
+ "name":"Ruby on Rails",
24
+ "description":"Ruby on Rails 3.2"
25
+ },
26
+ "runtime":{
27
+ "guid":"runtime-id-1",
28
+ "name":"Ruby",
29
+ "description":"Ruby 1.9"
30
+ },
31
+ "running_instances":0,
32
+ "services":[{
33
+ "guid":"service-id-1",
34
+ "name":"service-name-1",
35
+ "service_plan": {
36
+ "guid":"service-plan-id-1",
37
+ "name":"300",
38
+ "service":{
39
+ "guid":"paid-postgresql-id-1",
40
+ "provider":"core",
41
+ "label":"postgresql",
42
+ "version":"9.0"
43
+ }
44
+ }
45
+ }],
46
+ "space_guid":"space-id-1",
47
+ "framework_guid":"framework-id-1",
48
+ "runtime_guid":"runtime-id-1",
49
+ "environment_json":{},
50
+ "file_descriptors":256,
51
+ "disk_quota":256,
52
+ "available_domains":[
53
+ {"guid":"domain-id", "name":"app-domain.com", "owning_organization_guid":"organization-id"},
54
+ {"guid":"domain-id-2", "name":"app-domain-2.com", "owning_organization_guid":"organization-id"},
55
+ {"guid":"domain-id-3", "name":"vcap.me", "owning_organization_guid":null}
56
+ ]
57
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "created-application-id-1",
4
+ "url": "/v2/apps/created-application-id-1",
5
+ "created_at": "2012-08-13 12:48:41 -0700",
6
+ "updated_at": "2012-08-13 12:55:10 -0700"
7
+ },
8
+ "entity": {
9
+
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "created-domain-id-1",
4
+ "url": "/v2/domains/created-domain-id-1",
5
+ "created_at": "2012-08-13 12:48:41 -0700",
6
+ "updated_at": "2012-08-13 12:55:10 -0700"
7
+ },
8
+ "entity": {
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "created-organization-id-1",
4
+ "url": "/v2/organizations/created-organization-id-1",
5
+ "created_at": "2012-08-13 12:48:41 -0700",
6
+ "updated_at": "2012-08-13 12:55:10 -0700"
7
+ },
8
+ "entity": {
9
+
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "created-route-id-1",
4
+ "url": "/v2/routes/created-route-id-1",
5
+ "created_at": "2012-08-13 12:48:41 -0700",
6
+ "updated_at": "2012-08-13 12:55:10 -0700"
7
+ },
8
+ "entity": {
9
+ "host": "host",
10
+ "domain_guid": "domain-id",
11
+ "space_guid": "space-id"
12
+ }
13
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "created-service-id-1",
4
+ "url": "/v2/routes/created-service-id-1",
5
+ "created_at": "2012-08-13 12:48:41 -0700",
6
+ "updated_at": "2012-08-13 12:55:10 -0700"
7
+ },
8
+ "entity": {
9
+
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "created-space-id-1",
4
+ "url": "/v2/spaces/created-space-id-1",
5
+ "created_at": "2012-08-13 12:48:41 -0700",
6
+ "updated_at": "2012-08-13 12:55:10 -0700"
7
+ },
8
+ "entity": {
9
+
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "user-id-1",
4
+ "url": "/v2/users/user-id-1",
5
+ "created_at": "2012-08-13 12:48:41 -0700",
6
+ "updated_at": "2012-08-13 12:55:10 -0700"
7
+ },
8
+ "entity": {
9
+
10
+ }
11
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "total_results": 0,
3
+ "total_pages": 0,
4
+ "prev_url": null,
5
+ "next_url": null,
6
+ "resources": []
7
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "total_results": 1,
3
+ "total_pages": 1,
4
+ "prev_url": null,
5
+ "next_url": null,
6
+ "resources": [{
7
+ "metadata": {
8
+ "guid": "rails3-framework-id-1",
9
+ "url": "/v2/frameworks/rails3-framework-id-1",
10
+ "created_at": "2012-11-21 14:24:19 -0800",
11
+ "updated_at": "2012-11-23 22:25:28 -0800"
12
+ },
13
+ "entity": {
14
+ "name": "rails3",
15
+ "description": "Rails 3.2",
16
+ "apps_url": "/v2/frameworks/rails3-framework-id-1/apps",
17
+ "apps": []
18
+ }
19
+ }]
20
+ }
@@ -0,0 +1,144 @@
1
+ {
2
+ "metadata": {
3
+ "guid": "organization-id-1",
4
+ "url": "/v2/organizations/organization-id-1",
5
+ "created_at": "2012-10-24 12:14:54 -0700",
6
+ "updated_at": null
7
+ },
8
+ "entity": {
9
+ "name": "organization-name-1",
10
+ "spaces_url": "/v2/organizations/organization-id-1/spaces",
11
+ "spaces": [
12
+ {
13
+ "metadata": {
14
+ "guid": "space-id-1",
15
+ "url": "/v2/spaces/space-id-1",
16
+ "created_at": "2012-10-24 12:16:11 -0700",
17
+ "updated_at": null
18
+ },
19
+ "entity": {
20
+ "name": "space-name-1",
21
+ "organization_guid": "organization-id-1",
22
+ "developers_url": "/v2/spaces/space-id-1/developers",
23
+ "managers_url": "/v2/spaces/space-id-1/managers",
24
+ "auditors_url": "/v2/spaces/space-id-1/auditors",
25
+ "apps_url": "/v2/spaces/space-id-1/apps",
26
+ "domains_url": "/v2/spaces/space-id-1/domains",
27
+ "service_instances_url": "/v2/spaces/space-id-1/service_instances",
28
+ "organization_url": "/v2/organizations/organization-id-1"
29
+ }
30
+ }
31
+ ],
32
+ "domains_url": "/v2/organizations/organization-id-1/domains",
33
+ "domains": [
34
+ {
35
+ "metadata": {
36
+ "guid": "domain-id-1",
37
+ "url": "/v2/domains/domain-id-1",
38
+ "created_at": "2012-10-24 12:14:00 -0700",
39
+ "updated_at": null
40
+ },
41
+ "entity": {
42
+ "name": "vcap.me",
43
+ "owning_organization_guid": null
44
+ }
45
+ }
46
+ ],
47
+ "users_url": "/v2/organizations/organization-id-1/users",
48
+ "users": [
49
+ {
50
+ "metadata": {
51
+ "guid": "user-id-1",
52
+ "url": "/v2/users/user-id-1",
53
+ "created_at": "2012-10-24 12:14:54 -0700",
54
+ "updated_at": "2012-10-24 12:16:11 -0700"
55
+ },
56
+ "entity": {
57
+ "admin": false,
58
+ "active": false,
59
+ "default_space_guid": "space-id-1",
60
+ "spaces_url": "/v2/users/user-id-1/spaces",
61
+ "organizations_url": "/v2/users/user-id-1/organizations",
62
+ "managed_organizations_url": "/v2/users/user-id-1/managed_organizations",
63
+ "billing_managed_organizations_url": "/v2/users/user-id-1/billing_managed_organizations",
64
+ "audited_organizations_url": "/v2/users/user-id-1/audited_organizations",
65
+ "managed_spaces_url": "/v2/users/user-id-1/managed_spaces",
66
+ "audited_spaces_url": "/v2/users/user-id-1/audited_spaces",
67
+ "default_space_url": "/v2/spaces/space-id-1"
68
+ }
69
+ }
70
+ ],
71
+ "managers_url": "/v2/organizations/organization-id-1/managers",
72
+ "managers": [
73
+ {
74
+ "metadata": {
75
+ "guid": "user-id-1",
76
+ "url": "/v2/users/user-id-1",
77
+ "created_at": "2012-10-24 12:14:54 -0700",
78
+ "updated_at": "2012-10-24 12:16:11 -0700"
79
+ },
80
+ "entity": {
81
+ "admin": false,
82
+ "active": false,
83
+ "default_space_guid": "space-id-1",
84
+ "spaces_url": "/v2/users/user-id-1/spaces",
85
+ "organizations_url": "/v2/users/user-id-1/organizations",
86
+ "managed_organizations_url": "/v2/users/user-id-1/managed_organizations",
87
+ "billing_managed_organizations_url": "/v2/users/user-id-1/billing_managed_organizations",
88
+ "audited_organizations_url": "/v2/users/user-id-1/audited_organizations",
89
+ "managed_spaces_url": "/v2/users/user-id-1/managed_spaces",
90
+ "audited_spaces_url": "/v2/users/user-id-1/audited_spaces",
91
+ "default_space_url": "/v2/spaces/space-id-1"
92
+ }
93
+ }
94
+ ],
95
+ "billing_managers_url": "/v2/organizations/organization-id-1/billing_managers",
96
+ "billing_managers": [
97
+ {
98
+ "metadata": {
99
+ "guid": "user-id-1",
100
+ "url": "/v2/users/user-id-1",
101
+ "created_at": "2012-10-24 12:14:54 -0700",
102
+ "updated_at": "2012-10-24 12:16:11 -0700"
103
+ },
104
+ "entity": {
105
+ "admin": false,
106
+ "active": false,
107
+ "default_space_guid": "space-id-1",
108
+ "spaces_url": "/v2/users/user-id-1/spaces",
109
+ "organizations_url": "/v2/users/user-id-1/organizations",
110
+ "managed_organizations_url": "/v2/users/user-id-1/managed_organizations",
111
+ "billing_managed_organizations_url": "/v2/users/user-id-1/billing_managed_organizations",
112
+ "audited_organizations_url": "/v2/users/user-id-1/audited_organizations",
113
+ "managed_spaces_url": "/v2/users/user-id-1/managed_spaces",
114
+ "audited_spaces_url": "/v2/users/user-id-1/audited_spaces",
115
+ "default_space_url": "/v2/spaces/space-id-1"
116
+ }
117
+ }
118
+ ],
119
+ "auditors_url": "/v2/organizations/organization-id-1/auditors",
120
+ "auditors": [
121
+ {
122
+ "metadata": {
123
+ "guid": "user-id-1",
124
+ "url": "/v2/users/user-id-1",
125
+ "created_at": "2012-10-24 12:14:54 -0700",
126
+ "updated_at": "2012-10-24 12:16:11 -0700"
127
+ },
128
+ "entity": {
129
+ "admin": false,
130
+ "active": false,
131
+ "default_space_guid": "space-id-1",
132
+ "spaces_url": "/v2/users/user-id-1/spaces",
133
+ "organizations_url": "/v2/users/user-id-1/organizations",
134
+ "managed_organizations_url": "/v2/users/user-id-1/managed_organizations",
135
+ "billing_managed_organizations_url": "/v2/users/user-id-1/billing_managed_organizations",
136
+ "audited_organizations_url": "/v2/users/user-id-1/audited_organizations",
137
+ "managed_spaces_url": "/v2/users/user-id-1/managed_spaces",
138
+ "audited_spaces_url": "/v2/users/user-id-1/audited_spaces",
139
+ "default_space_url": "/v2/spaces/space-id-1"
140
+ }
141
+ }
142
+ ]
143
+ }
144
+ }