1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Match servers only on hostname not user and port

Servers must now be kept in an array and not a Set as user and port
are part of the hash value for an SSHKit Host. So changing them after
they're in a Set is not advised.

More role_properties tests
This commit is contained in:
Nick Townsend 2015-02-06 10:31:40 -08:00
parent f16dd121b8
commit 8125102ae6
3 changed files with 30 additions and 10 deletions

View file

@ -62,7 +62,7 @@ module Capistrano
end
def matches?(other)
user == other.user && hostname == other.hostname && port == other.port
hostname == other.hostname
end
private

View file

@ -8,7 +8,14 @@ module Capistrano
include Enumerable
def add_host(host, properties={})
servers.add server(host, properties).with(properties)
new_host = Server[host]
if server = servers.find { |s| s.matches? new_host }
server.user = new_host.user if new_host.user
server.port = new_host.port if new_host.port
server.with(properties)
else
servers << new_host.with(properties)
end
end
def add_role(role, hosts, options={})
@ -50,15 +57,8 @@ module Capistrano
private
def server(host, properties)
new_host = Server[host]
new_host.with({user: properties[:user]}) unless properties[:user].nil?
new_host.with({port: properties[:port]}) unless properties[:port].nil?
servers.find { |server| server.matches? new_host } || new_host
end
def servers
@servers ||= Set.new
@servers ||= []
end
def extract_options(array)

View file

@ -558,6 +558,26 @@ describe Capistrano::DSL do
recipient.doit(host, role, props)
end
end
it 'yields the merged properties for multiple roles' do
recipient = mock('recipient')
recipient.expects(:doit).with('example1.com', :redis, { port: 6379, type: :slave})
recipient.expects(:doit).with('example2.com', :redis, { port: 6379, type: :master})
recipient.expects(:doit).with('example1.com', :web, { port: 80 })
recipient.expects(:doit).with('example2.com', :web, { port: 81 })
dsl.role_properties(:redis, :web) do |host, role, props|
recipient.doit(host, role, props)
end
end
it 'honours a property filter before yielding' do
recipient = mock('recipient')
recipient.expects(:doit).with('example1.com', :redis, { port: 6379, type: :slave})
recipient.expects(:doit).with('example1.com', :web, { port: 80 })
dsl.role_properties(:redis, :web, select: :active) do |host, role, props|
recipient.doit(host, role, props)
end
end
end
end