Added success tests

This commit is contained in:
Sebastian Messmer 2015-11-02 12:20:10 -08:00
parent 4d6970837e
commit 9aee4b1657
3 changed files with 18 additions and 15 deletions

View File

@ -137,6 +137,7 @@ namespace cryfs {
}
void Cli::_initLogfile(const ProgramOptions &options) {
spdlog::drop("cryfs");
//TODO Test that --logfile parameter works. Should be: file if specified, otherwise stderr if foreground, else syslog.
if (options.logFile() != none) {
cpputils::logging::setLogger(

View File

@ -59,6 +59,9 @@ public:
if (GetParam().runningInForeground) {
result.push_back("-f");
}
// Test case should be non-interactive, so don't ask for cipher.
result.push_back("--cipher");
result.push_back("aes-256-gcm");
return result;
}
};
@ -74,7 +77,6 @@ INSTANTIATE_TEST_CASE_P(RunningInForeground_ExternalConfigfile_LogIsNotStderr, C
//Counter-Test. Test that it doesn't fail if we call it without an error condition.
TEST_P(CliTest_WrongEnvironment, NoErrorCondition) {
if (GetParam().runningInForeground) {return;} // Don't run this test in foreground, because it would block
Test_Run_Success();
}
@ -124,7 +126,6 @@ TEST_P(CliTest_WrongEnvironment, BaseDir_IsNotDirectory) {
TEST_P(CliTest_WrongEnvironment, BaseDir_AllPermissions) {
//Counter-Test. Test it doesn't fail if permissions are there.
SetAllPermissions(basedir);
if (GetParam().runningInForeground) {return;} // Don't run this test in foreground, because it would block
Test_Run_Success();
}
@ -161,7 +162,6 @@ TEST_P(CliTest_WrongEnvironment, MountDir_IsNotDirectory) {
TEST_P(CliTest_WrongEnvironment, MountDir_AllPermissions) {
//Counter-Test. Test it doesn't fail if permissions are there.
if (GetParam().runningInForeground) {return;} // Don't run this test in foreground, because it would block
SetAllPermissions(mountdir);
Test_Run_Success();
}

View File

@ -3,6 +3,7 @@
#define MESSMER_CRYFS_TEST_CLI_TESTUTILS_CLITEST_H
#include <google/gtest/gtest.h>
#include <google/gmock/gmock.h>
#include <messmer/cpp-utils/tempfile/TempDir.h>
#include <messmer/cpp-utils/tempfile/TempFile.h>
#include "../../../src/Cli.h"
@ -42,18 +43,19 @@ public:
}
void EXPECT_RUN_SUCCESS(std::vector<const char*> args, const boost::filesystem::path &mountDir) {
//TODO
/*EXPECT_EXIT(
run(args),
::testing::ExitedWithCode(0),
"Mounting filesystem"
);
//Cleanup: Unmount filesystem
auto returncode = system((std::string("fusermount -u ")+mountDir.c_str()).c_str());
if (0 != returncode) {
cpputils::logging::LOG(cpputils::logging::ERROR) << "Could not unmount cryfs";
}*/
std::thread unmountThread([&mountDir] {
int returncode = -1;
while (returncode != 0) {
returncode = system((std::string("fusermount -u ") + mountDir.c_str()).c_str());
std::this_thread::sleep_for(std::chrono::milliseconds(50)); // TODO Is this the test case duration? Does a shorter interval make the test case faster?
}
});
//testing::internal::CaptureStdout();
//TODO Don't force foreground, but find a way to run it also in background.
args.push_back("-f");
run(args);
unmountThread.join();
//EXPECT_THAT(testing::internal::GetCapturedStdout(), testing::MatchesRegex(".*Mounting filesystem.*"));
}
};