From 6b7167651f4730037d104bb571e3de7e5a602392 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Thu, 30 Jun 2016 18:34:29 -0700 Subject: [PATCH] Run env_basic_test on Env::Default Summary: Previously we couldn't run env_basic_test on Env::Default (PosixEnv on our platforms) since GetChildren*() behavior was inconsistent with our other Envs. We can normalize the output of GetChildren*() such that these test cases work on PosixEnv too. Test Plan: ran env_basic_test Reviewers: wanning Reviewed By: wanning Subscribers: andrewkr, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D59943 --- util/env_basic_test.cc | 44 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/util/env_basic_test.cc b/util/env_basic_test.cc index efc99dc10..9626097ba 100644 --- a/util/env_basic_test.cc +++ b/util/env_basic_test.cc @@ -13,6 +13,41 @@ namespace rocksdb { +// Normalizes trivial differences across Envs such that these test cases can +// run on all Envs. +class NormalizingEnvWrapper : public EnvWrapper { + public: + explicit NormalizingEnvWrapper(Env* base) : EnvWrapper(base) {} + + // Removes . and .. from directory listing + virtual Status GetChildren(const std::string& dir, + std::vector* result) override { + Status status = EnvWrapper::GetChildren(dir, result); + if (status.ok()) { + result->erase(std::remove_if(result->begin(), result->end(), + [](const std::string& s) { + return s == "." || s == ".."; + }), + result->end()); + } + return status; + } + + // Removes . and .. from directory listing + virtual Status GetChildrenFileAttributes( + const std::string& dir, std::vector* result) override { + Status status = EnvWrapper::GetChildrenFileAttributes(dir, result); + if (status.ok()) { + result->erase(std::remove_if(result->begin(), result->end(), + [](const FileAttributes& fa) { + return fa.name == "." || fa.name == ".."; + }), + result->end()); + } + return status; + } +}; + class EnvBasicTestWithParam : public testing::Test, public ::testing::WithParamInterface { public: @@ -20,8 +55,7 @@ class EnvBasicTestWithParam : public testing::Test, const EnvOptions soptions_; std::string test_dir_; - EnvBasicTestWithParam() { - env_ = GetParam(); + EnvBasicTestWithParam() : env_(GetParam()) { test_dir_ = test::TmpDir(env_) + "/env_basic_test"; } @@ -46,6 +80,12 @@ class EnvBasicTestWithParam : public testing::Test, class EnvMoreTestWithParam : public EnvBasicTestWithParam {}; +static std::unique_ptr def_env(new NormalizingEnvWrapper(Env::Default())); +INSTANTIATE_TEST_CASE_P(EnvDefault, EnvBasicTestWithParam, + ::testing::Values(def_env.get())); +INSTANTIATE_TEST_CASE_P(EnvDefault, EnvMoreTestWithParam, + ::testing::Values(def_env.get())); + static std::unique_ptr mock_env(new MockEnv(Env::Default())); INSTANTIATE_TEST_CASE_P(MockEnv, EnvBasicTestWithParam, ::testing::Values(mock_env.get()));