diff options
author | Benjamin Drung <bdrung@debian.org> | 2023-06-10 08:55:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-10 09:21:49 +0000 |
commit | 88837172f69eabc408ae3945d82e0270b8e07440 (patch) | |
tree | d6b7fa06694f45d25f54f6ea9ded93c981e51f6f /test/test-transport_id.py | |
parent | Initial commit. (diff) | |
download | nvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.tar.xz nvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.zip |
Adding upstream version 2.2.1.upstream/2.2.1
Signed-off-by: Benjamin Drung <bdrung@debian.org>
Diffstat (limited to 'test/test-transport_id.py')
-rwxr-xr-x | test/test-transport_id.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/test-transport_id.py b/test/test-transport_id.py new file mode 100755 index 0000000..36953dd --- /dev/null +++ b/test/test-transport_id.py @@ -0,0 +1,87 @@ +#!/usr/bin/python3 +import unittest +from staslib import trid + + +class Test(unittest.TestCase): + '''Unit test for class TRID''' + + TRANSPORT = 'tcp' + TRADDR = '10.10.10.10' + OTHER_TRADDR = '1.1.1.1' + SUBSYSNQN = 'nqn.1988-11.com.dell:SFSS:2:20220208134025e8' + TRSVCID = '8009' + HOST_TRADDR = '1.2.3.4' + HOST_IFACE = 'wlp0s20f3' + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.cid = { + 'transport': Test.TRANSPORT, + 'traddr': Test.TRADDR, + 'subsysnqn': Test.SUBSYSNQN, + 'trsvcid': Test.TRSVCID, + 'host-traddr': Test.HOST_TRADDR, + 'host-iface': Test.HOST_IFACE, + } + self.other_cid = { + 'transport': Test.TRANSPORT, + 'traddr': Test.OTHER_TRADDR, + 'subsysnqn': Test.SUBSYSNQN, + 'trsvcid': Test.TRSVCID, + 'host-traddr': Test.HOST_TRADDR, + 'host-iface': Test.HOST_IFACE, + } + + self.tid = trid.TID(self.cid) + self.other_tid = trid.TID(self.other_cid) + + def test_hash(self): + '''Check that a hash exists''' + self.assertIsInstance(self.tid._hash, int) + + def test_transport(self): + '''Check that transport is set''' + self.assertEqual(self.tid.transport, Test.TRANSPORT) + + def test_traddr(self): + '''Check that traddr is set''' + self.assertEqual(self.tid.traddr, Test.TRADDR) + + def test_trsvcid(self): + '''Check that trsvcid is set''' + self.assertEqual(self.tid.trsvcid, Test.TRSVCID) + + def test_host_traddr(self): + '''Check that host_traddr is set''' + self.assertEqual(self.tid.host_traddr, Test.HOST_TRADDR) + + def test_host_iface(self): + '''Check that host_iface is set''' + self.assertEqual(self.tid.host_iface, Test.HOST_IFACE) + + def test_subsysnqn(self): + '''Check that subsysnqn is set''' + self.assertEqual(self.tid.subsysnqn, Test.SUBSYSNQN) + + def test_as_dict(self): + '''Check that a TRID can be converted back to the original Dict it was created with''' + self.assertDictEqual(self.tid.as_dict(), self.cid) + + def test_str(self): + '''Check that a TRID can be represented as a string''' + self.assertTrue(str(self.tid).startswith(f'({Test.TRANSPORT},')) + + def test_eq(self): + '''Check that two TRID objects can be tested for equality''' + self.assertEqual(self.tid, trid.TID(self.cid)) + self.assertFalse(self.tid == 'blah') + + def test_ne(self): + '''Check that two TID objects can be tested for non-equality''' + self.assertNotEqual(self.tid, self.other_tid) + self.assertNotEqual(self.tid, 'hello') + + +if __name__ == '__main__': + unittest.main() |