Added unit test cases for container/auditor.py
Added unit test cases to cover all code path in _one_audit_pass function in container/auditor.py Change-Id: I8b89e94f1492e4366af3ac4260587e988ba29408
This commit is contained in:
parent
246e134275
commit
c4eeea7820
@ -20,6 +20,7 @@ import os
|
||||
import random
|
||||
from tempfile import mkdtemp
|
||||
from shutil import rmtree
|
||||
from eventlet import Timeout
|
||||
|
||||
from swift.common.utils import normalize_timestamp
|
||||
from swift.container import auditor
|
||||
@ -93,6 +94,12 @@ class TestAuditor(unittest.TestCase):
|
||||
self.assertEqual(test_auditor.container_failures, 2 * call_times)
|
||||
self.assertEqual(test_auditor.container_passes, 3 * call_times)
|
||||
|
||||
# now force timeout path code coverage
|
||||
with mock.patch('swift.container.auditor.ContainerAuditor.'
|
||||
'_one_audit_pass', side_effect=Timeout()):
|
||||
with mock.patch('swift.container.auditor.time', FakeTime()):
|
||||
self.assertRaises(ValueError, test_auditor.run_forever)
|
||||
|
||||
@mock.patch('swift.container.auditor.ContainerBroker', FakeContainerBroker)
|
||||
def test_run_once(self):
|
||||
conf = {}
|
||||
@ -108,6 +115,23 @@ class TestAuditor(unittest.TestCase):
|
||||
self.assertEqual(test_auditor.container_failures, 2)
|
||||
self.assertEqual(test_auditor.container_passes, 3)
|
||||
|
||||
@mock.patch('swift.container.auditor.ContainerBroker', FakeContainerBroker)
|
||||
def test_one_audit_pass(self):
|
||||
conf = {}
|
||||
test_auditor = auditor.ContainerAuditor(conf, logger=self.logger)
|
||||
|
||||
def fake_audit_location_generator(*args, **kwargs):
|
||||
files = sorted(os.listdir(self.testdir))
|
||||
return [(os.path.join(self.testdir, f), '', '') for f in files]
|
||||
|
||||
# force code coverage for logging path
|
||||
test_auditor.logging_interval = 0
|
||||
with mock.patch('swift.container.auditor.audit_location_generator',
|
||||
fake_audit_location_generator):
|
||||
test_auditor._one_audit_pass(test_auditor.logging_interval)
|
||||
self.assertEqual(test_auditor.container_failures, 1)
|
||||
self.assertEqual(test_auditor.container_passes, 3)
|
||||
|
||||
@mock.patch('swift.container.auditor.ContainerBroker', FakeContainerBroker)
|
||||
def test_container_auditor(self):
|
||||
conf = {}
|
||||
|
Loading…
Reference in New Issue
Block a user