diff options
author | John Estabrook <jestabro@vyos.io> | 2025-07-08 10:11:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-08 10:11:57 -0500 |
commit | 4b34c65d4129eede784d5747653bd81f8d40f299 (patch) | |
tree | 012976de08a49c6640c958b9b9c2fc6d7b836445 /src/tests/test_config_merge.py | |
parent | 2fa5d19d86c82f4519bd6aa05ba0c7d571172f3a (diff) | |
parent | 4d7a3a972a11ead1386ae2719b70dbfc2411831f (diff) | |
download | vyos-1x-4b34c65d4129eede784d5747653bd81f8d40f299.tar.gz vyos-1x-4b34c65d4129eede784d5747653bd81f8d40f299.zip |
Merge pull request #4574 from jestabro/merge-config
T7499: update config merge tools
Diffstat (limited to 'src/tests/test_config_merge.py')
-rw-r--r-- | src/tests/test_config_merge.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/tests/test_config_merge.py b/src/tests/test_config_merge.py new file mode 100644 index 000000000..c9b4ad5c8 --- /dev/null +++ b/src/tests/test_config_merge.py @@ -0,0 +1,50 @@ +# Copyright VyOS maintainers and contributors <maintainers@vyos.io> +# +# 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 vyos.configtree + +from unittest import TestCase + +class TestConfigDiff(TestCase): + def setUp(self): + with open('tests/data/config.left', 'r') as f: + config_string = f.read() + self.config_left = vyos.configtree.ConfigTree(config_string) + + with open('tests/data/config.right', 'r') as f: + config_string = f.read() + self.config_right = vyos.configtree.ConfigTree(config_string) + + def test_merge_destructive(self): + res = vyos.configtree.merge(self.config_left, self.config_right, + destructive=True) + right_value = self.config_right.return_value(['node1', 'tag_node', 'foo', 'single']) + merge_value = res.return_value(['node1', 'tag_node', 'foo', 'single']) + + # Check includes new value + self.assertEqual(right_value, merge_value) + + # Check preserves non-confliciting paths + self.assertTrue(res.exists(['node3'])) + + def test_merge_non_destructive(self): + res = vyos.configtree.merge(self.config_left, self.config_right) + left_value = self.config_left.return_value(['node1', 'tag_node', 'foo', 'single']) + merge_value = res.return_value(['node1', 'tag_node', 'foo', 'single']) + + # Check includes original value + self.assertEqual(left_value, merge_value) + + # Check preserves non-confliciting paths + self.assertTrue(res.exists(['node3'])) |