To avoid polluting the default SSH directory with lots of Kamal config, we'll default to putting them in a `kamal` sub directory. But also make the directory configurable with the `run_directory` key, so for example you can set it as `/var/run/kamal/` The directory is created during bootstrap or before any command that will need to access a file.
65 lines
1.7 KiB
Ruby
65 lines
1.7 KiB
Ruby
require "test_helper"
|
|
require "active_support/testing/time_helpers"
|
|
|
|
class CommandsAuditorTest < ActiveSupport::TestCase
|
|
include ActiveSupport::Testing::TimeHelpers
|
|
|
|
setup do
|
|
freeze_time
|
|
|
|
@config = {
|
|
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ]
|
|
}
|
|
|
|
@auditor = new_command
|
|
@performer = `whoami`.strip
|
|
@recorded_at = Time.now.utc.iso8601
|
|
end
|
|
|
|
test "record" do
|
|
assert_equal [
|
|
:echo,
|
|
"[#{@recorded_at}] [#{@performer}]",
|
|
"app removed container",
|
|
">>", "kamal/app-audit.log"
|
|
], @auditor.record("app removed container")
|
|
end
|
|
|
|
test "record with destination" do
|
|
new_command(destination: "staging").tap do |auditor|
|
|
assert_equal [
|
|
:echo,
|
|
"[#{@recorded_at}] [#{@performer}] [staging]",
|
|
"app removed container",
|
|
">>", "kamal/app-staging-audit.log"
|
|
], auditor.record("app removed container")
|
|
end
|
|
end
|
|
|
|
test "record with command details" do
|
|
new_command(role: "web").tap do |auditor|
|
|
assert_equal [
|
|
:echo,
|
|
"[#{@recorded_at}] [#{@performer}] [web]",
|
|
"app removed container",
|
|
">>", "kamal/app-audit.log"
|
|
], auditor.record("app removed container")
|
|
end
|
|
end
|
|
|
|
test "record with arg details" do
|
|
assert_equal [
|
|
:echo,
|
|
"[#{@recorded_at}] [#{@performer}] [value]",
|
|
"app removed container",
|
|
">>", "kamal/app-audit.log"
|
|
], @auditor.record("app removed container", detail: "value")
|
|
end
|
|
|
|
|
|
private
|
|
def new_command(destination: nil, **details)
|
|
Kamal::Commands::Auditor.new(Kamal::Configuration.new(@config, destination: destination, version: "123"), **details)
|
|
end
|
|
end
|