Skip to content

Commit b22d410

Browse files
committed
add unit test for apply-patch ipv6 regex
1 parent 4a2bc07 commit b22d410

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/ip_config_input/patch_ipv6.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"path": "/INTERFACE/Ethernet12|FC00::1~1126",
4+
"op": "remove"
5+
}
6+
]

tests/ip_config_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
import jsonpatch
13
import os
24
import traceback
35
from unittest import mock
@@ -8,6 +10,9 @@
810
import show.main as show
911
from utilities_common.db import Db
1012

13+
test_path = os.path.dirname(os.path.abspath(__file__))
14+
ip_config_input_path = os.path.join(test_path, "ip_config_input")
15+
1116
ERROR_MSG = "Error: IP address is not valid"
1217

1318
class TestConfigIP(object):
@@ -157,6 +162,22 @@ def test_add_del_interface_shortened_ipv6_with_leading_zeros(self):
157162
assert result.exit_code != 0
158163
assert ('Ethernet68', '3000::1/64') not in db.cfgdb.get_table('INTERFACE')
159164

165+
def test_remove_interface_case_sensitive_mock_ipv6_w_apply_patch(self):
166+
runner = CliRunner()
167+
any_patch_as_json = [{"op": "remove", "path": "/INTERFACE/Ethernet12|FC00::1~1126"}]
168+
any_patch = jsonpatch.JsonPatch(any_patch_as_json)
169+
any_patch_as_text = json.dumps(any_patch_as_json)
170+
ipv6_patch_file = os.path.join(ip_config_input_path, 'patch_ipv6.test')
171+
172+
# config apply-patch patch
173+
mock_generic_updater = mock.Mock()
174+
with mock.patch('config.main.GenericUpdater', return_value=mock_generic_updater):
175+
with mock.patch('builtins.open', mock.mock_open(read_data=any_patch_as_text)):
176+
result = runner.invoke(config.config.commands["apply-patch"], [ipv6_patch_file], catch_exceptions=False)
177+
print(result.exit_code, result.output)
178+
assert "converted ipv6 address to lowercase fc00::1~1126 with prefix /INTERFACE/Ethernet12| in value: /INTERFACE/Ethernet12|FC00::1~1126" in result.output
179+
180+
160181
@classmethod
161182
def teardown_class(cls):
162183
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)