diff --git a/lib/litestream.rb b/lib/litestream.rb index c73aa31..e70dabc 100644 --- a/lib/litestream.rb +++ b/lib/litestream.rb @@ -33,7 +33,8 @@ def initialize end end - mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key, :systemctl_command + mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key, :systemctl_command, + :config_path class << self def verify!(database_path) @@ -89,6 +90,10 @@ def systemctl_command @@systemctl_command || "systemctl status litestream" end + def config_path + @@config_path || Rails.root.join("config", "litestream.yml") + end + def replicate_process info = {} if !`which systemctl`.empty? diff --git a/lib/litestream/commands.rb b/lib/litestream/commands.rb index 8eed563..2e98ff1 100644 --- a/lib/litestream/commands.rb +++ b/lib/litestream/commands.rb @@ -129,7 +129,7 @@ def prepare(command, argv = {}, database = nil) ENV["LITESTREAM_SECRET_ACCESS_KEY"] ||= Litestream.replica_access_key args = { - "--config" => Rails.root.join("config", "litestream.yml").to_s + "--config" => Litestream.config_path.to_s }.merge(argv.stringify_keys).to_a.flatten.compact cmd = [executable, command, *args, database].compact puts cmd.inspect if ENV["DEBUG"] diff --git a/test/litestream/test_commands.rb b/test/litestream/test_commands.rb index bafaaf5..81cf99b 100644 --- a/test/litestream/test_commands.rb +++ b/test/litestream/test_commands.rb @@ -15,6 +15,7 @@ def teardown Litestream.replica_bucket = ENV["LITESTREAM_REPLICA_BUCKET"] = nil Litestream.replica_key_id = ENV["LITESTREAM_ACCESS_KEY_ID"] = nil Litestream.replica_access_key = ENV["LITESTREAM_SECRET_ACCESS_KEY"] = nil + Litestream.config_path = nil end class TestReplicateCommand < TestCommands @@ -422,6 +423,22 @@ def test_databases_does_not_set_env_var_from_config_when_env_vars_already_set assert_equal "original_key", ENV["LITESTREAM_ACCESS_KEY_ID"] assert_equal "original_access", ENV["LITESTREAM_SECRET_ACCESS_KEY"] end + + def test_databases_read_from_custom_configured_litestream_config_path + Litestream.config_path = "dummy/config/litestream/production.yml" + + stub = proc do |cmd, _async| + _executable, _command, *argv = cmd + + assert_equal 2, argv.size + assert_equal "--config", argv[0] + assert_match Regexp.new("dummy/config/litestream/production.yml"), argv[1] + end + + Litestream::Commands.stub :run, stub do + Litestream::Commands.databases + end + end end class TestGenerationsCommand < TestCommands