Skip to content

Commit

Permalink
add unit test for apply-patch ipv6 regex
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarashinvd committed Aug 8, 2022
1 parent 4a2bc07 commit 81c3c3a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/ip_config_input/ipv6_interfaces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"INTERFACE|Ethernet12|FC00::11/126":{
"NULL" : "NULL"
}
}
6 changes: 6 additions & 0 deletions tests/ip_config_input/patch_ipv6.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"path": "/INTERFACE/Ethernet12|FC00::1~1126",
"op": "remove"
}
]
19 changes: 19 additions & 0 deletions tests/ip_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import config.main as config
import show.main as show
from utilities_common.db import Db
from .mock_tables import dbconnector

test_path = os.path.dirname(os.path.abspath(__file__))
mock_db_path = os.path.join(test_path, "ip_config_input")

ERROR_MSG = "Error: IP address is not valid"

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

def test_remove_interface_case_sensitive_mock_ipv6_w_apply_patch(self):
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'ipv6_interfaces')
db = Db()
runner = CliRunner()

assert ('Ethernet12', 'FC00::11/126') in db.cfgdb.get_table('INTERFACE')

# config apply-patch patch
ipv6_patch_file = os.path.join(mock_db_path, 'patch_ipv6.test')
result = runner.invoke(config.config.commands["apply-patch"], [ipv6_patch_file], obj=db)
print(result.exit_code, result.output)
assert "converted ipv6 address to lowercase fc00::1~1126 with prefix /INTERFACE/Ethernet12| in value: /INTERFACE/Ethernet12|FC00::1~1126" in result.output


@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
dbconnector.dedicated_dbs['CONFIG_DB'] = None
print("TEARDOWN")

0 comments on commit 81c3c3a

Please sign in to comment.