Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/actions/route_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ module VCAP::CloudController
class RouteUpdate
def update(route:, message:)
Route.db.transaction do
route.options = route.options.symbolize_keys.merge(message.options).compact if message.requested?(:options)

if message.requested?(:options)
route.options = route.options.symbolize_keys.merge(message.options).compact
route.apps.each do |process|
Comment thread
philippthun marked this conversation as resolved.
Outdated
ProcessRouteHandler.new(process).notify_backend_of_route_update
end
end
route.save
MetadataUpdate.update(route, message)
end

route
end
end
Expand Down
42 changes: 39 additions & 3 deletions spec/unit/actions/route_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ module VCAP::CloudController
end

let(:message) { RouteUpdateMessage.new(body) }
let(:route) { Route.make }
Comment thread
philippthun marked this conversation as resolved.
let(:process) { ProcessModel.make }
let(:route_mapping) { RouteMappingModel.make(app: process.app) }
let(:route) { route_mapping.route }

subject { RouteUpdate.new }
describe '#update metadata' do
Comment thread
philippthun marked this conversation as resolved.
before do
expect(ProcessRouteHandler).not_to receive(:new)
end

context 'when the route has no existing metadata' do
context 'when no metadata is specified' do
let(:body) do
Expand Down Expand Up @@ -135,6 +141,13 @@ module VCAP::CloudController
end

describe '#update options' do
let(:fake_route_handler) { instance_double(ProcessRouteHandler) }

before do
allow(ProcessRouteHandler).to receive(:new).with(process).and_return(fake_route_handler)
allow(fake_route_handler).to receive(:notify_backend_of_route_update)
end

context 'when the route has no existing options' do
context 'when no options are specified' do
let(:body) do
Expand All @@ -147,6 +160,11 @@ module VCAP::CloudController
route.reload
expect(route.options).to eq({})
end

it 'does not notifies the backend' do
expect(fake_route_handler).not_to receive(:notify_backend_of_route_update)
subject.update(route:, message:)
end
end

context 'when an option is specified' do
Expand All @@ -161,10 +179,14 @@ module VCAP::CloudController
it 'adds the route option' do
expect(message).to be_valid
subject.update(route:, message:)

route.reload
expect(route[:options]).to eq('{"loadbalancing":"round-robin"}')
end

it 'notifies the backend' do
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
subject.update(route:, message:)
end
end
end

Expand All @@ -184,6 +206,11 @@ module VCAP::CloudController
route.reload
expect(route.options).to include({ 'loadbalancing' => 'round-robin' })
end

it 'does not notifies the backend' do
expect(fake_route_handler).not_to receive(:notify_backend_of_route_update)
subject.update(route:, message:)
end
end

context 'when an option is specified' do
Expand All @@ -199,9 +226,13 @@ module VCAP::CloudController
expect(message).to be_valid
subject.update(route:, message:)
route.reload

expect(route.options).to include({ 'loadbalancing' => 'least-connection' })
end

it 'notifies the backend' do
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
subject.update(route:, message:)
end
end

context 'when the option value is set to null' do
Expand All @@ -219,6 +250,11 @@ module VCAP::CloudController
route.reload
expect(route.options).to eq({})
end

it 'notifies the backend' do
expect(fake_route_handler).to receive(:notify_backend_of_route_update)
subject.update(route:, message:)
end
end
end
end
Expand Down