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
6 #include "test_util/testutil.h"
7
8 #include "file/file_util.h"
9 #include "port/port.h"
10 #include "port/stack_trace.h"
11 #include "test_util/testharness.h"
12
13 namespace ROCKSDB_NAMESPACE {
14
CreateFile(Env * env,const std::string & path)15 void CreateFile(Env* env, const std::string& path) {
16 std::unique_ptr<WritableFile> f;
17 ASSERT_OK(env->NewWritableFile(path, &f, EnvOptions()));
18 f->Close();
19 }
20
TEST(TestUtil,DestroyDirRecursively)21 TEST(TestUtil, DestroyDirRecursively) {
22 auto env = Env::Default();
23 // test_util/file
24 // /dir
25 // /dir/file
26 std::string test_dir = test::PerThreadDBPath("test_util");
27 ASSERT_OK(env->CreateDir(test_dir));
28 CreateFile(env, test_dir + "/file");
29 ASSERT_OK(env->CreateDir(test_dir + "/dir"));
30 CreateFile(env, test_dir + "/dir/file");
31
32 ASSERT_OK(DestroyDir(env, test_dir));
33 auto s = env->FileExists(test_dir);
34 ASSERT_TRUE(s.IsNotFound());
35 }
36
37 } // namespace ROCKSDB_NAMESPACE
38
main(int argc,char ** argv)39 int main(int argc, char** argv) {
40 ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
41 ::testing::InitGoogleTest(&argc, argv);
42 return RUN_ALL_TESTS();
43 }
44