From: Cyrill Gorcunov <gorcunov@gmail.com> To: tml <tarantool-patches@dev.tarantool.org> Subject: [Tarantool-patches] [PATCH v9 2/2] test: app-tap/logger -- test new modes Date: Fri, 5 Jun 2020 21:55:44 +0300 [thread overview] Message-ID: <20200605185544.54436-3-gorcunov@gmail.com> (raw) In-Reply-To: <20200605185544.54436-1-gorcunov@gmail.com> Add tests for setting up logging via log module. Part-of #689 Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> --- test/app-tap/logger.test.lua | 83 +++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/test/app-tap/logger.test.lua b/test/app-tap/logger.test.lua index 222343908..c2f0ab5c0 100755 --- a/test/app-tap/logger.test.lua +++ b/test/app-tap/logger.test.lua @@ -1,13 +1,92 @@ #!/usr/bin/env tarantool local test = require('tap').test('log') -test:plan(25) +test:plan(54) -- gh-3946: Assertion failure when using log_format() before box.cfg() local log = require('log') log.log_format('plain') _, err = pcall(log.log_format, 'json') -test:ok(err:find("log_format: json can\'t be used") ~= nil) +test:ok(err:find("json can\'t be used") ~= nil) + +-- +-- gh-689: various settings change from box.cfg/log.cfg interfaces +-- +-- +local box2log_keys = { + ['log'] = 'log', + ['log_nonblock'] = 'nonblock', + ['log_level'] = 'level', + ['log_format'] = 'format', +} + +local function verify_keys(prefix) + for k, v in pairs(box2log_keys) do + local m = "%s: %s/%s (%s %s) are equal" + test:ok(box.cfg[k] == log.cfg[v], + m:format(prefix, k, v, + box.cfg[k], log.cfg[v])) + end +end + +-- Make sure the configuration defaults are fetched +-- correctly from log module +test:ok(log.cfg.log == nil, "log.cfg.log is nil") +test:ok(log.cfg.format == 'plain', "log.cfg.format is 'plain'") +test:ok(log.cfg.level == 5, "log.cfg.level is 5") +test:ok(log.cfg.nonblock == nil , "log.cfg.nonblock is nil") + +-- Configure logging from log module +local filename = "1.log" + +_, err = pcall(log.cfg, {log=filename, format='plain', level=6}) +test:ok(err == nil, "valid log.cfg call") +test:ok(log.cfg.log == filename, "log.cfg.log ok") +test:ok(log.cfg.format == 'plain', "log.cfg.format is ok") +test:ok(log.cfg.level == 6, "log.cfg.level is 6") + +-- switch to json mode +_, err = pcall(log.cfg, {format='json', level='verbose'}) +test:ok(err == nil, "switch to json") + +local message = "json message" +local json = require('json') +local file = io.open(filename) +while file:read() do +end + +log.verbose(message) +local line = file:read() +local s = json.decode(line) +test:ok(s['message'] == message, "message match") + +-- Now switch to box.cfg interface +box.cfg{ + log = filename, + log_level = 6, + memtx_memory = 107374182, +} +test:ok(box.cfg.log == filename, "filename match") +test:ok(box.cfg.log_level == 6, "loglevel match") +verify_keys("box.cfg") + +-- Now try to change a static field. +_, err = pcall(box.cfg, {log_level = 5, log = "2.txt"}) +test:ok(tostring(err):find("can\'t be set dynamically") ~= nil) +test:ok(box.cfg.log == filename, "filename match") +test:ok(box.cfg.log_level == 6, "loglevel match") +verify_keys("box.cfg static error") + +-- Change format and levels. +_, err = pcall(log.log_format, 'json') +test:ok(err == nil, "change to json") +_, err = pcall(log.level, 1) +test:ok(err == nil, "change log level") +verify_keys("log change json and level") + +-- Restore defaults +log.log_format('plain') +log.level(5) -- -- Check that Tarantool creates ADMIN session for #! script -- 2.26.2
next prev parent reply other threads:[~2020-06-05 18:56 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-05 18:55 [Tarantool-patches] [PATCH v9 0/2] lua/log: add an ability to setup logger without box.cfg{} Cyrill Gorcunov 2020-06-05 18:55 ` [Tarantool-patches] [PATCH v9 1/2] lua/log: add ability to configure logging early Cyrill Gorcunov 2020-06-05 18:55 ` Cyrill Gorcunov [this message] 2020-06-05 19:14 ` [Tarantool-patches] [PATCH v9 0/2] lua/log: add an ability to setup logger without box.cfg{} Oleg Babin 2020-06-05 19:21 ` Cyrill Gorcunov 2020-06-08 9:36 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200605185544.54436-3-gorcunov@gmail.com \ --to=gorcunov@gmail.com \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v9 2/2] test: app-tap/logger -- test new modes' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox