From af99afa6f792c4b5c7351e1c52c2e438e10db9e2 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Thu, 24 Jul 2008 08:46:01 +0000 Subject: [PATCH] Add utils unittests for new functions The submitted WritePidFile, RemovePidfile and IsPidFileAlive functions miss unit tests. Adding a simple one which covers their basic functionality. Reviewed-by: iustinp --- test/ganeti.utils_unittest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py index e7b93c017..7a9c64f5c 100755 --- a/test/ganeti.utils_unittest.py +++ b/test/ganeti.utils_unittest.py @@ -32,6 +32,7 @@ import signal import socket import shutil import re +import tempfile import ganeti import testutils @@ -98,6 +99,24 @@ class TestIsProcessAlive(unittest.TestCase): self.assert_(not IsProcessAlive(self.pid_non_existing), "noexisting process detected") +class TestPidFileFunctions(unittest.TestCase): + """Tests for WritePidFile, RemovePidFile and IsPidFileAlive""" + + def setUp(self): + self.dir = tempfile.mkdtemp() + self.f_dpn = lambda name: os.path.join(self.dir, "%s.pid" % name) + utils._DaemonPidFileName = self.f_dpn + + def testPidFileFunctions(self): + utils.WritePidFile('test') + self.assert_(os.path.exists(self.f_dpn('test'))) + self.assert_(utils.IsPidFileAlive(self.f_dpn('test'))) + utils.RemovePidFile('test') + self.assert_(not os.path.exists(self.f_dpn('test'))) + + def tearDown(self): + os.rmdir(self.dir) + class TestRunCmd(unittest.TestCase): """Testing case for the RunCmd function""" -- GitLab