瀏覽代碼

Add unit tests for the `cache.py` module

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 2 年之前
父節點
當前提交
fe0467c548
共有 1 個文件被更改,包括 31 次插入0 次删除
  1. 31 0
      coriolis/tests/test_cache.py

+ 31 - 0
coriolis/tests/test_cache.py

@@ -0,0 +1,31 @@
+# Copyright 2023 Cloudbase Solutions Srl
+# All Rights Reserved.
+
+from unittest import mock
+from coriolis import exception
+from coriolis import cache
+from coriolis.tests import test_base
+
+
+class CacheTestCase(test_base.CoriolisBaseTestCase):
+    """Collection of tests for the Coriolis cache package."""
+
+    @mock.patch.object(cache.cache, 'get_memoization_decorator')
+    def test_get_cache_decorator(self, mock_get_memoization_decorator):
+        provider = 'ValidProviderName'
+        result = cache.get_cache_decorator(provider)
+
+        self.assertEqual(result, mock_get_memoization_decorator.return_value)
+        mock_get_memoization_decorator.assert_called_once_with(
+            cache.CONF,
+            cache.cache_region,
+            provider
+        )
+
+    def test_get_cache_decorator_invalid_provider_name(self):
+        invalid_providers = [123, '', None]
+
+        for provider in invalid_providers:
+            self.assertRaises(exception.CoriolisException,
+                              cache.get_cache_decorator,
+                              provider)