Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion app/actions/route_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ class RouteUpdate
def update(route:, message:)
Route.db.transaction do
route.options = route.options.symbolize_keys.merge(message.options).compact if message.requested?(:options)

route.save
MetadataUpdate.update(route, message)
end

if message.requested?(:options)
route.apps.each do |process|
ProcessRouteHandler.new(process).notify_backend_of_route_update
end
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