summaryrefslogtreecommitdiff
path: root/tooz/tests
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@protonmail.com>2020-07-07 14:21:24 +0200
committerDmitry Tantsur <dtantsur@protonmail.com>2020-07-12 14:56:17 +0200
commitf5d32480d9cd76e33f3a88e00441bc39b2a55ff1 (patch)
tree3d0b8cd4e28a342a3b941c15149bd193563affc5 /tooz/tests
parent5ac72fcb3d2071d8fd4c382a48efe5b9dbd4dec9 (diff)
downloadtooz-f5d32480d9cd76e33f3a88e00441bc39b2a55ff1.tar.gz
hashring: allow choosing hash function
In FIPS mode it's not possible to use md5 for any purposes. Change-Id: Ia3d9035abb645e82083fe9a796d7d7df7cf4d7a7
Diffstat (limited to 'tooz/tests')
-rw-r--r--tooz/tests/test_hashring.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/tooz/tests/test_hashring.py b/tooz/tests/test_hashring.py
index eeb9edb..d44c1d1 100644
--- a/tooz/tests/test_hashring.py
+++ b/tooz/tests/test_hashring.py
@@ -31,7 +31,7 @@ class HashRingTestCase(testcase.TestCase):
# fake -> foo, bar, baz
# fake-again -> bar, baz, foo
- @mock.patch.object(hashlib, 'md5', autospec=True)
+ @mock.patch.object(hashlib, 'new', autospec=True)
def test_hash2int_returns_int(self, mock_md5):
r1 = 32 * 'a'
r2 = 32 * 'b'
@@ -45,12 +45,20 @@ class HashRingTestCase(testcase.TestCase):
self.assertIn(int(r1, 16), ring._ring)
self.assertIn(int(r2, 16), ring._ring)
+ mock_md5.assert_called_with('md5', mock.ANY)
+
def test_create_ring(self):
nodes = {'foo', 'bar'}
ring = hashring.HashRing(nodes)
self.assertEqual(nodes, set(ring.nodes.keys()))
self.assertEqual(2 ** 5 * 2, len(ring))
+ def test_wrong_hash_function(self):
+ nodes = {'foo', 'bar'}
+ self.assertRaisesRegex(ValueError, 'is not supported',
+ hashring.HashRing, nodes,
+ hash_function='fold twice and leave to dry')
+
def test_add_node(self):
nodes = {'foo', 'bar'}
ring = hashring.HashRing(nodes)