Skip to content

Commit 45455c9

Browse files
committed
Add first integration test (routes log from logger to sink)
1 parent 1f4025d commit 45455c9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

script/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
if [ -z "$1" ]; then
44
nvim --headless --noplugin -u test/minimal-init.lua -c "PlenaryBustedDirectory test/unit { minimal_init = 'test/minimal-init.lua' }"
5+
nvim --headless --noplugin -u test/minimal-init.lua -c "PlenaryBustedDirectory test/integration { minimal_init = 'test/minimal-init.lua' }"
56
else
67
nvim --headless --noplugin -u test/minimal-init.lua -c "lua require('plenary.busted').run('$1')"
78
fi

test/integration/logger_spec.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
local log = require("structlog")
2+
3+
local stub = require("luassert.stub")
4+
local match = require("luassert.match")
5+
6+
describe("Log message", function()
7+
it("should be formatted with the added entries", function()
8+
local sink = log.sinks.Console({
9+
processors = { log.processors.Namer() },
10+
formatter = log.formatters.Format( --
11+
"[%s] %s: %s",
12+
{ "level", "logger_name", "msg" }
13+
),
14+
})
15+
stub(sink, "write")
16+
17+
local logger = log.Logger("test", log.level.TRACE, {
18+
sink,
19+
})
20+
logger.context = { context = "test" }
21+
22+
logger:info("message", { key = "value" })
23+
24+
assert.stub(sink.write).was_called_with(match.ref(sink), '[INFO] test: message context="test", key="value"')
25+
end)
26+
end)

0 commit comments

Comments
 (0)