From 859319124611ea13c372a8f41a2beaaca5434190 Mon Sep 17 00:00:00 2001
From: Gleb Kashkin <g.kashkin@tarantool.org>
Date: Wed, 16 Aug 2023 11:15:26 +0000
Subject: [PATCH] test: add roundtrip() to interactive_tarantool

Sometimes it is useful to have one function to execute command,
read and compare response.
This patch introduces such function - `roundtrip()` to
interactive_tarantool helper.

NO_CHANGELOG=test helper change
NO_TEST=test helper change
NO_DOC=test helper change

(cherry picked from commit 5053f286f8c5fca49a5e3428df3cfbc570e448d2)
---
 test/interactive_tarantool.lua | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/test/interactive_tarantool.lua b/test/interactive_tarantool.lua
index 91cd9ec2b6..bf67654e0f 100644
--- a/test/interactive_tarantool.lua
+++ b/test/interactive_tarantool.lua
@@ -7,6 +7,7 @@ local log = require('log')
 local yaml = require('yaml')
 local popen = require('popen')
 local tnt = require('tarantool')
+local t = require('luatest')
 
 -- Default timeout for expecting an input on child's stdout.
 --
@@ -269,6 +270,15 @@ function mt.close(self)
     self.ph:close()
 end
 
+-- Run a command and assert response.
+function mt.roundtrip(self, command, expected)
+    self:execute_command(command)
+    local response = self:read_response()
+    if expected ~= nil then
+        t.assert_equals(response, expected)
+    end
+end
+
 -- }}} Instance methods
 
 -- {{{ Module functions
-- 
GitLab