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

Issue #36 Find_servers return [] if roles or hosts is nil or empty

This commit is contained in:
Bertrand Paquet 2011-05-19 20:44:00 +02:00
parent a47e18d452
commit 4a0f86de63
2 changed files with 14 additions and 0 deletions

View file

@ -39,6 +39,9 @@ module Capistrano
# # returns the given hosts, translated to ServerDefinition objects
# servers = find_servers :hosts => "jamis@example.host.com"
def find_servers(options={})
return [] if options.key?(:hosts) && (options[:hosts].nil? || options[:hosts] == [])
return [] if options.key?(:roles) && (options[:roles].nil? || options[:roles] == [])
hosts = server_list_from(ENV['HOSTS'] || options[:hosts])
if hosts.any?

View file

@ -155,4 +155,15 @@ class ConfigurationServersTest < Test::Unit::TestCase
assert_equal %w(app1 app2 app3), @config.find_servers(:roles => lambda { :app }).map { |s| s.host }.sort
assert_equal %w(app2 file), @config.find_servers(:roles => lambda { [:report, :file] }).map { |s| s.host }.sort
end
def test_find_servers_with_hosts_nil_or_empty
assert_equal [], @config.find_servers(:hosts => nil)
assert_equal [], @config.find_servers(:hosts => [])
end
def test_find_servers_with_rolees_nil_or_empty
assert_equal [], @config.find_servers(:roles => nil)
assert_equal [], @config.find_servers(:roles => [])
end
end