Skip to content

Commit

Permalink
including both mapped ports and exposed ports when determining ports …
Browse files Browse the repository at this point in the history
…and protocols for dependency links
  • Loading branch information
dharmamike committed Nov 7, 2014
1 parent aaf7930 commit 40e22d6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/models/service_sorter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ def set_link_port_and_protocol(service, dependency)
# Finds the explicitly exposed ports (:ports and :expose) on the dependency and
# creates a hash of the port and protocol for each
def ports_and_protocols_for(service)
return [] unless service.has_key?(:ports)
ports = []

ports = service[:ports].map do |exposed_port|
{ port: exposed_port[:hostPort], protocol: (exposed_port[:protocol] || 'tcp') }
if service[:ports]
mapped_ports = service[:ports].map do |exposed_port|
{ port: exposed_port[:hostPort], protocol: (exposed_port[:protocol] || 'tcp') }
end
ports.push(mapped_ports).flatten!
end

if service[:expose]
Expand Down
25 changes: 25 additions & 0 deletions spec/models/service_sorter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
it 'uses the lowest numbered exposed port as the link port' do
expect(subject.last[:links].first[:port]).to eq 80
end

it "uses 'tcp' as the link protocol" do
expect(subject.last[:links].first[:protocol]).to eq 'tcp'
end
Expand Down Expand Up @@ -92,4 +93,28 @@
expect(described_class.send(:get_service_names_for, links)).to contain_exactly("FOO", "BAZ")
end
end

describe '.ports_and_protocols_for' do
it 'responds with mapped ports when there are only mapped ports' do
service = { ports: [{ hostPort: 80, protocol: 'tcp' }] }
expect(described_class.send(:ports_and_protocols_for, service)).to match_array([{ port: 80, protocol: 'tcp' }])
end


it 'responds with exposed ports when there are only exposed ports' do
service = { expose: [80] }
expect(described_class.send(:ports_and_protocols_for, service)).to match_array([{ port: 80, protocol: 'tcp' }])
end

it 'combines mapped and exposed ports if there are both' do
service = { expose: [80], ports: [{ hostPort: 8080, protocol: 'tcp' }] }
expect(described_class.send(:ports_and_protocols_for, service)).to match_array([{ port: 80, protocol: 'tcp' },
{ port: 8080, protocol: 'tcp' }])
end

it 'returns an empty array if there no mapped or exposed ports' do
service = { expose: [], ports: [] }
expect(described_class.send(:ports_and_protocols_for, service)).to match_array([])
end
end
end

0 comments on commit 40e22d6

Please sign in to comment.