Allow customizing audit broadcast with env

When invoking the audit broadcast command, provide a few environment
variables so that people can customize the format of the message if they
want.

We currently provide `MRSK_PERFORMER`, `MRSK_ROLE`, `MRSK_DESTINATION` and
`MRSK_EVENT`.

Also adds the destination to the default message, which we continue to
send as the first argument as before.
This commit is contained in:
Kevin McConnell
2023-04-13 11:47:29 +01:00
parent bc8875e020
commit 828e56912e
4 changed files with 51 additions and 6 deletions

View File

@@ -31,9 +31,26 @@ class CommandsAuditorTest < ActiveSupport::TestCase
end
test "broadcast" do
assert_match \
/bin\/audit_broadcast '\[.*\] app removed container'/,
new_command.broadcast("app removed container").join(" ")
Mrsk::Commands::Auditor.any_instance.stubs(:performer).returns("bob")
@role = "web"
@destination = "staging"
assert_equal \
["bin/audit_broadcast", "'[bob] [web] [staging] app removed container'"],
new_command.broadcast("app removed container")
end
test "broadcast environment" do
Mrsk::Commands::Auditor.any_instance.stubs(:performer).returns("bob")
@role = "web"
@destination = "staging"
env = new_command.broadcast_environment("app removed container")
assert_equal "bob", env["MRSK_PERFORMER"]
assert_equal "web", env["MRSK_ROLE"]
assert_equal "staging", env["MRSK_DESTINATION"]
assert_equal "app removed container", env["MRSK_EVENT"]
end
private