From eeb92debe6097bc32bb0c4885282d196a4e03d14 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 3 Nov 2015 13:02:04 -0800 Subject: [PATCH] Make test cases non-interacative by using --extpass option --- test/cli/CliTest_Setup.cpp | 20 +++++++++++++++----- test/cli/CliTest_WrongEnvironment.cpp | 7 ++++++- test/cli/testutils/CliTest.h | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/test/cli/CliTest_Setup.cpp b/test/cli/CliTest_Setup.cpp index 63b67042..c7023fe5 100644 --- a/test/cli/CliTest_Setup.cpp +++ b/test/cli/CliTest_Setup.cpp @@ -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); } \ No newline at end of file diff --git a/test/cli/CliTest_WrongEnvironment.cpp b/test/cli/CliTest_WrongEnvironment.cpp index 3c75bea3..f93aa62e 100644 --- a/test/cli/CliTest_WrongEnvironment.cpp +++ b/test/cli/CliTest_WrongEnvironment.cpp @@ -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(); diff --git a/test/cli/testutils/CliTest.h b/test/cli/testutils/CliTest.h index dd788e8c..9bcfe788 100644 --- a/test/cli/testutils/CliTest.h +++ b/test/cli/testutils/CliTest.h @@ -44,6 +44,8 @@ public: } void EXPECT_RUN_SUCCESS(std::vector 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.*"));