add test_load_doc_from_json_file for unit test

Change-Id: I4afb36f7b87e5c2150ad8f675eeb397fd2b07b69
This commit is contained in:
gecong1973 2021-02-04 01:42:31 -08:00
parent f4bc498f04
commit 543eb4c26c
1 changed files with 10 additions and 0 deletions

View File

@ -60,6 +60,16 @@ class TestUtils(unittest.TestCase):
temp.close()
self.assertFalse(os.path.exists(temp.name))
@patch('oslo_serialization.jsonutils.load')
def test_load_doc_from_json_file(self, mock_load):
os.mknod("/tmp/test_freezer.conf")
mock_load.side_effect = Exception('error')
try:
utils.load_doc_from_json_file("/tmp/test_freezer.conf")
except Exception as e:
self.assertIn("Unable to load conf file", str(e))
os.remove("/tmp/test_freezer.conf")
def test_get_jobs_from_disk(self):
temp = tempfile.mkdtemp()
file = '/'.join([temp, "test.conf"])