Skip to content

Commit

Permalink
Test accessory_hosts with roles and without filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Oct 3, 2024
1 parent 4f7ebd7 commit 7be2e7e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
21 changes: 21 additions & 0 deletions test/commander_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ class CommanderTest < ActiveSupport::TestCase
assert_equal [ "1.1.1.2" ], @kamal.proxy_hosts
end

test "accessory hosts without filtering" do
configure_with(:deploy_with_single_accessory)
assert_equal [ "1.1.1.5" ], @kamal.accessory_hosts

configure_with(:deploy_with_accessories)
assert_equal [ "1.1.1.5", "1.1.1.1", "1.1.1.2" ], @kamal.accessory_hosts
end

test "accessory hosts with role filtering" do
configure_with(:deploy_with_single_accessory)
@kamal.specific_roles = [ "web" ]
assert_equal [ ], @kamal.accessory_hosts

configure_with(:deploy_with_accessories)
@kamal.specific_roles = [ "web" ]
assert_equal [ "1.1.1.1", "1.1.1.2" ], @kamal.accessory_hosts

@kamal.specific_roles = [ "workers" ]
assert_equal [ ], @kamal.accessory_hosts
end

private
def configure_with(variant)
@kamal = Kamal::Commander.new.tap do |kamal|
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/deploy_with_accessories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ builder:
accessories:
mysql:
image: mysql:5.7
host: 1.1.1.3
host: 1.1.1.5
port: 3306
env:
clear:
Expand Down
29 changes: 29 additions & 0 deletions test/fixtures/deploy_with_single_accessory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
service: app
image: dhh/app
servers:
web:
- "1.1.1.1"
- "1.1.1.2"
workers:
- "1.1.1.3"
- "1.1.1.4"
registry:
username: user
password: pw
builder:
arch: amd64

accessories:
mysql:
image: mysql:5.7
host: 1.1.1.5
port: 3306
env:
clear:
MYSQL_ROOT_HOST: '%'
secret:
- MYSQL_ROOT_PASSWORD
files:
- test/fixtures/files/my.cnf:/etc/mysql/my.cnf
directories:
- data:/var/lib/mysql

0 comments on commit 7be2e7e

Please sign in to comment.