Back to Repositories

Validating SSH Configuration Options in Kamal Deployment Framework

This test suite validates SSH configuration options in the Kamal deployment tool, covering basic SSH settings, proxy configurations, and user authentication scenarios.

Test Coverage Overview

The test suite comprehensively covers SSH configuration functionality in Kamal deployments:

  • Default SSH user settings and overrides
  • Custom port configurations
  • Logging level customization
  • Proxy host configurations with and without user specifications

Implementation Analysis

The testing approach utilizes ActiveSupport::TestCase with a setup method establishing baseline deployment configurations. Each test case isolates specific SSH configuration aspects, using assertion methods to verify expected outcomes.

The implementation leverages Ruby’s hash manipulation capabilities to test configuration merging and overrides.

Technical Details

  • Testing Framework: Minitest with ActiveSupport
  • Configuration Format: Ruby Hash structures
  • Setup Requirements: Test helper integration
  • Key Components: Kamal::Configuration class, SSH options handling

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Isolated test setup using setup blocks
  • Clear test case naming conventions
  • Systematic verification of default and override scenarios
  • Comprehensive coverage of edge cases in proxy configurations

basecamp/kamal

test/configuration/ssh_test.rb

            
require "test_helper"

class ConfigurationSshTest < ActiveSupport::TestCase
  setup do
    @deploy = {
      service: "app", image: "dhh/app",
      registry: { "username" => "dhh", "password" => "secret" },
      builder: { "arch" => "amd64" },
      env: { "REDIS_URL" => "redis://x/y" },
      servers: [ "1.1.1.1", "1.1.1.2" ],
      volumes: [ "/local/path:/container/path" ]
    }

    @config = Kamal::Configuration.new(@deploy)
  end

  test "ssh options" do
    assert_equal "root", @config.ssh.options[:user]

    config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "user" => "app" }) })
    assert_equal "app", config.ssh.options[:user]
    assert_equal 4, config.ssh.options[:logger].level

    config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "log_level" => "debug" }) })
    assert_equal 0, config.ssh.options[:logger].level

    config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "port" => 2222 }) })
    assert_equal 2222, config.ssh.options[:port]
  end

  test "ssh options with proxy host" do
    config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) })
    assert_equal "[email protected]", config.ssh.options[:proxy].jump_proxies
  end

  test "ssh options with proxy host and user" do
    config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "[email protected]" }) })
    assert_equal "[email protected]", config.ssh.options[:proxy].jump_proxies
  end
end