Add an ACL yaml unit test, to cover get_acls() and get_by_name()

This commit is contained in:
Pim van Pelt
2023-01-16 09:42:22 +00:00
parent adf7c7eb24
commit f0da3abe6e
3 changed files with 44 additions and 1 deletions

View File

@ -17,7 +17,7 @@ import socket
import ipaddress
def get_aclx(yaml):
def get_acls(yaml):
"""Return a list of all acls."""
ret = []
if "acls" in yaml:

View File

@ -14,10 +14,30 @@
# -*- coding: utf-8 -*-
""" Unit tests for taps """
import unittest
import yaml
from . import acl
from .unittestyaml import UnitTestYaml
class TestACLMethods(unittest.TestCase):
def setUp(self):
with UnitTestYaml("test_acl.yaml") as f:
self.cfg = yaml.load(f, Loader=yaml.FullLoader)
def test_get_acls(self):
acllist = acl.get_acls(self.cfg)
self.assertIsInstance(acllist, list)
self.assertEqual(2, len(acllist))
def test_get_by_name(self):
aclname, _acl = acl.get_by_name(self.cfg, "deny-all")
self.assertIsNotNone(_acl)
self.assertEqual("deny-all", aclname)
aclname, _acl = acl.get_by_name(self.cfg, "acl-noexist")
self.assertIsNone(aclname)
self.assertIsNone(_acl)
def test_get_port_low_high(self):
lo, hi = acl.get_port_low_high(80)
self.assertEqual(80, lo)