Remove proxy only if no apps are installed
This commit is contained in:
@@ -166,7 +166,7 @@ class CliAccessoryTest < CliTestCase
|
||||
Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_app_directory).with("mysql")
|
||||
|
||||
run_command("remove", "mysql", "-y")
|
||||
end
|
||||
@@ -175,11 +175,11 @@ class CliAccessoryTest < CliTestCase
|
||||
Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_app_directory).with("mysql")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:stop).with("redis")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("redis")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("redis")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("redis")
|
||||
Kamal::Cli::Accessory.any_instance.expects(:remove_app_directory).with("redis")
|
||||
|
||||
run_command("remove", "all", "-y")
|
||||
end
|
||||
@@ -192,8 +192,8 @@ class CliAccessoryTest < CliTestCase
|
||||
assert_match "docker image rm --force mysql", run_command("remove_image", "mysql")
|
||||
end
|
||||
|
||||
test "remove_service_directory" do
|
||||
assert_match "rm -rf app-mysql", run_command("remove_service_directory", "mysql")
|
||||
test "remove_app_directory" do
|
||||
assert_match "rm -rf app-mysql", run_command("remove_app_directory", "mysql")
|
||||
end
|
||||
|
||||
test "hosts param respected" do
|
||||
|
||||
@@ -98,11 +98,36 @@ class CliProxyTest < CliTestCase
|
||||
end
|
||||
|
||||
test "remove" do
|
||||
Kamal::Cli::Proxy.any_instance.expects(:stop)
|
||||
Kamal::Cli::Proxy.any_instance.expects(:remove_container)
|
||||
Kamal::Cli::Proxy.any_instance.expects(:remove_image)
|
||||
run_command("remove").tap do |output|
|
||||
assert_match "/usr/bin/env ls .kamal/apps | wc -l", output
|
||||
assert_match "docker container prune --force --filter label=org.opencontainers.image.title=kamal-proxy", output
|
||||
assert_match "docker image prune --all --force --filter label=org.opencontainers.image.title=kamal-proxy", output
|
||||
assert_match "/usr/bin/env rm -r .kamal/proxy", output
|
||||
end
|
||||
end
|
||||
|
||||
run_command("remove")
|
||||
test "remove with other apps" do
|
||||
Thread.report_on_exception = false
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info).with(:ls, ".kamal/apps", "|", :wc, "-l").returns("1\n").twice
|
||||
|
||||
run_command("remove").tap do |output|
|
||||
assert_match "Not removing the proxy, as other apps are installed, ignore this check with kamal proxy remove --force", output
|
||||
end
|
||||
ensure
|
||||
Thread.report_on_exception = true
|
||||
end
|
||||
|
||||
test "force remove with other apps" do
|
||||
Thread.report_on_exception = false
|
||||
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info).with(:ls, ".kamal/apps", "|", :wc, "-l").returns("1\n").twice
|
||||
|
||||
run_command("remove").tap do |output|
|
||||
assert_match "Not removing the proxy, as other apps are installed, ignore this check with kamal proxy remove --force", output
|
||||
end
|
||||
ensure
|
||||
Thread.report_on_exception = true
|
||||
end
|
||||
|
||||
test "remove_container" do
|
||||
@@ -117,6 +142,12 @@ class CliProxyTest < CliTestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "remove_host_directory" do
|
||||
run_command("remove_host_directory").tap do |output|
|
||||
assert_match "/usr/bin/env rm -r .kamal/proxy", output
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def run_command(*command, fixture: :with_proxy)
|
||||
stdouted { Kamal::Cli::Proxy.start([ *command, "-c", "test/fixtures/deploy_#{fixture}.yml" ]) }
|
||||
|
||||
@@ -9,7 +9,7 @@ class CommandsServerTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "ensure service directory" do
|
||||
assert_equal "mkdir -p .kamal/apps/app", new_command.ensure_service_directory.join(" ")
|
||||
assert_equal "mkdir -p .kamal/apps/app", new_command.ensure_app_directory.join(" ")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -49,5 +49,6 @@ class AppTest < IntegrationTest
|
||||
kamal :app, :remove
|
||||
|
||||
assert_app_is_down
|
||||
assert_app_directory_removed
|
||||
end
|
||||
end
|
||||
|
||||
@@ -148,4 +148,16 @@ class IntegrationTest < ActiveSupport::TestCase
|
||||
def container_running?(host:, name:)
|
||||
docker_compose("exec #{host} docker ps --filter=name=#{name} | tail -n+2", capture: true).strip.present?
|
||||
end
|
||||
|
||||
def assert_app_directory_removed
|
||||
assert_directory_removed("./kamal/apps/#{@app}")
|
||||
end
|
||||
|
||||
def assert_proxy_directory_removed
|
||||
assert_directory_removed("./kamal/proxy")
|
||||
end
|
||||
|
||||
def assert_directory_removed(directory)
|
||||
assert docker_compose("exec vm1 ls #{directory} | wc -l", capture: true).strip == "0"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -97,6 +97,8 @@ class MainTest < IntegrationTest
|
||||
|
||||
kamal :remove, "-y"
|
||||
assert_no_images_or_containers
|
||||
assert_app_directory_removed
|
||||
assert_proxy_directory_removed
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -48,6 +48,7 @@ class ProxyTest < IntegrationTest
|
||||
|
||||
kamal :proxy, :remove
|
||||
assert_proxy_not_running
|
||||
assert_proxy_directory_removed
|
||||
|
||||
kamal :env, :delete
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user