lua-ln/spec/ln_spec.lua

63 lines
2.2 KiB
Lua

local ln = require "ln"
describe("ln", function()
describe("exports", function()
it("has Logger", function()
assert.truthy(ln.Logger)
end)
it("has default_logger", function()
assert.truthy(ln.default_logger)
end)
it("has LogfmtFormatter", function()
assert.truthy(ln.LogfmtFormatter)
end)
it("has JSONFormatter", function()
assert.truthy(ln.JSONFormatter)
end)
it("has log", function()
assert.truthy(ln.log)
end)
it("has err", function()
assert.truthy(ln.err)
end)
end)
describe("default logger operations", function()
local lgr = ln.default_logger
it("can log", function()
lgr:log {foo = "bar"}
end)
it("can error", function()
lgr:err("vibe check failed", {foo = "bar"})
end)
it("takes multiple tables", function()
lgr:log({foo = "bar"}, {baz = "boz"})
end)
it("lets you override the formatter", function()
lgr.formatter = ln.JSONFormatter:new()
lgr:log {foo = "bar"}
end)
end)
describe("logfmt", function()
local fmtr = ln.LogfmtFormatter:new()
it("should return a non-nil message", function()
assert.truthy(fmtr:format({foo = "bar"}))
end)
it("should have spaces when the input does", function()
local msg = fmtr:format {foo = "bar with spaces"}
assert.truthy(string.find(msg, 'foo="bar with spaces"'))
end)
end)
end)