Fixed some issues in the not-yet-used success tests

This commit is contained in:
Sebastian Messmer 2015-10-30 22:24:18 +01:00
parent 6bbdc1be3d
commit d25d51f195
3 changed files with 19 additions and 23 deletions

View File

@ -6,24 +6,24 @@ using cpputils::TempFile;
using CliTest_Setup = CliTest; using CliTest_Setup = CliTest;
TEST_F(CliTest_Setup, NoSpecialOptions) { TEST_F(CliTest_Setup, NoSpecialOptions) {
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--cipher", "aes-256-gcm"}, basedir); EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--cipher", "aes-256-gcm"}, mountdir);
} }
TEST_F(CliTest_Setup, NotexistingLogfileGiven) { TEST_F(CliTest_Setup, NotexistingLogfileGiven) {
TempFile notexisting_logfile(false); TempFile notexisting_logfile(false);
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--logfile", notexisting_logfile.path().c_str()}, basedir); EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--logfile", notexisting_logfile.path().c_str()}, mountdir);
//TODO Expect logfile is used (check logfile content) //TODO Expect logfile is used (check logfile content)
} }
TEST_F(CliTest_Setup, ExistingLogfileGiven) { TEST_F(CliTest_Setup, ExistingLogfileGiven) {
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--logfile", logfile.path().c_str()}, basedir); EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--logfile", logfile.path().c_str()}, mountdir);
//TODO Expect logfile is used (check logfile content) //TODO Expect logfile is used (check logfile content)
} }
TEST_F(CliTest_Setup, ConfigfileGiven) { TEST_F(CliTest_Setup, ConfigfileGiven) {
EXPECT_RUN_SUCCESS({basedir.c_str(), "--config", configfile.path().c_str(), mountdir.c_str()}, basedir); EXPECT_RUN_SUCCESS({basedir.c_str(), "--config", configfile.path().c_str(), mountdir.c_str()}, mountdir);
} }
TEST_F(CliTest_Setup, FuseOptionGiven) { TEST_F(CliTest_Setup, FuseOptionGiven) {
EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--", "-f"}, basedir); EXPECT_RUN_SUCCESS({basedir.c_str(), mountdir.c_str(), "--", "-f"}, mountdir);
} }

View File

@ -36,7 +36,7 @@ public:
} }
void Test_Run_Success() { void Test_Run_Success() {
EXPECT_RUN_SUCCESS(args(), basedir); EXPECT_RUN_SUCCESS(args(), mountdir);
} }
void Test_Run_Error(const char *expectedError) { void Test_Run_Error(const char *expectedError) {
@ -74,6 +74,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. //Counter-Test. Test that it doesn't fail if we call it without an error condition.
TEST_P(CliTest_WrongEnvironment, NoErrorCondition) { TEST_P(CliTest_WrongEnvironment, NoErrorCondition) {
if (GetParam().runningInForeground) {return;} // Don't run this test in foreground, because it would block
Test_Run_Success(); Test_Run_Success();
} }
@ -123,6 +124,7 @@ TEST_P(CliTest_WrongEnvironment, BaseDir_IsNotDirectory) {
TEST_P(CliTest_WrongEnvironment, BaseDir_AllPermissions) { TEST_P(CliTest_WrongEnvironment, BaseDir_AllPermissions) {
//Counter-Test. Test it doesn't fail if permissions are there. //Counter-Test. Test it doesn't fail if permissions are there.
SetAllPermissions(basedir); SetAllPermissions(basedir);
if (GetParam().runningInForeground) {return;} // Don't run this test in foreground, because it would block
Test_Run_Success(); Test_Run_Success();
} }
@ -159,6 +161,7 @@ TEST_P(CliTest_WrongEnvironment, MountDir_IsNotDirectory) {
TEST_P(CliTest_WrongEnvironment, MountDir_AllPermissions) { TEST_P(CliTest_WrongEnvironment, MountDir_AllPermissions) {
//Counter-Test. Test it doesn't fail if permissions are there. //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); SetAllPermissions(mountdir);
Test_Run_Success(); Test_Run_Success();
} }

View File

@ -41,26 +41,19 @@ public:
); );
} }
class _UnmountFilesystemInDestructor final { void EXPECT_RUN_SUCCESS(std::vector<const char*> args, const boost::filesystem::path &mountDir) {
public:
_UnmountFilesystemInDestructor(const boost::filesystem::path &baseDir) :_baseDir(baseDir) {}
~_UnmountFilesystemInDestructor() {
if (0 != system((std::string("fusermount -u ")+_baseDir.c_str()).c_str())) {
cpputils::logging::LOG(cpputils::logging::ERROR) << "Could not unmount cryfs";
}
}
private:
boost::filesystem::path _baseDir;
};
void EXPECT_RUN_SUCCESS(std::vector<const char*> args, const boost::filesystem::path &baseDir) {
//TODO //TODO
/*_UnmountFilesystemInDestructor raii(baseDir); /*EXPECT_EXIT(
EXPECT_EXIT(
run(args), run(args),
::testing::ExitedWithCode(0), ::testing::ExitedWithCode(0),
"Filesystem is running" "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";
}*/
} }
}; };