From 7ddb122a221b2acb84c00debacf793b2c6a125a7 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Thu, 6 Jun 2024 13:12:44 +0100 Subject: [PATCH] Get tests passing --- test/cli/build_test.rb | 16 ++++++---------- test/cli/cli_test_case.rb | 5 ++--- test/cli/main_test.rb | 8 -------- test/commands/builder_test.rb | 14 +++++++------- test/configuration/builder_test.rb | 3 +-- 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/test/cli/build_test.rb b/test/cli/build_test.rb index 9158d0fe..4f05866c 100644 --- a/test/cli/build_test.rb +++ b/test/cli/build_test.rb @@ -21,10 +21,6 @@ class CliBuildTest < CliTestCase .with(:git, "-C", anything, :status, "--porcelain") .returns("") - SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) - .with(:docker, :buildx, :inspect, "kamal-local", "> /dev/null") - .returns("") - run_command("push", "--verbose").tap do |output| assert_hook_ran "pre-build", output, **hook_variables assert_match /Cloning repo into build directory/, output @@ -126,8 +122,8 @@ class CliBuildTest < CliTestCase SSHKit::Backend::Abstract.any_instance.expects(:execute) .with(:docker, :buildx, :create, "--name", "kamal-local", "--driver=docker-container") - SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) - .with(:docker, :buildx, :inspect, "kamal-local", "> /dev/null") + SSHKit::Backend::Abstract.any_instance.expects(:execute) + .with(:docker, :buildx, :inspect, "kamal-local") .raises(SSHKit::Command::Failed.new("no builder")) SSHKit::Backend::Abstract.any_instance.expects(:execute).with { |*args| args.first.start_with?("git") } @@ -214,16 +210,16 @@ class CliBuildTest < CliTestCase test "create remote" do run_command("create", fixture: :with_remote_builder).tap do |output| assert_match "Running /usr/bin/env true on 1.1.1.5", output - assert_match "docker context create kamal-remote-amd64 --description 'kamal-remote-amd64 host' --docker 'host=ssh://app@1.1.1.5'", output - assert_match "docker buildx create --name kamal-remote-amd64 kamal-remote-amd64 --platform linux/amd64", output + assert_match "docker context create kamal-remote-amd64-ssh---app-1-1-1-5 --description 'kamal-remote-amd64-ssh---app-1-1-1-5 host' --docker 'host=ssh://app@1.1.1.5'", output + assert_match "docker buildx create --name kamal-remote-amd64-ssh---app-1-1-1-5 kamal-remote-amd64-ssh---app-1-1-1-5 --platform linux/amd64", output end end test "create remote with custom ports" do run_command("create", fixture: :with_remote_builder_and_custom_ports).tap do |output| assert_match "Running /usr/bin/env true on 1.1.1.5", output - assert_match "docker context create kamal-remote-amd64 --description 'kamal-remote-amd64 host' --docker 'host=ssh://app@1.1.1.5:2122'", output - assert_match "docker buildx create --name kamal-remote-amd64 kamal-remote-amd64 --platform linux/amd64", output + assert_match "docker context create kamal-remote-amd64-ssh---app-1-1-1-5-2122 --description 'kamal-remote-amd64-ssh---app-1-1-1-5-2122 host' --docker 'host=ssh://app@1.1.1.5:2122'", output + assert_match "docker buildx create --name kamal-remote-amd64-ssh---app-1-1-1-5-2122 kamal-remote-amd64-ssh---app-1-1-1-5-2122 --platform linux/amd64", output end end diff --git a/test/cli/cli_test_case.rb b/test/cli/cli_test_case.rb index 231da3d0..5777bf57 100644 --- a/test/cli/cli_test_case.rb +++ b/test/cli/cli_test_case.rb @@ -36,9 +36,8 @@ class CliTestCase < ActiveSupport::TestCase .with { |arg1, arg2| arg1 == :mkdir && arg2 == ".kamal/locks/app" } SSHKit::Backend::Abstract.any_instance.stubs(:execute) .with { |arg1, arg2| arg1 == :rm && arg2 == ".kamal/locks/app/details" } - SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info) - .with { |*args| args[0..2] == [ :docker, :buildx, :inspect ] } - .returns("") + SSHKit::Backend::Abstract.any_instance.stubs(:execute) + .with(:docker, :buildx, :inspect, "kamal-local") end def assert_hook_ran(hook, output, version:, service_version:, hosts:, command:, subcommand: nil, runtime: false) diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index fd37e4f9..2b87191c 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -121,10 +121,6 @@ class CliMainTest < CliTestCase .with(:git, "-C", anything, :status, "--porcelain") .returns("") - SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) - .with(:docker, :buildx, :inspect, "kamal-local", "> /dev/null") - .returns("") - SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) .with(:docker, :info, "--format '{{index .RegistryConfig.Mirrors 0}}'") .returns("") @@ -159,10 +155,6 @@ class CliMainTest < CliTestCase .with(:git, "-C", anything, :status, "--porcelain") .returns("") - SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) - .with(:docker, :buildx, :inspect, "kamal-local", "> /dev/null") - .returns("") - SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) .with(:docker, :info, "--format '{{index .RegistryConfig.Mirrors 0}}'") .returns("") diff --git a/test/commands/builder_test.rb b/test/commands/builder_test.rb index f04e53b6..3fea77e7 100644 --- a/test/commands/builder_test.rb +++ b/test/commands/builder_test.rb @@ -30,10 +30,10 @@ class CommandsBuilderTest < ActiveSupport::TestCase end test "target multiarch remote when local and remote is set" do - builder = new_builder_command(builder: { "local" => {}, "remote" => {}, "cache" => { "type" => "gha" } }) - assert_equal "multiarch/remote", builder.name + builder = new_builder_command(builder: { "local" => { "arch" => "arm64" }, "remote" => { "arch" => "amd64", "host" => "ssh://app@127.0.0.1" }, "cache" => { "type" => "gha" } }) + assert_equal "hybrid", builder.name assert_equal \ - "docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", + "docker buildx build --push --platform linux/arm64,linux/amd64 --builder kamal-hybrid-arm64-amd64-ssh---app-127-0-0-1 -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", builder.push.join(" ") end @@ -46,10 +46,10 @@ class CommandsBuilderTest < ActiveSupport::TestCase end test "target native remote when only remote is set" do - builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } }) + builder = new_builder_command(builder: { "remote" => { "arch" => "amd64", "host" => "ssh://app@host" }, "cache" => { "type" => "gha" } }) assert_equal "remote", builder.name assert_equal \ - "docker buildx build --push --platform linux/amd64 --builder kamal-remote-amd64 -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", + "docker buildx build --push --platform linux/amd64 --builder kamal-remote-amd64-ssh---app-host -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", builder.push.join(" ") end @@ -152,9 +152,9 @@ class CommandsBuilderTest < ActiveSupport::TestCase end test "remote context build" do - builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "context" => "./foo" }) + builder = new_builder_command(builder: { "remote" => { "arch" => "amd64", "host" => "ssh://app@host" }, "context" => "./foo" }) assert_equal \ - "docker buildx build --push --platform linux/amd64 --builder kamal-remote-amd64 -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo", + "docker buildx build --push --platform linux/amd64 --builder kamal-remote-amd64-ssh---app-host -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo", builder.push.join(" ") end diff --git a/test/configuration/builder_test.rb b/test/configuration/builder_test.rb index 4b37b5e8..94acdacc 100644 --- a/test/configuration/builder_test.rb +++ b/test/configuration/builder_test.rb @@ -42,7 +42,7 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase test "setting both local and remote configs" do @deploy_with_builder_option[:builder] = { - "local" => { "arch" => "arm64", "host" => "unix:///Users/<%= `whoami`.strip %>/.docker/run/docker.sock" }, + "local" => { "arch" => "arm64" }, "remote" => { "arch" => "amd64", "host" => "ssh://root@192.168.0.1" } } @@ -53,7 +53,6 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase assert_equal "ssh://root@192.168.0.1", config_with_builder_option.builder.remote_host assert_equal "arm64", config_with_builder_option.builder.local_arch - assert_equal "unix:///Users/<%= `whoami`.strip %>/.docker/run/docker.sock", config_with_builder_option.builder.local_host end test "cached?" do