summaryrefslogtreecommitdiff
path: root/glance_store/tests
diff options
context:
space:
mode:
authorwhoami-rajat <rajatdhasmana@gmail.com>2022-03-15 16:20:01 +0530
committerwhoami-rajat <rajatdhasmana@gmail.com>2022-03-22 14:18:23 +0530
commite5a3c9eefa83f173f12ee38804207e94bbdfa544 (patch)
tree6af001dae4503b612721394ff3acee555e495900 /glance_store/tests
parent77919e15d281e908de7b687e2af927b59d3dc8a8 (diff)
downloadglance_store-e5a3c9eefa83f173f12ee38804207e94bbdfa544.tar.gz
Add coverage for helper methods
Add coverage for helper methods like ``get_hash_str``, ``_get_mount_path`` and ``_get_host_ip``. Change-Id: Idb232f2d7b0f74e9c65e42955c767fb7bb6ae004
Diffstat (limited to 'glance_store/tests')
-rw-r--r--glance_store/tests/unit/test_cinder_base.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/glance_store/tests/unit/test_cinder_base.py b/glance_store/tests/unit/test_cinder_base.py
index 0fd8294..29bf5cc 100644
--- a/glance_store/tests/unit/test_cinder_base.py
+++ b/glance_store/tests/unit/test_cinder_base.py
@@ -577,3 +577,36 @@ class TestCinderStoreBase(object):
self.config(rootwrap_config=fake_rootwrap, group=group)
res = self.store.get_root_helper()
self.assertEqual(expected, res)
+
+ def test_get_hash_str(self):
+ test_str = 'test_str'
+ with mock.patch.object(cinder.hashlib, 'sha256') as fake_hashlib:
+ self.store.get_hash_str(test_str)
+ test_str = test_str.encode('utf-8')
+ fake_hashlib.assert_called_once_with(test_str)
+
+ def test__get_mount_path(self):
+ fake_hex = 'fake_hex_digest'
+ fake_share = 'fake_share'
+ fake_path = 'fake_mount_path'
+ expected_path = os.path.join(fake_path, fake_hex)
+ with mock.patch.object(self.store, 'get_hash_str') as fake_hash:
+ fake_hash.return_value = fake_hex
+ res = self.store._get_mount_path(fake_share, fake_path)
+ self.assertEqual(expected_path, res)
+
+ def test__get_host_ip_v6(self):
+ fake_ipv6 = '2001:0db8:85a3:0000:0000:8a2e:0370'
+ fake_socket_return = [[0, 1, 2, 3, [fake_ipv6]]]
+ with mock.patch.object(cinder.socket, 'getaddrinfo') as fake_socket:
+ fake_socket.return_value = fake_socket_return
+ res = self.store._get_host_ip('fake_host')
+ self.assertEqual(fake_ipv6, res)
+
+ def test__get_host_ip_v4(self):
+ fake_ip = '127.0.0.1'
+ fake_socket_return = [[0, 1, 2, 3, [fake_ip]]]
+ with mock.patch.object(cinder.socket, 'getaddrinfo') as fake_socket:
+ fake_socket.side_effect = [socket.gaierror, fake_socket_return]
+ res = self.store._get_host_ip('fake_host')
+ self.assertEqual(fake_ip, res)