Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to configure default config path #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/litestream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/litestream/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
17 changes: 17 additions & 0 deletions test/litestream/test_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading