summaryrefslogtreecommitdiffstats
path: root/test/test-transport_id.py
blob: d0386ec520ac4ddc8360302188b02d758644ceb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/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'
    HOST_NQN = 'nqn.1988-11.com.dell:12345'

    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,
            'host-nqn': Test.HOST_NQN,
        }
        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,
            'host-nqn': Test.HOST_NQN,
        }

        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()