Parcourir la source

[trac3867] Update PIDFile test code per review comments

Update the PIDFile test code to create the file for the
not writable test.

Add entry in ChangeLog
Shawn Routhier il y a 10 ans
Parent
commit
d93715fd48
2 fichiers modifiés avec 12 ajouts et 3 suppressions
  1. 5 0
      ChangeLog
  2. 7 3
      src/lib/util/tests/pid_file_unittest.cc

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+880.	[func]		sar
+	A utility class has been added which handles writing and
+	deleting pid files as well as checking if the process with
+	the given pid is running.
+
 879.	[bug]		fdupont
 879.	[bug]		fdupont
 	Drop DHCPREQUEST message from an unknown client in the
 	Drop DHCPREQUEST message from an unknown client in the
 	INIT-REBOOT state.
 	INIT-REBOOT state.

+ 7 - 3
src/lib/util/tests/pid_file_unittest.cc

@@ -23,7 +23,6 @@ using namespace isc::util;
 
 
 // Filenames used for testing.
 // Filenames used for testing.
 const char* TESTNAME = "pid_file.test";
 const char* TESTNAME = "pid_file.test";
-const char* TESTNAME2 = "pid_file.test.2";
 
 
 class PIDFileTest : public ::testing::Test {
 class PIDFileTest : public ::testing::Test {
 public:
 public:
@@ -66,7 +65,6 @@ private:
     /// @brief Removes any remaining test files
     /// @brief Removes any remaining test files
     void removeTestFile() const {
     void removeTestFile() const {
         remove(TESTNAME);
         remove(TESTNAME);
-        remove(TESTNAME2);
     }
     }
 
 
 };
 };
@@ -184,8 +182,14 @@ TEST_F(PIDFileTest, pidGarbage) {
 
 
 /// @brief Test failing to write a file.
 /// @brief Test failing to write a file.
 TEST_F(PIDFileTest, pidWriteFail) {
 TEST_F(PIDFileTest, pidWriteFail) {
-    PIDFile pid_file(absolutePath(TESTNAME2));
+    PIDFile pid_file(absolutePath(TESTNAME));
+
+    // Create the test file and change it's permission bits
+    // so we can't write to it.
+    pid_file.write(10);
+    chmod(absolutePath(TESTNAME).c_str(), S_IRUSR);
 
 
+    // Now try a write to the file, expecting an exception
     EXPECT_THROW(pid_file.write(10), PIDFileError);
     EXPECT_THROW(pid_file.write(10), PIDFileError);
 }
 }