Skip to content

Commit 716a03c

Browse files
Merge pull request #54 from rossta/feat/configure-config-path
Adds ability to configure default config path
2 parents 872ef21 + 509caa8 commit 716a03c

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/litestream.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def initialize
3333
end
3434
end
3535

36-
mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key, :systemctl_command
36+
mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key, :systemctl_command,
37+
:config_path
3738

3839
class << self
3940
def verify!(database_path)
@@ -89,6 +90,10 @@ def systemctl_command
8990
@@systemctl_command || "systemctl status litestream"
9091
end
9192

93+
def config_path
94+
@@config_path || Rails.root.join("config", "litestream.yml")
95+
end
96+
9297
def replicate_process
9398
info = {}
9499
if !`which systemctl`.empty?

lib/litestream/commands.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def prepare(command, argv = {}, database = nil)
129129
ENV["LITESTREAM_SECRET_ACCESS_KEY"] ||= Litestream.replica_access_key
130130

131131
args = {
132-
"--config" => Rails.root.join("config", "litestream.yml").to_s
132+
"--config" => Litestream.config_path.to_s
133133
}.merge(argv.stringify_keys).to_a.flatten.compact
134134
cmd = [executable, command, *args, database].compact
135135
puts cmd.inspect if ENV["DEBUG"]

test/litestream/test_commands.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def teardown
1515
Litestream.replica_bucket = ENV["LITESTREAM_REPLICA_BUCKET"] = nil
1616
Litestream.replica_key_id = ENV["LITESTREAM_ACCESS_KEY_ID"] = nil
1717
Litestream.replica_access_key = ENV["LITESTREAM_SECRET_ACCESS_KEY"] = nil
18+
Litestream.config_path = nil
1819
end
1920

2021
class TestReplicateCommand < TestCommands
@@ -422,6 +423,22 @@ def test_databases_does_not_set_env_var_from_config_when_env_vars_already_set
422423
assert_equal "original_key", ENV["LITESTREAM_ACCESS_KEY_ID"]
423424
assert_equal "original_access", ENV["LITESTREAM_SECRET_ACCESS_KEY"]
424425
end
426+
427+
def test_databases_read_from_custom_configured_litestream_config_path
428+
Litestream.config_path = "dummy/config/litestream/production.yml"
429+
430+
stub = proc do |cmd, _async|
431+
_executable, _command, *argv = cmd
432+
433+
assert_equal 2, argv.size
434+
assert_equal "--config", argv[0]
435+
assert_match Regexp.new("dummy/config/litestream/production.yml"), argv[1]
436+
end
437+
438+
Litestream::Commands.stub :run, stub do
439+
Litestream::Commands.databases
440+
end
441+
end
425442
end
426443

427444
class TestGenerationsCommand < TestCommands

0 commit comments

Comments
 (0)