summaryrefslogtreecommitdiff
path: root/smoketest
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-03-18 11:54:53 -0500
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-04-19 23:48:56 +0000
commite50eb3c942ce3a7951d7cadd8a73ed7d1dc99b33 (patch)
treeb726cd8820884d5970bd53c306647a23aaf91329 /smoketest
parent37c1ac4f2ce6d604cc0f7dcd096e7fe48e8cf5de (diff)
downloadvyos-1x-e50eb3c942ce3a7951d7cadd8a73ed7d1dc99b33.tar.gz
vyos-1x-e50eb3c942ce3a7951d7cadd8a73ed7d1dc99b33.zip
T5996: add smoketest to check translation of backslash character
(cherry picked from commit d2df08856ddc5a6132544d73e1beb3074a352508)
Diffstat (limited to 'smoketest')
-rwxr-xr-xsmoketest/scripts/cli/test_backslash_escape.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_backslash_escape.py b/smoketest/scripts/cli/test_backslash_escape.py
new file mode 100755
index 000000000..e94e9ab0a
--- /dev/null
+++ b/smoketest/scripts/cli/test_backslash_escape.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2024 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import unittest
+
+from base_vyostest_shim import VyOSUnitTestSHIM
+from vyos.configtree import ConfigTree
+
+base_path = ['interfaces', 'ethernet', 'eth0', 'description']
+
+cases_word = [r'fo\o', r'fo\\o', r'foço\o', r'foço\\o']
+# legacy CLI output quotes only if whitespace present; this is a notable
+# difference that confounds the translation legacy -> modern, hence
+# determines the regex used in function replace_backslash
+cases_phrase = [r'some fo\o', r'some fo\\o', r'some foço\o', r'some foço\\o']
+
+case_save_config = '/tmp/smoketest-case-save'
+
+class TestBackslashEscape(VyOSUnitTestSHIM.TestCase):
+ def test_backslash_escape_word(self):
+ for case in cases_word:
+ self.cli_set(base_path + [case])
+ self.cli_commit()
+ # save_config tests translation though subsystems:
+ # legacy output -> config -> configtree -> file
+ self._session.save_config(case_save_config)
+ # reload to configtree and confirm:
+ with open(case_save_config) as f:
+ config_string = f.read()
+ ct = ConfigTree(config_string)
+ res = ct.return_value(base_path)
+ self.assertEqual(case, res, msg=res)
+ print(f'description: {res}')
+ self.cli_delete(base_path)
+ self.cli_commit()
+
+ def test_backslash_escape_phrase(self):
+ for case in cases_phrase:
+ self.cli_set(base_path + [case])
+ self.cli_commit()
+ # save_config tests translation though subsystems:
+ # legacy output -> config -> configtree -> file
+ self._session.save_config(case_save_config)
+ # reload to configtree and confirm:
+ with open(case_save_config) as f:
+ config_string = f.read()
+ ct = ConfigTree(config_string)
+ res = ct.return_value(base_path)
+ self.assertEqual(case, res, msg=res)
+ print(f'description: {res}')
+ self.cli_delete(base_path)
+ self.cli_commit()
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)