Skip to content

Commit

Permalink
Run env_basic_test on Env::Default
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ajkr committed Jul 1, 2016
1 parent 9eb0b53 commit 6b71676
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions util/env_basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,49 @@

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<std::string>* 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<FileAttributes>* 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<Env*> {
public:
Env* env_;
const EnvOptions soptions_;
std::string test_dir_;

EnvBasicTestWithParam() {
env_ = GetParam();
EnvBasicTestWithParam() : env_(GetParam()) {
test_dir_ = test::TmpDir(env_) + "/env_basic_test";
}

Expand All @@ -46,6 +80,12 @@ class EnvBasicTestWithParam : public testing::Test,

class EnvMoreTestWithParam : public EnvBasicTestWithParam {};

static std::unique_ptr<Env> 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<Env> mock_env(new MockEnv(Env::Default()));
INSTANTIATE_TEST_CASE_P(MockEnv, EnvBasicTestWithParam,
::testing::Values(mock_env.get()));
Expand Down

0 comments on commit 6b71676

Please sign in to comment.