Skip to content

Commit f81a62a

Browse files
committed
update manfifest tests
1 parent 7d78f31 commit f81a62a

File tree

2 files changed

+82
-46
lines changed

2 files changed

+82
-46
lines changed

spec/request/space_manifests_spec.rb

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -699,58 +699,56 @@
699699
end
700700

701701
context 'when the loadbalancing-algorithm is supported' do
702-
context 'when a new route is added' do
703-
let(:yml_manifest) do
704-
{
705-
'applications' => [
706-
{ 'name' => app1_model.name,
707-
'routes' => [
708-
{ 'route' => "https://round-robin-app.#{shared_domain.name}",
709-
'options' => {
710-
'loadbalancing-algorithm' => 'round-robin'
711-
} }
712-
] }
713-
]
714-
}.to_yaml
715-
end
716-
717-
it 'adds and removes the loadbalancing-algorithm to the route' do
718-
post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header)
702+
let(:yml_manifest) do
703+
{
704+
'applications' => [
705+
{ 'name' => app1_model.name,
706+
'routes' => [
707+
{ 'route' => "https://round-robin-app.#{shared_domain.name}",
708+
'options' => {
709+
'loadbalancing-algorithm' => 'round-robin'
710+
} }
711+
] }
712+
]
713+
}.to_yaml
714+
end
719715

720-
expect(last_response.status).to eq(202)
721-
job_guid = VCAP::CloudController::PollableJobModel.last.guid
716+
it 'adds and updates the loadbalancing-algorithm' do
717+
post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header)
722718

723-
Delayed::Worker.new.work_off
724-
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
719+
expect(last_response.status).to eq(202)
720+
job_guid = VCAP::CloudController::PollableJobModel.last.guid
725721

726-
app1_model.reload
727-
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' })
728-
# expect(route.route_mappings_dataset.first(app: app1_model).protocol).to eq('http1')
729-
# expect(second_route.route_mappings_dataset.first(app: app1_model).protocol).to eq('http2')
722+
Delayed::Worker.new.work_off
723+
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
730724

731-
### remove the loadbalancing-algorithm from the route
725+
app1_model.reload
726+
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' })
732727

733-
yml_manifest = {
734-
'applications' => [
735-
{ 'name' => app1_model.name,
736-
'routes' => [
737-
{ 'route' => "https://round-robin-app.#{shared_domain.name}" }
738-
] }
739-
]
740-
}.to_yaml
728+
### update the loadbalancing-algorithm from the route
741729

742-
post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header)
730+
yml_manifest = {
731+
'applications' => [
732+
{ 'name' => app1_model.name,
733+
'routes' => [
734+
{ 'route' => "https://round-robin-app.#{shared_domain.name}",
735+
'options' => {
736+
'loadbalancing-algorithm' => 'least-connections'
737+
} }
738+
] }
739+
]
740+
}.to_yaml
743741

744-
expect(last_response.status).to eq(202)
745-
job_guid = VCAP::CloudController::PollableJobModel.last.guid
742+
post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header)
746743

747-
Delayed::Worker.new.work_off
748-
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
744+
expect(last_response.status).to eq(202)
745+
job_guid = VCAP::CloudController::PollableJobModel.last.guid
749746

750-
app1_model.reload
751-
expect(app1_model.routes.first.options).to eq({})
747+
Delayed::Worker.new.work_off
748+
expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error
752749

753-
end
750+
app1_model.reload
751+
expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'least-connections' })
754752

755753
end
756754
end

spec/unit/lib/cloud_controller/app_manifest/manifest_route_spec.rb

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ module VCAP::CloudController
5858
expect(manifest_route.valid?).to be(true)
5959
end
6060
end
61+
62+
context 'when there is a valid loadbalancing-algorithm' do
63+
let(:route) { 'http://example.com' }
64+
let(:options) { { 'loadbalancing-algorithm' => 'round-robin' } }
65+
66+
it 'is valid' do
67+
manifest_route = ManifestRoute.parse(route, options)
68+
expect(manifest_route.valid?).to be(true)
69+
end
70+
end
6171
end
6272

6373
describe 'invalid routes' do
@@ -106,6 +116,16 @@ module VCAP::CloudController
106116
expect(manifest_route.valid?).to be(false)
107117
end
108118
end
119+
120+
context 'when there is an invalid loadbalancing-algorithm' do
121+
let(:route) { 'http://example.com' }
122+
let(:options) { { 'loadbalancing-algorithm' => 'invalid' } }
123+
124+
it 'is invalid' do
125+
manifest_route = ManifestRoute.parse(route, options)
126+
expect(manifest_route.valid?).to be(false)
127+
end
128+
end
109129
end
110130
end
111131

@@ -119,7 +139,8 @@ module VCAP::CloudController
119139
{ host: 'host', domain: 'sub.some-domain.com' }
120140
],
121141
port: nil,
122-
path: '/path'
142+
path: '/path',
143+
options: nil
123144
})
124145
end
125146

@@ -131,7 +152,8 @@ module VCAP::CloudController
131152
{ host: '*', domain: 'sub.some-domain.com' }
132153
],
133154
port: nil,
134-
path: '/path'
155+
path: '/path',
156+
options: nil
135157
})
136158
end
137159

@@ -144,7 +166,8 @@ module VCAP::CloudController
144166
{ host: 'potato', domain: 'sub.some-domain.com' }
145167
],
146168
port: nil,
147-
path: '/path'
169+
path: '/path',
170+
options: nil
148171
})
149172
end
150173

@@ -157,7 +180,22 @@ module VCAP::CloudController
157180
{ host: 'potato', domain: 'sub.some-domain.com' }
158181
],
159182
port: 1234,
160-
path: ''
183+
path: '',
184+
options: nil
185+
})
186+
end
187+
188+
it 'parses a route with a loadbalancing-algorithm into route components' do
189+
route = ManifestRoute.parse('http://potato.sub.some-domain.com', { 'loadbalancing-algorithm': 'round-robin' })
190+
191+
expect(route.to_hash).to eq({
192+
candidate_host_domain_pairs: [
193+
{ host: '', domain: 'potato.sub.some-domain.com' },
194+
{ host: 'potato', domain: 'sub.some-domain.com' }
195+
],
196+
port: nil,
197+
path: '',
198+
options: { lb_algo: 'round-robin' }
161199
})
162200
end
163201
end

0 commit comments

Comments
 (0)