From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 918CA469711 for ; Fri, 5 Jun 2020 21:56:11 +0300 (MSK) Received: by mail-lj1-f178.google.com with SMTP id c11so13041585ljn.2 for ; Fri, 05 Jun 2020 11:56:11 -0700 (PDT) From: Cyrill Gorcunov Date: Fri, 5 Jun 2020 21:55:44 +0300 Message-Id: <20200605185544.54436-3-gorcunov@gmail.com> In-Reply-To: <20200605185544.54436-1-gorcunov@gmail.com> References: <20200605185544.54436-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v9 2/2] test: app-tap/logger -- test new modes List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Add tests for setting up logging via log module. Part-of #689 Signed-off-by: Cyrill Gorcunov --- 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