Raise an error when either the filtered hosts or roles are empty.
Keeps us confusingly running things on the primary_host when nothing matches.
This commit is contained in:
@@ -28,11 +28,27 @@ class Kamal::Commander
|
|||||||
end
|
end
|
||||||
|
|
||||||
def specific_roles=(role_names)
|
def specific_roles=(role_names)
|
||||||
@specific_roles = Kamal::Utils.filter_specific_items(role_names, config.roles) if role_names.present?
|
if role_names.present?
|
||||||
|
@specific_roles = Kamal::Utils.filter_specific_items(role_names, config.roles)
|
||||||
|
|
||||||
|
if @specific_roles.empty?
|
||||||
|
raise ArgumentError, "No --roles match for #{role_names.join(',')}"
|
||||||
|
end
|
||||||
|
|
||||||
|
@specific_roles
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def specific_hosts=(hosts)
|
def specific_hosts=(hosts)
|
||||||
@specific_hosts = Kamal::Utils.filter_specific_items(hosts, config.all_hosts) if hosts.present?
|
if hosts.present?
|
||||||
|
@specific_hosts = Kamal::Utils.filter_specific_items(hosts, config.all_hosts)
|
||||||
|
|
||||||
|
if @specific_hosts.empty?
|
||||||
|
raise ArgumentError, "No --hosts match for #{hosts.join(',')}"
|
||||||
|
end
|
||||||
|
|
||||||
|
@specific_hosts
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def primary_host
|
def primary_host
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
@kamal.specific_hosts = [ "*" ]
|
@kamal.specific_hosts = [ "*" ]
|
||||||
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @kamal.hosts
|
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @kamal.hosts
|
||||||
|
|
||||||
@kamal.specific_hosts = [ "*miss" ]
|
exception = assert_raises(ArgumentError) do
|
||||||
assert_equal [], @kamal.hosts
|
@kamal.specific_hosts = [ "*miss" ]
|
||||||
|
end
|
||||||
|
assert_match /hosts match for \*miss/, exception.message
|
||||||
end
|
end
|
||||||
|
|
||||||
test "filtering hosts by filtering roles" do
|
test "filtering hosts by filtering roles" do
|
||||||
@@ -33,6 +35,11 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
@kamal.specific_roles = [ "web" ]
|
@kamal.specific_roles = [ "web" ]
|
||||||
assert_equal [ "1.1.1.1", "1.1.1.2" ], @kamal.hosts
|
assert_equal [ "1.1.1.1", "1.1.1.2" ], @kamal.hosts
|
||||||
|
|
||||||
|
exception = assert_raises(ArgumentError) do
|
||||||
|
@kamal.specific_roles = [ "*miss" ]
|
||||||
|
end
|
||||||
|
assert_match /roles match for \*miss/, exception.message
|
||||||
end
|
end
|
||||||
|
|
||||||
test "filtering roles" do
|
test "filtering roles" do
|
||||||
@@ -50,8 +57,10 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
@kamal.specific_roles = [ "*" ]
|
@kamal.specific_roles = [ "*" ]
|
||||||
assert_equal [ "web", "workers" ], @kamal.roles.map(&:name)
|
assert_equal [ "web", "workers" ], @kamal.roles.map(&:name)
|
||||||
|
|
||||||
@kamal.specific_roles = [ "*miss" ]
|
exception = assert_raises(ArgumentError) do
|
||||||
assert_equal [], @kamal.roles.map(&:name)
|
@kamal.specific_roles = [ "*miss" ]
|
||||||
|
end
|
||||||
|
assert_match /roles match for \*miss/, exception.message
|
||||||
end
|
end
|
||||||
|
|
||||||
test "filtering roles by filtering hosts" do
|
test "filtering roles by filtering hosts" do
|
||||||
|
|||||||
Reference in New Issue
Block a user