From b6a10df56aaff503edf5acb9389138ea39f60efe Mon Sep 17 00:00:00 2001 From: Igor Alexandrov Date: Tue, 1 Oct 2024 20:24:28 +0400 Subject: [PATCH] Added tests for network configuration option --- lib/kamal/configuration/docs/accessory.yml | 8 ++++++++ lib/kamal/configuration/docs/configuration.yml | 7 +++++++ lib/kamal/configuration/docs/proxy.yml | 7 +++++++ test/configuration/accessory_test.rb | 9 +++++++++ test/configuration/proxy_test.rb | 9 +++++++++ test/configuration_test.rb | 9 +++++++++ 6 files changed, 49 insertions(+) diff --git a/lib/kamal/configuration/docs/accessory.yml b/lib/kamal/configuration/docs/accessory.yml index 86d49b77..e77bf754 100644 --- a/lib/kamal/configuration/docs/accessory.yml +++ b/lib/kamal/configuration/docs/accessory.yml @@ -90,3 +90,11 @@ accessories: # They are not created or copied before mounting: volumes: - /path/to/mysql-logs:/var/log/mysql + + # Network + # + # The network the accessory will be attached to. + # + # Defaults to kamal: + network: custom + diff --git a/lib/kamal/configuration/docs/configuration.yml b/lib/kamal/configuration/docs/configuration.yml index 6b059346..b59394a3 100644 --- a/lib/kamal/configuration/docs/configuration.yml +++ b/lib/kamal/configuration/docs/configuration.yml @@ -176,3 +176,10 @@ logging: # Alias configuration, see kamal docs alias: aliases: ... + +# Network +# +# The network the application will be attached to. +# +# Defaults to kamal: +network: custom diff --git a/lib/kamal/configuration/docs/proxy.yml b/lib/kamal/configuration/docs/proxy.yml index 76ec3e41..0af14826 100644 --- a/lib/kamal/configuration/docs/proxy.yml +++ b/lib/kamal/configuration/docs/proxy.yml @@ -103,3 +103,10 @@ proxy: # By default, kamal-proxy will not forward the headers if the `ssl` option is set to `true`, and # will forward them if it is set to `false`. forward_headers: true + + # Network + # + # The network the proxy container will be attached to. + # + # Defaults to kamal: + network: custom diff --git a/test/configuration/accessory_test.rb b/test/configuration/accessory_test.rb index 2615dab6..f5220902 100644 --- a/test/configuration/accessory_test.rb +++ b/test/configuration/accessory_test.rb @@ -152,4 +152,13 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase test "options" do assert_equal [ "--cpus", "\"4\"", "--memory", "\"2GB\"" ], @config.accessory(:redis).option_args end + + test "network_args default" do + assert_equal [ "--network", "kamal" ], @config.accessory(:mysql).network_args + end + + test "network_args with configured options" do + @deploy[:accessories]["mysql"]["network"] = "database" + assert_equal [ "--network", "database" ], @config.accessory(:mysql).network_args + end end diff --git a/test/configuration/proxy_test.rb b/test/configuration/proxy_test.rb index 588e5a35..562c229f 100644 --- a/test/configuration/proxy_test.rb +++ b/test/configuration/proxy_test.rb @@ -38,6 +38,15 @@ class ConfigurationProxyTest < ActiveSupport::TestCase assert_not config.proxy.ssl? end + test "network_args defaults" do + assert_equal [ "--network", "kamal" ], config.proxy.network_args + end + + test "network_args with configured options" do + @deploy[:proxy] = { "network" => "example" } + assert_equal [ "--network", "example" ], config.proxy.network_args + end + private def config Kamal::Configuration.new(@deploy) diff --git a/test/configuration_test.rb b/test/configuration_test.rb index c1aaa697..da53ddb6 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -217,6 +217,15 @@ class ConfigurationTest < ActiveSupport::TestCase assert_equal [ "--log-driver", "\"local\"", "--log-opt", "max-size=\"100m\"", "--log-opt", "max-file=\"5\"" ], config.logging_args end + test "network_args default" do + assert_equal [ "--network", "kamal" ], @config.network_args + end + + test "network_args with configured options" do + config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(network: "custom") }) + assert_equal [ "--network", "custom" ], config.network_args + end + test "erb evaluation of yml config" do config = Kamal::Configuration.create_from config_file: Pathname.new(File.expand_path("fixtures/deploy.erb.yml", __dir__)) assert_equal "my-user", config.registry.username