Back to Repositories

Validating SSHKit Configuration Parameters in Kamal

This test suite validates SSHKit configuration settings in the Kamal deployment tool, focusing on connection pooling and concurrent execution parameters. The tests ensure proper initialization and customization of SSHKit’s operational parameters for deployment orchestration.

Test Coverage Overview

The test suite provides comprehensive coverage of SSHKit configuration parameters in Kamal.

Key areas tested include:
  • Maximum concurrent start operations validation
  • Connection pool idle timeout settings
  • Default configuration values verification
  • Custom configuration override functionality

Implementation Analysis

The testing approach employs Minitest’s ActiveSupport::TestCase framework with a setup method establishing baseline deployment configuration. Tests utilize assertion-based verification to confirm both default and custom SSHKit parameters, implementing a clear pattern of configuration override testing.

Technical implementation features:
  • Hash-based configuration management
  • Dynamic configuration updates via tap
  • Isolated test cases with setup/teardown

Technical Details

Testing tools and configuration:
  • Framework: Minitest
  • Test Helper Integration
  • ActiveSupport::TestCase implementation
  • Mock deployment configuration
  • SSHKit parameter validation

Best Practices Demonstrated

The test suite exemplifies strong testing practices through clear organization and thorough validation. Notable practices include:
  • Isolated test setup with mock data
  • Explicit assertion messages
  • Comprehensive default and override testing
  • Clean separation of concerns
  • DRY configuration handling

basecamp/kamal

test/configuration/sshkit_test.rb

            
require "test_helper"

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

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

  test "sshkit max concurrent starts" do
    assert_equal 30, @config.sshkit.max_concurrent_starts
    @config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "max_concurrent_starts" => 50 }) })
    assert_equal 50, @config.sshkit.max_concurrent_starts
  end

  test "sshkit pool idle timeout" do
    assert_equal 900, @config.sshkit.pool_idle_timeout
    @config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "pool_idle_timeout" => 600 }) })
    assert_equal 600, @config.sshkit.pool_idle_timeout
  end
end