Skip to content

Commit

Permalink
Include service name to lock details
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-alexandrov committed Jul 15, 2023
1 parent d03195c commit e6ca270
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/mrsk/commands/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def stat_lock_dir
end

def lock_dir
:mrsk_lock
"mrsk_lock-#{config.service}"
end

def lock_details_file
Expand Down
4 changes: 2 additions & 2 deletions test/cli/cli_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def fail_hook(hook)

def stub_locking
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |arg1, arg2| arg1 == :mkdir && arg2 == :mrsk_lock }
.with { |arg1, arg2| arg1 == :mkdir && arg2 == "mrsk_lock-app" }
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |arg1, arg2| arg1 == :rm && arg2 == "mrsk_lock/details" }
.with { |arg1, arg2| arg1 == :rm && arg2 == "mrsk_lock-app/details" }
end

def assert_hook_ran(hook, output, version:, service_version:, hosts:, command:, subcommand: nil, runtime: nil)
Expand Down
8 changes: 4 additions & 4 deletions test/cli/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class CliMainTest < CliTestCase
Thread.report_on_exception = false

SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |*arg| arg[0..1] == [:mkdir, :mrsk_lock] }
.raises(RuntimeError, "mkdir: cannot create directory ‘mrsk_lock’: File exists")
.with { |*arg| arg[0..1] == [:mkdir, 'mrsk_lock-app'] }
.raises(RuntimeError, "mkdir: cannot create directory ‘mrsk_lock-app’: File exists")

SSHKit::Backend::Abstract.any_instance.expects(:capture_with_debug)
.with(:stat, :mrsk_lock, ">", "/dev/null", "&&", :cat, "mrsk_lock/details", "|", :base64, "-d")
.with(:stat, 'mrsk_lock-app', ">", "/dev/null", "&&", :cat, "mrsk_lock-app/details", "|", :base64, "-d")

assert_raises(Mrsk::Cli::LockError) do
run_command("deploy")
Expand All @@ -78,7 +78,7 @@ class CliMainTest < CliTestCase
Thread.report_on_exception = false

SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |*arg| arg[0..1] == [:mkdir, :mrsk_lock] }
.with { |*arg| arg[0..1] == [:mkdir, 'mrsk_lock-app'] }
.raises(SocketError, "getaddrinfo: nodename nor servname provided, or not known")

assert_raises(SSHKit::Runner::ExecuteError) do
Expand Down
6 changes: 3 additions & 3 deletions test/commands/lock_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class CommandsLockTest < ActiveSupport::TestCase

test "status" do
assert_equal \
"stat mrsk_lock > /dev/null && cat mrsk_lock/details | base64 -d",
"stat mrsk_lock-app > /dev/null && cat mrsk_lock-app/details | base64 -d",
new_command.status.join(" ")
end

test "acquire" do
assert_match \
/mkdir mrsk_lock && echo ".*" > mrsk_lock\/details/m,
/mkdir mrsk_lock-app && echo ".*" > mrsk_lock-app\/details/m,
new_command.acquire("Hello", "123").join(" ")
end

test "release" do
assert_match \
"rm mrsk_lock/details && rm -r mrsk_lock",
"rm mrsk_lock-app/details && rm -r mrsk_lock-app",
new_command.release.join(" ")
end

Expand Down

0 comments on commit e6ca270

Please sign in to comment.