Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Oct 24, 2024
1 parent a5fd7b3 commit a51d2e7
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
require "test_helper"

class AuditLogFormatterTest < ActiveSupport::TestCase
class JsonLogFormatterTest < ActiveSupport::TestCase
setup do
Thread.current[:request_id] = nil
end

test "#call formats logformatter inputs as json" do
t = Time.now
result = AuditLogFormatter.new.call("info", t, nil, "some message")
result = JsonLogFormatter.new.call("info", t, nil, "some message")
assert_equal %Q({"type":"info","time":"#{t}","request_id":null,"message":"some message"}\n), result
end

test "#call accepts and merges a Hash type for the message" do
t = Time.now
result = AuditLogFormatter.new.call("info", t, nil, { key: "some message", key2: "another" })
result = JsonLogFormatter.new.call("info", t, nil, { key: "some message", key2: "another" })
assert_equal %Q({"type":"info","time":"#{t}","request_id":null,"key":"some message","key2":"another"}\n), result
end

test "#call can render a thread local request_id" do
t = Time.now
req_id = SecureRandom.hex
Thread.stub :current, { request_id: req_id } do
result = AuditLogFormatter.new.call("info", t, nil, { key: "some message" })
result = JsonLogFormatter.new.call("info", t, nil, { key: "some message" })
assert_equal %Q({"type":"info","time":"#{t}","request_id":"#{req_id}","key":"some message"}\n), result
end
end
Expand Down

0 comments on commit a51d2e7

Please sign in to comment.