Make test cases non-interacative by using --extpass option

This commit is contained in:
Sebastian Messmer 2015-11-03 13:02:04 -08:00
parent eb0a27759c
commit eeb92debe6
3 changed files with 23 additions and 8 deletions

View File

@ -6,24 +6,34 @@ using cpputils::TempFile;
using CliTest_Setup = CliTest;
TEST_F(CliTest_Setup, NoSpecialOptions) {
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--cipher", "aes-256-gcm"}, mountdir);
//Specify --cipher and --extpass parameters to make it non-interactive
//TODO Remove "-f" parameter, once EXPECT_RUN_SUCCESS can handle that
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--cipher", "aes-256-gcm", "--extpass", "echo mypassword", "-f"}, mountdir);
}
TEST_F(CliTest_Setup, NotexistingLogfileGiven) {
TempFile notexisting_logfile(false);
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--logfile", notexisting_logfile.path().c_str()}, mountdir);
//Specify --cipher and --extpass parameters to make it non-interactive
//TODO Remove "-f" parameter, once EXPECT_RUN_SUCCESS can handle that
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "-f", "--cipher", "aes-256-gcm", "--extpass", "echo mypassword", "--logfile", notexisting_logfile.path().c_str()}, mountdir);
//TODO Expect logfile is used (check logfile content)
}
TEST_F(CliTest_Setup, ExistingLogfileGiven) {
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--logfile", logfile.path().c_str()}, mountdir);
//Specify --cipher and --extpass parameters to make it non-interactive
//TODO Remove "-f" parameter, once EXPECT_RUN_SUCCESS can handle that
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "-f", "--cipher", "aes-256-gcm", "--extpass", "echo mypassword", "--logfile", logfile.path().c_str()}, mountdir);
//TODO Expect logfile is used (check logfile content)
}
TEST_F(CliTest_Setup, ConfigfileGiven) {
EXPECT_RUN_SUCCESS({basedir.c_str(), "--config", configfile.path().c_str(), mountdir.c_str()}, mountdir);
//Specify --cipher and --extpass parameters to make it non-interactive
//TODO Remove "-f" parameter, once EXPECT_RUN_SUCCESS can handle that
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "-f", "--cipher", "aes-256-gcm", "--extpass", "echo mypassword", "--config", configfile.path().c_str()}, mountdir);
}
TEST_F(CliTest_Setup, FuseOptionGiven) {
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--", "-f"}, mountdir);
//Specify --cipher and --extpass parameters to make it non-interactive
//TODO Remove "-f" parameter, once EXPECT_RUN_SUCCESS can handle that
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "-f", "--cipher", "aes-256-gcm", "--extpass", "echo mypassword", "--", "-f"}, mountdir);
}

View File

@ -59,9 +59,11 @@ public:
if (GetParam().runningInForeground) {
result.push_back("-f");
}
// Test case should be non-interactive, so don't ask for cipher.
// Test case should be non-interactive, so don't ask for cipher or password.
result.push_back("--cipher");
result.push_back("aes-256-gcm");
result.push_back("--extpass");
result.push_back("echo mypassword");
return result;
}
};
@ -77,6 +79,7 @@ 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;} // TODO Make this work also if run in background (see CliTest::EXPECT_RUN_SUCCESS)
Test_Run_Success();
}
@ -124,6 +127,7 @@ TEST_P(CliTest_WrongEnvironment, BaseDir_IsNotDirectory) {
}
TEST_P(CliTest_WrongEnvironment, BaseDir_AllPermissions) {
if (!GetParam().runningInForeground) {return;} // TODO Make this work also if run in background (see CliTest::EXPECT_RUN_SUCCESS)
//Counter-Test. Test it doesn't fail if permissions are there.
SetAllPermissions(basedir);
Test_Run_Success();
@ -161,6 +165,7 @@ TEST_P(CliTest_WrongEnvironment, MountDir_IsNotDirectory) {
}
TEST_P(CliTest_WrongEnvironment, MountDir_AllPermissions) {
if (!GetParam().runningInForeground) {return;} // TODO Make this work also if run in background (see CliTest::EXPECT_RUN_SUCCESS)
//Counter-Test. Test it doesn't fail if permissions are there.
SetAllPermissions(mountdir);
Test_Run_Success();

View File

@ -44,6 +44,8 @@ public:
}
void EXPECT_RUN_SUCCESS(std::vector<const char*> args, const boost::filesystem::path &mountDir) {
//TODO Make this work when run in background
ASSERT(std::find(args.begin(), args.end(), string("-f")) != args.end(), "Currently only works if run in foreground");
std::thread unmountThread([&mountDir] {
int returncode = -1;
while (returncode != 0) {
@ -52,8 +54,6 @@ public:
}
});
//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.*"));