testutil_test.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #include "test_util/testutil.h"
  6. #include "file/file_util.h"
  7. #include "port/port.h"
  8. #include "port/stack_trace.h"
  9. #include "test_util/testharness.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. void CreateFile(Env* env, const std::string& path) {
  12. std::unique_ptr<WritableFile> f;
  13. ASSERT_OK(env->NewWritableFile(path, &f, EnvOptions()));
  14. f->Close();
  15. }
  16. TEST(TestUtil, DestroyDirRecursively) {
  17. auto env = Env::Default();
  18. // test_util/file
  19. // /dir
  20. // /dir/file
  21. std::string test_dir = test::PerThreadDBPath("test_util");
  22. ASSERT_OK(env->CreateDir(test_dir));
  23. CreateFile(env, test_dir + "/file");
  24. ASSERT_OK(env->CreateDir(test_dir + "/dir"));
  25. CreateFile(env, test_dir + "/dir/file");
  26. ASSERT_OK(DestroyDir(env, test_dir));
  27. auto s = env->FileExists(test_dir);
  28. ASSERT_TRUE(s.IsNotFound());
  29. }
  30. } // namespace ROCKSDB_NAMESPACE
  31. int main(int argc, char** argv) {
  32. ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
  33. ::testing::InitGoogleTest(&argc, argv);
  34. return RUN_ALL_TESTS();
  35. }