From 902919ca5b4accaa823c5be8ea0a6ccf8795cd65 Mon Sep 17 00:00:00 2001
From: Alexander Turenko <alexander.turenko@tarantool.org>
Date: Fri, 11 Aug 2023 17:59:25 +0300
Subject: [PATCH] test/config: fix helper to use w/o extra config options

A set of testing helpers was added in commit 06ca83c9320d ("test/config:
add several application script tests"). In particular, they allow to run
a tarantool instance with some default config file and write only
necessary config options in a test case.

In fact, if no options were set in the test, the config file was not
written. It is fixed in this commit and used in the next commit.

Part of #8862

NO_DOC=testing helper change
NO_CHANGELOG=see NO_DOC
---
 test/config-luatest/helpers.lua | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/test/config-luatest/helpers.lua b/test/config-luatest/helpers.lua
index 5b8972d1aa..e5c6af2493 100644
--- a/test/config-luatest/helpers.lua
+++ b/test/config-luatest/helpers.lua
@@ -102,15 +102,17 @@ local function prepare_case(g, opts)
         treegen.write_script(dir, 'main.lua', script)
     end
 
+    local config = simple_config
     if options ~= nil then
-        local config = table.deepcopy(simple_config)
+        config = table.deepcopy(simple_config)
         for path, value in pairs(options) do
             cluster_config:set(config, path, value)
         end
-        treegen.write_script(dir, 'config.yaml', yaml.encode(config))
     end
 
+    treegen.write_script(dir, 'config.yaml', yaml.encode(config))
     local config_file = fio.pathjoin(dir, 'config.yaml')
+
     local server = {
         config_file = config_file,
         chdir = dir,
@@ -198,6 +200,7 @@ end
 --   Verify test invariants after config:reload().
 local function reload_success_case(g, opts)
     local script_2 = assert(opts.script_2)
+    local options = assert(opts.options)
     local verify_2 = assert(opts.verify_2)
 
     local prepared = success_case(g, opts)
@@ -205,6 +208,7 @@ local function reload_success_case(g, opts)
     prepare_case(g, {
         dir = prepared.dir,
         script = script_2,
+        options = options,
     })
     g.server:exec(function()
         local config = require('config')
@@ -232,6 +236,7 @@ end
 --   An error that config:reload() must raise.
 local function reload_failure_case(g, opts)
     local script_2 = assert(opts.script_2)
+    local options = assert(opts.options)
     local exp_err = assert(opts.exp_err)
 
     local prepared = success_case(g, opts)
@@ -239,6 +244,7 @@ local function reload_failure_case(g, opts)
     prepare_case(g, {
         dir = prepared.dir,
         script = script_2,
+        options = options,
     })
     t.assert_error_msg_equals(exp_err, g.server.exec, g.server, function()
         local config = require('config')
-- 
GitLab