Merge branch 'main' into global-logging-config
This commit is contained in:
@@ -3,6 +3,7 @@ require "test_helper"
|
||||
class ConfigurationTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
ENV["RAILS_MASTER_KEY"] = "456"
|
||||
ENV["VERSION"] = "missing"
|
||||
|
||||
@deploy = {
|
||||
service: "app", image: "dhh/app",
|
||||
@@ -22,17 +23,23 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
teardown do
|
||||
ENV["RAILS_MASTER_KEY"] = nil
|
||||
ENV.delete("RAILS_MASTER_KEY")
|
||||
ENV.delete("VERSION")
|
||||
end
|
||||
|
||||
test "ensure valid keys" do
|
||||
assert_raise(ArgumentError) do
|
||||
Mrsk::Configuration.new(@deploy.tap { _1.delete(:service) })
|
||||
Mrsk::Configuration.new(@deploy.tap { _1.delete(:image) })
|
||||
Mrsk::Configuration.new(@deploy.tap { _1.delete(:registry) })
|
||||
%i[ service image registry ].each do |key|
|
||||
test "#{key} config required" do
|
||||
assert_raise(ArgumentError) do
|
||||
Mrsk::Configuration.new @deploy.tap { _1.delete key }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Mrsk::Configuration.new(@deploy.tap { _1[:registry].delete("username") })
|
||||
Mrsk::Configuration.new(@deploy.tap { _1[:registry].delete("password") })
|
||||
%w[ username password ].each do |key|
|
||||
test "registry #{key} required" do
|
||||
assert_raise(ArgumentError) do
|
||||
Mrsk::Configuration.new @deploy.tap { _1[:registry].delete key }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,8 +74,20 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "version" do
|
||||
assert_equal "missing", @config.version
|
||||
assert_equal "123", Mrsk::Configuration.new(@deploy, version: "123").version
|
||||
ENV.delete("VERSION")
|
||||
|
||||
@config.expects(:system).with("git rev-parse").returns(nil)
|
||||
error = assert_raises(RuntimeError) { @config.version}
|
||||
assert_match /no git repository found/, error.message
|
||||
|
||||
@config.expects(:current_commit_hash).returns("git-version")
|
||||
assert_equal "git-version", @config.version
|
||||
|
||||
ENV["VERSION"] = "env-version"
|
||||
assert_equal "env-version", @config.version
|
||||
|
||||
@config.version = "arg-version"
|
||||
assert_equal "arg-version", @config.version
|
||||
end
|
||||
|
||||
test "repository" do
|
||||
@@ -135,6 +154,39 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
|
||||
test "valid config" do
|
||||
assert @config.valid?
|
||||
assert @config_with_roles.valid?
|
||||
end
|
||||
|
||||
test "hosts required for all roles" do
|
||||
# Empty server list for implied web role
|
||||
assert_raises(ArgumentError) do
|
||||
Mrsk::Configuration.new @deploy.merge(servers: [])
|
||||
end
|
||||
|
||||
# Empty server list
|
||||
assert_raises(ArgumentError) do
|
||||
Mrsk::Configuration.new @deploy.merge(servers: { "web" => [] })
|
||||
end
|
||||
|
||||
# Missing hosts key
|
||||
assert_raises(ArgumentError) do
|
||||
Mrsk::Configuration.new @deploy.merge(servers: { "web" => {} })
|
||||
end
|
||||
|
||||
# Empty hosts list
|
||||
assert_raises(ArgumentError) do
|
||||
Mrsk::Configuration.new @deploy.merge(servers: { "web" => { "hosts" => [] } })
|
||||
end
|
||||
|
||||
# Nil hosts
|
||||
assert_raises(ArgumentError) do
|
||||
Mrsk::Configuration.new @deploy.merge(servers: { "web" => { "hosts" => nil } })
|
||||
end
|
||||
|
||||
# One role with hosts, one without
|
||||
assert_raises(ArgumentError) do
|
||||
Mrsk::Configuration.new @deploy.merge(servers: { "web" => %w[ web ], "workers" => { "hosts" => %w[ ] } })
|
||||
end
|
||||
end
|
||||
|
||||
test "ssh options" do
|
||||
@@ -163,17 +215,17 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "erb evaluation of yml config" do
|
||||
config = Mrsk::Configuration.create_from Pathname.new(File.expand_path("fixtures/deploy.erb.yml", __dir__))
|
||||
config = Mrsk::Configuration.create_from config_file: Pathname.new(File.expand_path("fixtures/deploy.erb.yml", __dir__))
|
||||
assert_equal "my-user", config.registry["username"]
|
||||
end
|
||||
|
||||
test "destination yml config merge" do
|
||||
dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__))
|
||||
|
||||
config = Mrsk::Configuration.create_from dest_config_file, destination: "world"
|
||||
config = Mrsk::Configuration.create_from config_file: dest_config_file, destination: "world"
|
||||
assert_equal "1.1.1.1", config.all_hosts.first
|
||||
|
||||
config = Mrsk::Configuration.create_from dest_config_file, destination: "mars"
|
||||
config = Mrsk::Configuration.create_from config_file: dest_config_file, destination: "mars"
|
||||
assert_equal "1.1.1.3", config.all_hosts.first
|
||||
end
|
||||
|
||||
@@ -181,7 +233,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__))
|
||||
|
||||
assert_raises(RuntimeError) do
|
||||
config = Mrsk::Configuration.create_from dest_config_file, destination: "missing"
|
||||
config = Mrsk::Configuration.create_from config_file: dest_config_file, destination: "missing"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user