Skip to content

Commit

Permalink
MB-24293: Modify tests to use the new cb::io::rmrf API
Browse files Browse the repository at this point in the history
cb::io::rmrf has been modified to throw exceptions. Modify the
callers of the API accordingly

Change-Id: I16e81f3572e0b7d58af3d5ee1f7849aec8cabf97
Reviewed-on: http://review.couchbase.org/78424
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information
Sriram Ganesan authored and trondn committed May 24, 2017
1 parent 4fe820b commit e983902
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
6 changes: 3 additions & 3 deletions auditd/tests/auditconfig_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ TEST_F(AuditConfigTest, TestGetSetSanitizeLogPathMixedSeparators) {
std::string path = testdir + std::string("/mydir\\baddir");
EXPECT_NO_THROW(config.set_log_directory(path));
EXPECT_EQ(testdir + "\\mydir\\baddir", config.get_log_directory());
EXPECT_TRUE(cb::io::rmrf(config.get_log_directory()))
EXPECT_NO_THROW(cb::io::rmrf(config.get_log_directory()))
<< "Failed to remove: " << config.get_log_directory()
<< ": " << strerror(errno) << std::endl;
}
Expand All @@ -300,7 +300,7 @@ TEST_F(AuditConfigTest, TestCreateDirLogPath) {
cJSON_ReplaceItemInObject(json, "log_path",
cJSON_CreateString(path.c_str()));
EXPECT_NO_THROW(config.initialize_config(json));
EXPECT_TRUE(cb::io::rmrf(config.get_log_directory()))
EXPECT_NO_THROW(cb::io::rmrf(config.get_log_directory()))
<< "Failed to remove: " << config.get_log_directory()
<< ": " << strerror(errno) << std::endl;
}
Expand All @@ -322,7 +322,7 @@ TEST_F(AuditConfigTest, TestSetMissingEventDescrFileDescriptorsPath) {
cb::io::mkdirp(path);

EXPECT_THROW(config.set_descriptors_path(path), std::string);
EXPECT_TRUE(cb::io::rmrf(path))
EXPECT_NO_THROW(cb::io::rmrf(path))
<< "Failed to remove: " << path
<< ": " << strerror(errno) << std::endl;
}
Expand Down
16 changes: 14 additions & 2 deletions auditd/tests/testauditd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,24 @@ class AuditDaemonTest : public ::testing::Test {
static void SetUpTestCase() {
// create the test directory
testdir = std::string("auditd-test-") + std::to_string(cb_getpid());
cb::io::rmrf(testdir);
try {
cb::io::rmrf(testdir);
} catch (std::system_error& e) {
if (e.code() != std::error_code(ENOENT, std::system_category())) {
throw e;
}
}
cb::io::mkdirp(testdir);

// create the name of the configuration file to use
cfgfile = "test_audit-" + std::to_string(cb_getpid()) + ".json";
cb::io::rmrf(cfgfile);
try {
cb::io::rmrf(cfgfile);
} catch (std::system_error& e) {
if (e.code() != std::error_code(ENOENT, std::system_category())) {
throw e;
}
}

// Start the audit daemon
AUDIT_EXTENSION_DATA audit_extension_data;
Expand Down
6 changes: 2 additions & 4 deletions programs/cbtrace/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,11 @@ int main(int argc, char** argv) {
createCache(cachefile, argv[optind]);
} catch (std::runtime_error& e) {
std::cerr << e.what() << std::endl;
if (!cb::io::rmrf(cachefile)) {
if (access(cachefile.c_str(), F_OK) != -1) {
cb::io::rmrf(cachefile);
if (access(cachefile.c_str(), F_OK) != -1) {
std::cerr << "You should manually nuke " << cachefile
<< std::endl;
}
}
return EXIT_FAILURE;
}
} else {
std::cout << "Using cache in " << cachefile.c_str() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class EncryptedDatabaseTest : public ::testing::Test {
#else
unsetenv("COUCHBASE_CBSASL_SECRETS");
#endif
EXPECT_TRUE(cb::io::rmrf(filename));
EXPECT_NO_THROW(cb::io::rmrf(filename));
}

protected:
Expand Down
4 changes: 2 additions & 2 deletions tests/testapp/testapp_audit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class AuditTest : public TestappClientTest {
void SetUp() {
TestappClientTest::SetUp();
auto& logdir = mcd_env->getAuditLogDir();
ASSERT_TRUE(cb::io::rmrf(logdir));
EXPECT_NO_THROW(cb::io::rmrf(logdir));
cb::io::mkdirp(logdir);
setEnabled(true);
}

void TearDown() {
setEnabled(false);
auto& logdir = mcd_env->getAuditLogDir();
EXPECT_TRUE(cb::io::rmrf(mcd_env->getAuditLogDir()));
EXPECT_NO_THROW(cb::io::rmrf(mcd_env->getAuditLogDir()));
cb::io::mkdirp(logdir);
TestappClientTest::TearDown();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/testapp_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void McdEnvironment::SetupAuditFile() {
audit_file_name = cwd + "/" + cb::io::mktemp("audit.cfg");
audit_log_dir = cwd + "/" + cb::io::mktemp("audit.log");
const std::string descriptor = cwd + "/auditd";
EXPECT_TRUE(cb::io::rmrf(audit_log_dir));
EXPECT_NO_THROW(cb::io::rmrf(audit_log_dir));
cb::io::mkdirp(audit_log_dir);

// Generate the auditd config file.
Expand Down

0 comments on commit e983902

Please sign in to comment.