You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/03/02 08:55:48 UTC

[7/7] mesos git commit: Stout:[2/2] Added significant test coverage of `os::rmdir`.

Stout:[2/2] Added significant test coverage of `os::rmdir`.

Review: https://reviews.apache.org/r/43908/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c55ca294
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c55ca294
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c55ca294

Branch: refs/heads/master
Commit: c55ca2941b0119c13764bccdebcea46119e69e4e
Parents: fbe1f37
Author: Alex Clemmer <cl...@gmail.com>
Authored: Tue Mar 1 23:29:31 2016 -0800
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Tue Mar 1 23:55:26 2016 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/Makefile.am  |   1 +
 .../3rdparty/stout/tests/CMakeLists.txt         |   1 +
 .../stout/tests/os/filesystem_tests.cpp         |   2 +-
 .../3rdparty/stout/tests/os/rmdir_tests.cpp     | 173 +++++++++++++++++++
 .../3rdparty/stout/tests/os_tests.cpp           | 103 -----------
 5 files changed, 176 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c55ca294/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index 756aa29..400c6dc 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -46,6 +46,7 @@ EXTRA_DIST =					\
   tests/option_tests.cpp			\
   tests/os_tests.cpp				\
   tests/os/filesystem_tests.cpp			\
+  tests/os/rmdir_tests.cpp			\
   tests/os/sendfile_tests.cpp			\
   tests/os/signals_tests.cpp			\
   tests/os/strerror_tests.cpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/c55ca294/3rdparty/libprocess/3rdparty/stout/tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/CMakeLists.txt b/3rdparty/libprocess/3rdparty/stout/tests/CMakeLists.txt
index 6f9d46c..03e09fb 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/CMakeLists.txt
+++ b/3rdparty/libprocess/3rdparty/stout/tests/CMakeLists.txt
@@ -38,6 +38,7 @@ set(STOUT_TESTS_SRC
   numify_tests.cpp
   option_tests.cpp
   os/filesystem_tests.cpp
+  os/rmdir_tests.cpp
   protobuf_tests.pb.h
   protobuf_tests.proto
   result_tests.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/c55ca294/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
index d0592ef..4c30189 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
@@ -96,7 +96,7 @@ TEST_F(FsTest, ReadWriteString)
 }
 
 
-TEST_F(FsTest, Rmdir)
+TEST_F(FsTest, Mkdir)
 {
   const hashset<string> EMPTY;
   const string tmpdir = os::getcwd();

http://git-wip-us.apache.org/repos/asf/mesos/blob/c55ca294/3rdparty/libprocess/3rdparty/stout/tests/os/rmdir_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os/rmdir_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/os/rmdir_tests.cpp
new file mode 100644
index 0000000..291a22b
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os/rmdir_tests.cpp
@@ -0,0 +1,173 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <list>
+#include <map>
+#include <set>
+#include <string>
+
+#include <stout/path.hpp>
+
+#include <stout/os/getcwd.hpp>
+#include <stout/os/ls.hpp>
+#include <stout/os/mkdir.hpp>
+#include <stout/os/touch.hpp>
+
+#include <stout/tests/utils.hpp>
+
+using std::list;
+using std::set;
+using std::string;
+
+
+const hashset<string>& EMPTY = hashset<string>::EMPTY;
+
+
+static hashset<string> listfiles(const string& directory)
+{
+  hashset<string> fileset;
+  Try<list<string>> entries = os::ls(directory);
+  if (entries.isSome()) {
+    foreach (const string& entry, entries.get()) {
+      fileset.insert(entry);
+    }
+  }
+  return fileset;
+}
+
+
+class RmdirTest : public TemporaryDirectoryTest {};
+
+
+// TODO(hausdorff): This test is almost copy-pasted from
+// `TrivialRemoveEmptyDirectoryRelativePath`; we should parameterize them to
+// reduce redundancy.
+TEST_F(RmdirTest, TrivialRemoveEmptyDirectoryAbsolutePath)
+{
+  const string tmpdir = os::getcwd();
+  hashset<string> expectedListing = EMPTY;
+
+  // Directory is initially empty.
+  EXPECT_EQ(expectedListing, listfiles(tmpdir));
+
+  // Successfully make directory using absolute path.
+  const string newDirectoryName = "newDirectory";
+  const string newDirectoryAbsolutePath = path::join(tmpdir, newDirectoryName);
+  expectedListing.insert(newDirectoryName);
+  EXPECT_SOME(os::mkdir(newDirectoryAbsolutePath));
+  EXPECT_EQ(expectedListing, listfiles(tmpdir));
+  EXPECT_EQ(EMPTY, listfiles(newDirectoryAbsolutePath));
+
+  // Successfully remove.
+  EXPECT_SOME(os::rmdir(newDirectoryAbsolutePath));
+  EXPECT_EQ(EMPTY, listfiles(tmpdir));
+}
+
+
+TEST_F(RmdirTest, TrivialRemoveEmptyDirectoryRelativePath)
+{
+  const string tmpdir = os::getcwd();
+  hashset<string> expectedListing = EMPTY;
+
+  // Directory is initially empty.
+  EXPECT_EQ(expectedListing, listfiles(tmpdir));
+
+  // Successfully make directory using relative path.
+  const string newDirectoryName = "newDirectory";
+  expectedListing.insert(newDirectoryName);
+  EXPECT_SOME(os::mkdir(newDirectoryName));
+  EXPECT_EQ(expectedListing, listfiles(tmpdir));
+  EXPECT_EQ(EMPTY, listfiles(newDirectoryName));
+
+  // Successfully remove.
+  EXPECT_SOME(os::rmdir(newDirectoryName));
+  EXPECT_EQ(EMPTY, listfiles(tmpdir));
+}
+
+
+TEST_F(RmdirTest, RemoveRecursiveByDefault)
+{
+  const string tmpdir = os::getcwd();
+  hashset<string> expectedRootListing = EMPTY;
+  hashset<string> expectedSubListing = EMPTY;
+
+  // Directory is initially empty.
+  EXPECT_EQ(expectedRootListing, listfiles(tmpdir));
+
+  // Successfully make directory using absolute path, and then `touch` a file
+  // in that folder.
+  const string newDirectoryName = "newDirectory";
+  const string newDirectoryAbsolutePath = path::join(tmpdir, newDirectoryName);
+  const string newFileName = "newFile";
+  const string newFileAbsolutePath = path::join(
+      newDirectoryAbsolutePath,
+      newFileName);
+
+  expectedRootListing.insert(newDirectoryName);
+  expectedSubListing.insert(newFileName);
+
+  EXPECT_SOME(os::mkdir(newDirectoryAbsolutePath));
+  EXPECT_SOME(os::touch(newFileAbsolutePath));
+  EXPECT_EQ(expectedRootListing, listfiles(tmpdir));
+  EXPECT_EQ(expectedSubListing, listfiles(newDirectoryAbsolutePath));
+
+  // Successfully remove.
+  EXPECT_SOME(os::rmdir(newDirectoryAbsolutePath));
+  EXPECT_EQ(EMPTY, listfiles(tmpdir));
+  EXPECT_EQ(EMPTY, listfiles(newDirectoryAbsolutePath));
+}
+
+
+TEST_F(RmdirTest, TrivialFailToRemoveInvalidPath)
+{
+  // Directory is initially empty.
+  EXPECT_EQ(EMPTY, listfiles(os::getcwd()));
+
+  // Removing fake relative paths should error out.
+  EXPECT_ERROR(os::rmdir("fakeRelativePath", false));
+  EXPECT_ERROR(os::rmdir("fakeRelativePath", true));
+
+  // Directory still empty.
+  EXPECT_EQ(EMPTY, listfiles(os::getcwd()));
+}
+
+
+TEST_F(RmdirTest, FailTRemoveNestedInvalidPath)
+{
+  const string tmpdir = os::getcwd();
+  hashset<string> expectedRootListing = EMPTY;
+
+  // Directory is initially empty.
+  EXPECT_EQ(expectedRootListing, listfiles(tmpdir));
+
+  // Successfully make directory using absolute path.
+  const string newDirectoryName = "newDirectory";
+  const string newDirectoryAbsolutePath = path::join(tmpdir, newDirectoryName);
+
+  expectedRootListing.insert(newDirectoryName);
+
+  EXPECT_SOME(os::mkdir(newDirectoryAbsolutePath));
+  EXPECT_EQ(expectedRootListing, listfiles(tmpdir));
+  EXPECT_EQ(EMPTY, listfiles(newDirectoryAbsolutePath));
+
+  // Fail to remove a path to an invalid folder inside the
+  // `newDirectoryAbsolutePath`.
+  const string fakeAbsolutePath = path::join(newDirectoryAbsolutePath, "fake");
+  EXPECT_ERROR(os::rmdir(fakeAbsolutePath, false));
+  EXPECT_EQ(expectedRootListing, listfiles(tmpdir));
+  EXPECT_EQ(EMPTY, listfiles(newDirectoryAbsolutePath));
+
+  // Test the same thing, but using the `recursive` flag.
+  EXPECT_ERROR(os::rmdir(fakeAbsolutePath, true));
+  EXPECT_EQ(expectedRootListing, listfiles(tmpdir));
+  EXPECT_EQ(EMPTY, listfiles(newDirectoryAbsolutePath));
+}

http://git-wip-us.apache.org/repos/asf/mesos/blob/c55ca294/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
index a2bc5c4..a69fd2d 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
@@ -61,19 +61,6 @@ using std::string;
 using std::vector;
 
 
-static hashset<string> listfiles(const string& directory)
-{
-  hashset<string> fileset;
-  Try<list<string> > entries = os::ls(directory);
-  if (entries.isSome()) {
-    foreach (const string& entry, entries.get()) {
-      fileset.insert(entry);
-    }
-  }
-  return fileset;
-}
-
-
 #ifdef __FreeBSD__
 static bool isJailed() {
   int mib[4];
@@ -115,44 +102,6 @@ TEST_F(OsTest, Environment)
 }
 
 
-TEST_F(OsTest, Rmdir)
-{
-  const hashset<string> EMPTY;
-  const string tmpdir = os::getcwd();
-
-  hashset<string> expectedListing = EMPTY;
-  EXPECT_EQ(expectedListing, listfiles(tmpdir));
-
-  os::mkdir(tmpdir + "/a/b/c");
-  os::mkdir(tmpdir + "/a/b/d");
-  os::mkdir(tmpdir + "/e/f");
-
-  expectedListing = EMPTY;
-  expectedListing.insert("a");
-  expectedListing.insert("e");
-  EXPECT_EQ(expectedListing, listfiles(tmpdir));
-
-  expectedListing = EMPTY;
-  expectedListing.insert("b");
-  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/a"));
-
-  expectedListing = EMPTY;
-  expectedListing.insert("c");
-  expectedListing.insert("d");
-  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/a/b"));
-
-  expectedListing = EMPTY;
-  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/a/b/c"));
-  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/a/b/d"));
-
-  expectedListing.insert("f");
-  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/e"));
-
-  expectedListing = EMPTY;
-  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/e/f"));
-}
-
-
 TEST_F(OsTest, System)
 {
   EXPECT_EQ(0, os::system("exit 0"));
@@ -211,28 +160,6 @@ TEST_F(OsTest, Nonblock)
 }
 
 
-TEST_F(OsTest, Touch)
-{
-  const string testfile  = path::join(os::getcwd(), UUID::random().toString());
-
-  ASSERT_SOME(os::touch(testfile));
-  ASSERT_TRUE(os::exists(testfile));
-}
-
-
-TEST_F(OsTest, ReadWriteString)
-{
-  const string testfile  = path::join(os::getcwd(), UUID::random().toString());
-  const string teststr = "line1\nline2";
-
-  ASSERT_SOME(os::write(testfile, teststr));
-
-  Try<string> readstr = os::read(testfile);
-
-  EXPECT_SOME_EQ(teststr, readstr);
-}
-
-
 // Tests whether a file's size is reported by os::stat::size as expected.
 // Tests all four combinations of following a link or not and of a file
 // or a link as argument. Also tests that an error is returned for a
@@ -265,36 +192,6 @@ TEST_F(OsTest, Size)
 }
 
 
-TEST_F(OsTest, Find)
-{
-  const string testdir = path::join(os::getcwd(), UUID::random().toString());
-  const string subdir = testdir + "/test1";
-  ASSERT_SOME(os::mkdir(subdir)); // Create the directories.
-
-  // Now write some files.
-  const string file1 = testdir + "/file1.txt";
-  const string file2 = subdir + "/file2.txt";
-  const string file3 = subdir + "/file3.jpg";
-
-  ASSERT_SOME(os::touch(file1));
-  ASSERT_SOME(os::touch(file2));
-  ASSERT_SOME(os::touch(file3));
-
-  // Find "*.txt" files.
-  Try<list<string> > result = os::find(testdir, ".txt");
-  ASSERT_SOME(result);
-
-  hashset<string> files;
-  foreach (const string& file, result.get()) {
-    files.insert(file);
-  }
-
-  ASSERT_EQ(2u, files.size());
-  ASSERT_TRUE(files.contains(file1));
-  ASSERT_TRUE(files.contains(file2));
-}
-
-
 TEST_F(OsTest, BootId)
 {
   Try<string> bootId = os::bootId();