Don't pollute users local state dir when running test cases

This commit is contained in:
Sebastian Messmer 2017-09-30 09:03:19 +01:00
parent 7a5b23db13
commit 011c6d26ce
5 changed files with 8 additions and 17 deletions

View File

@ -6,10 +6,8 @@ namespace bf = boost::filesystem;
namespace cryfs {
namespace {
// TODO constexpr?
bf::path& appDir() {
static bf::path singleton = cpputils::system::HomeDirectory::get() / ".cryfs";
return singleton;
bf::path appDir() {
return cpputils::system::HomeDirectory::get() / ".cryfs";
}
}
@ -32,8 +30,4 @@ namespace cryfs {
bf::create_directories(path);
}
}
void LocalStateDir::setAppDir(boost::filesystem::path path) {
appDir() = std::move(path);
}
}

View File

@ -13,10 +13,6 @@ namespace cryfs {
static boost::filesystem::path forFilesystemId(const CryConfig::FilesystemID &filesystemId);
static boost::filesystem::path forBasedirMetadata();
// Use this from test cases to not pollute local config
// TODO Make test cases call this
static void setAppDir(boost::filesystem::path path);
private:
LocalStateDir(); // static functions only

View File

@ -4,6 +4,7 @@
#include <cryfs/config/CryCipher.h>
#include <cpp-utils/crypto/symmetric/ciphers.h>
#include "../testutils/MockConsole.h"
#include "../testutils/TestWithFakeHomeDirectory.h"
#include <cpp-utils/io/NoninteractiveConsole.h>
#include <gitversion/gitversion.h>
@ -46,7 +47,7 @@ using ::testing::WithParamInterface;
#define IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION() \
EXPECT_CALL(*console, askYesNo(HasSubstr("missing block"), false))
class CryConfigCreatorTest: public ::testing::Test {
class CryConfigCreatorTest: public ::testing::Test, TestWithFakeHomeDirectory {
public:
CryConfigCreatorTest()
: console(make_shared<MockConsole>()),

View File

@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include <cryfs/config/CryConfigLoader.h>
#include "../testutils/MockConsole.h"
#include "../testutils/TestWithFakeHomeDirectory.h"
#include <cpp-utils/tempfile/TempFile.h>
#include <cpp-utils/random/Random.h>
#include <cpp-utils/crypto/symmetric/ciphers.h>
@ -34,7 +35,7 @@ namespace boost {
}
#include <boost/optional/optional_io.hpp>
class CryConfigLoaderTest: public ::testing::Test, public TestWithMockConsole {
class CryConfigLoaderTest: public ::testing::Test, public TestWithMockConsole, TestWithFakeHomeDirectory {
public:
CryConfigLoaderTest(): file(false) {
console = mockConsole();

View File

@ -4,6 +4,7 @@
#include <cryfs/localstate/LocalStateDir.h>
#include <cryfs/config/CryConfig.h>
#include <cpp-utils/tempfile/TempDir.h>
#include "../testutils/TestWithFakeHomeDirectory.h"
using cpputils::TempDir;
using cryfs::BasedirMetadata;
@ -11,7 +12,7 @@ using std::ofstream;
namespace bf = boost::filesystem;
using FilesystemID = cryfs::CryConfig::FilesystemID ;
class BasedirMetadataTest : public ::testing::Test {
class BasedirMetadataTest : public ::testing::Test, TestWithFakeHomeDirectory {
public:
TempDir tempdir;
bf::path basedir1;
@ -26,8 +27,6 @@ public:
, id1(FilesystemID::FromString("1491BB4932A389EE14BC7090AC772972"))
, id2(FilesystemID::FromString("A1491BB493214BC7090C772972A389EE"))
{
// Use temporary local state dir to not pollute local state
cryfs::LocalStateDir::setAppDir(tempdir.path() / "appdir");
// Create basedirs so bf::canonical() works
bf::create_directories(basedir1);
bf::create_directories(basedir2);