Skip to content

Commit 81c3c3a

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

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"INTERFACE|Ethernet12|FC00::11/126":{
3+
"NULL" : "NULL"
4+
}
5+
}

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import config.main as config
88
import show.main as show
99
from utilities_common.db import Db
10+
from .mock_tables import dbconnector
11+
12+
test_path = os.path.dirname(os.path.abspath(__file__))
13+
mock_db_path = os.path.join(test_path, "ip_config_input")
1014

1115
ERROR_MSG = "Error: IP address is not valid"
1216

@@ -157,7 +161,22 @@ def test_add_del_interface_shortened_ipv6_with_leading_zeros(self):
157161
assert result.exit_code != 0
158162
assert ('Ethernet68', '3000::1/64') not in db.cfgdb.get_table('INTERFACE')
159163

164+
def test_remove_interface_case_sensitive_mock_ipv6_w_apply_patch(self):
165+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'ipv6_interfaces')
166+
db = Db()
167+
runner = CliRunner()
168+
169+
assert ('Ethernet12', 'FC00::11/126') in db.cfgdb.get_table('INTERFACE')
170+
171+
# config apply-patch patch
172+
ipv6_patch_file = os.path.join(mock_db_path, 'patch_ipv6.test')
173+
result = runner.invoke(config.config.commands["apply-patch"], [ipv6_patch_file], obj=db)
174+
print(result.exit_code, result.output)
175+
assert "converted ipv6 address to lowercase fc00::1~1126 with prefix /INTERFACE/Ethernet12| in value: /INTERFACE/Ethernet12|FC00::1~1126" in result.output
176+
177+
160178
@classmethod
161179
def teardown_class(cls):
162180
os.environ['UTILITIES_UNIT_TESTING'] = "0"
181+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
163182
print("TEARDOWN")

0 commit comments

Comments
 (0)