From 7be2e7e0bafd5cdf48508afdf33babbf73e5b1ea Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 2 Oct 2024 17:03:30 -0700 Subject: [PATCH] Test accessory_hosts with roles and without filtering --- test/commander_test.rb | 21 ++++++++++++++ test/fixtures/deploy_with_accessories.yml | 2 +- .../fixtures/deploy_with_single_accessory.yml | 29 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/deploy_with_single_accessory.yml diff --git a/test/commander_test.rb b/test/commander_test.rb index 54031e80..b6b61e16 100644 --- a/test/commander_test.rb +++ b/test/commander_test.rb @@ -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| diff --git a/test/fixtures/deploy_with_accessories.yml b/test/fixtures/deploy_with_accessories.yml index 29f502ec..e6c6825f 100644 --- a/test/fixtures/deploy_with_accessories.yml +++ b/test/fixtures/deploy_with_accessories.yml @@ -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: diff --git a/test/fixtures/deploy_with_single_accessory.yml b/test/fixtures/deploy_with_single_accessory.yml new file mode 100644 index 00000000..4af4a9e6 --- /dev/null +++ b/test/fixtures/deploy_with_single_accessory.yml @@ -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