Created
June 16, 2014 20:12
A patch to bring test coverage of storage policies module to 100% from just running it's test module only.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 981b623a5f0f08a6840437fb0015dd668855ec95 Mon Sep 17 00:00:00 2001 | |
From: Peter Portante <peter.portante@redhat.com> | |
Date: Mon, 16 Jun 2014 16:07:20 -0400 | |
Subject: [PATCH] Bring storage policy module coverage to 100% | |
A simple set of additional tests to ensure coverage of the storage policy | |
module is 100% from just running it's module test. | |
Change-Id: Id5773438c297678bcfe53e959bc9eb132170d30b | |
--- | |
test/unit/common/test_storage_policy.py | 70 +++++++++++++++++++++++++++++++++ | |
1 file changed, 70 insertions(+) | |
diff --git a/test/unit/common/test_storage_policy.py b/test/unit/common/test_storage_policy.py | |
index 36d0c11..39f16b8 100644 | |
--- a/test/unit/common/test_storage_policy.py | |
+++ b/test/unit/common/test_storage_policy.py | |
@@ -63,6 +63,20 @@ class TestStoragePolicies(unittest.TestCase): | |
zero_policy_by_name = POLICIES.get_by_name(zero_policy.name) | |
self.assert_(zero_policy_by_name.idx == 0) | |
+ def test_storage_policy_collection_object(self): | |
+ test_policies = [StoragePolicy(0, 'aay', True), | |
+ StoragePolicy(1, 'bee', False), | |
+ StoragePolicy(2, 'cee', False)] | |
+ policies = StoragePolicyCollection(test_policies) | |
+ therepr = repr(policies) | |
+ self.assertEquals(therepr, | |
+ "StoragePolicyCollection([\n" | |
+ " StoragePolicy(0, 'aay', is_default=True," | |
+ " is_deprecated=False),\n" | |
+ " StoragePolicy(1, 'bee', is_default=False," | |
+ " is_deprecated=False),\n StoragePolicy(2," | |
+ " 'cee', is_default=False, is_deprecated=False)\n])") | |
+ | |
def test_validate_policies_defaults(self): | |
# 0 explicit default | |
test_policies = [StoragePolicy(0, 'zero', True), | |
@@ -374,7 +388,10 @@ class TestStoragePolicies(unittest.TestCase): | |
self.assertRaisesWithMessage(PolicyError, 'Invalid name', | |
parse_storage_policies, bad_conf) | |
+ # Additional section added to ensure parser ignores other sections | |
conf = self._conf(""" | |
+ [some-other-section] | |
+ foo = bar | |
[storage-policy:0] | |
name = zero | |
[storage-policy:5] | |
@@ -459,5 +476,58 @@ class TestStoragePolicies(unittest.TestCase): | |
p503 = test_policies[503] | |
self.assertTrue(501 < p503 < 507) | |
+ def test_get_object_ring(self): | |
+ test_policies = [StoragePolicy(0, 'aay', True), | |
+ StoragePolicy(1, 'bee', False), | |
+ StoragePolicy(2, 'cee', False)] | |
+ policies = StoragePolicyCollection(test_policies) | |
+ | |
+ class mock_policy_class(object): | |
+ | |
+ def __init__(self): | |
+ self.object_ring = None | |
+ self.swift_dir = '' | |
+ self._load_cnt = 0 | |
+ | |
+ def load_ring(self, swift_dir): | |
+ self.swift_dir = swift_dir | |
+ self._load_cnt += 1 | |
+ self.object_ring = 'loaded-%d' % self._load_cnt | |
+ | |
+ mock_policy = mock_policy_class() | |
+ | |
+ def mock_get_by_index(idx): | |
+ return mock_policy | |
+ | |
+ policies.get_by_index = mock_get_by_index | |
+ | |
+ retval = policies.get_object_ring(1, '/tmp') | |
+ self.assertEquals(retval, 'loaded-1') | |
+ | |
+ retval = policies.get_object_ring(1, '/tmp') | |
+ self.assertEquals(retval, 'loaded-1') | |
+ | |
+ def test_get_object_ring_bad_policy(self): | |
+ test_policies = [StoragePolicy(0, 'aay', True), | |
+ StoragePolicy(1, 'bee', False), | |
+ StoragePolicy(2, 'cee', False)] | |
+ policies = StoragePolicyCollection(test_policies) | |
+ self.assertRaises(PolicyError, policies.get_object_ring, 99, '/tmp') | |
+ | |
+ def test_storage_policy_singleton(self): | |
+ therepr = repr(POLICIES) | |
+ self.assertEquals(therepr, | |
+ "StoragePolicyCollection([\n" | |
+ " StoragePolicy(0, 'Policy-0', is_default=True," | |
+ " is_deprecated=False)\n])") | |
+ theval = POLICIES[0] | |
+ self.assertEquals(theval, 0) | |
+ for pol in POLICIES: | |
+ self.assertTrue(isinstance(pol, StoragePolicy)) | |
+ self.assertEquals(repr(pol), | |
+ "StoragePolicy(0, 'Policy-0'," | |
+ " is_default=True, is_deprecated=False)") | |
+ | |
+ | |
if __name__ == '__main__': | |
unittest.main() | |
-- | |
1.9.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment