mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
update all C++ unit tests to use the new temporary file functions
Summary: Update all of the C++ unit tests that create temporary files and directories to use the new `facebook::eden::makeTempFile()` and `facebook::eden::makeTempDir()` functions. Note that this likely changes the behavior of some code paths in meaningful ways: `/dev/shm` normally does not support `getxattr()`, and Eden's overlay code attempts to store the SHA-1 for materialized files as using extended attributes. This means that the tests will now typically hit the fallback code path and will not store SHA-1 data in the overlay. Reviewed By: chadaustin, strager Differential Revision: D12971162 fbshipit-source-id: 6cc5eba2e04be7e9a13a30e90883feadfb78f9ce
This commit is contained in:
parent
2adb4a36b1
commit
0824d0280c
@ -28,6 +28,7 @@
|
||||
#include "eden/fs/service/PrettyPrinters.h"
|
||||
#include "eden/fs/testharness/FakeBackingStore.h"
|
||||
#include "eden/fs/testharness/FakeTreeBuilder.h"
|
||||
#include "eden/fs/testharness/TempFile.h"
|
||||
#include "eden/fs/testharness/TestChecks.h"
|
||||
#include "eden/fs/testharness/TestMount.h"
|
||||
#include "eden/fs/testharness/TestUtil.h"
|
||||
@ -59,7 +60,7 @@ TEST(OverlayGoldMasterTest, can_load_overlay_v2) {
|
||||
// This test helps ensure that new edenfs versions can still successfully load
|
||||
// this overlay format even if we change how the overlay is saved in the
|
||||
// future.
|
||||
TemporaryDirectory tmpdir("eden_test");
|
||||
auto tmpdir = makeTempDir("eden_test");
|
||||
Subprocess tarProcess({"/bin/tar",
|
||||
"-xzf",
|
||||
"eden/test-data/overlay-v2.tgz",
|
||||
@ -267,7 +268,7 @@ enum class OverlayRestartMode {
|
||||
|
||||
class RawOverlayTest : public ::testing::TestWithParam<OverlayRestartMode> {
|
||||
public:
|
||||
RawOverlayTest() : testDir_{"eden_raw_overlay_test_"} {
|
||||
RawOverlayTest() : testDir_{makeTempDir("eden_raw_overlay_test_")} {
|
||||
loadOverlay();
|
||||
}
|
||||
|
||||
@ -604,7 +605,7 @@ TEST(OverlayInodePath, defaultInodePathIsEmpty) {
|
||||
class DebugDumpOverlayInodesTest : public ::testing::Test {
|
||||
public:
|
||||
DebugDumpOverlayInodesTest()
|
||||
: testDir_{"eden_DebugDumpOverlayInodesTest"},
|
||||
: testDir_{makeTempDir("eden_DebugDumpOverlayInodesTest")},
|
||||
overlay{AbsolutePathPiece{testDir_.path().string()}} {}
|
||||
|
||||
folly::test::TemporaryDirectory testDir_;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "eden/fs/store/RocksDbLocalStore.h"
|
||||
#include "eden/fs/store/SqliteLocalStore.h"
|
||||
#include "eden/fs/store/StoreResult.h"
|
||||
#include "eden/fs/testharness/TempFile.h"
|
||||
|
||||
using namespace facebook::eden;
|
||||
using namespace std::chrono_literals;
|
||||
@ -47,12 +48,12 @@ class LocalStoreTest : public ::testing::TestWithParam<StoreImpl> {
|
||||
store_ = std::make_unique<MemoryLocalStore>();
|
||||
break;
|
||||
case StoreImpl::RocksDB:
|
||||
testDir_ = std::make_unique<TemporaryDirectory>("eden_test");
|
||||
testDir_ = makeTempDir();
|
||||
store_ = std::make_unique<RocksDbLocalStore>(
|
||||
AbsolutePathPiece{testDir_->path().string()});
|
||||
break;
|
||||
case StoreImpl::Sqlite:
|
||||
testDir_ = std::make_unique<TemporaryDirectory>("eden_test");
|
||||
testDir_ = makeTempDir();
|
||||
store_ = std::make_unique<SqliteLocalStore>(
|
||||
AbsolutePathPiece{testDir_->path().string()} + "sqlite"_pc);
|
||||
}
|
||||
@ -63,7 +64,7 @@ class LocalStoreTest : public ::testing::TestWithParam<StoreImpl> {
|
||||
testDir_.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<TemporaryDirectory> testDir_;
|
||||
std::optional<TemporaryDirectory> testDir_;
|
||||
std::unique_ptr<LocalStore> store_;
|
||||
};
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "eden/fs/testharness/FakeFuse.h"
|
||||
#include "eden/fs/testharness/FakePrivHelper.h"
|
||||
#include "eden/fs/testharness/FakeTreeBuilder.h"
|
||||
#include "eden/fs/testharness/TempFile.h"
|
||||
#include "eden/fs/testharness/TestUtil.h"
|
||||
#include "eden/fs/utils/ProcessNameCache.h"
|
||||
#include "eden/fs/utils/UnboundedQueueExecutor.h"
|
||||
@ -49,8 +50,6 @@ using folly::Future;
|
||||
using folly::makeFuture;
|
||||
using folly::StringPiece;
|
||||
using folly::Unit;
|
||||
using folly::test::TemporaryDirectory;
|
||||
using folly::test::TemporaryFile;
|
||||
using namespace std::chrono_literals;
|
||||
using std::make_shared;
|
||||
using std::make_unique;
|
||||
@ -184,7 +183,7 @@ void TestMount::initialize(FakeTreeBuilder& rootBuilder, bool startReady) {
|
||||
|
||||
void TestMount::initTestDirectory() {
|
||||
// Create the temporary directory
|
||||
testDir_ = make_unique<TemporaryDirectory>("eden_test");
|
||||
testDir_ = makeTempDir();
|
||||
|
||||
// Make the mount point and the eden client storage directories
|
||||
// inside the test directory.
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <folly/Range.h>
|
||||
#include <folly/experimental/TestUtil.h>
|
||||
#include <sys/stat.h>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include "eden/fs/inodes/EdenMount.h"
|
||||
#include "eden/fs/inodes/InodePtr.h"
|
||||
@ -300,7 +301,7 @@ class TestMount {
|
||||
* first, and destroyed (and deleted from disk) after the EdenMount is
|
||||
* destroyed.
|
||||
*/
|
||||
std::unique_ptr<folly::test::TemporaryDirectory> testDir_;
|
||||
std::optional<folly::test::TemporaryDirectory> testDir_;
|
||||
|
||||
std::shared_ptr<EdenMount> edenMount_;
|
||||
std::shared_ptr<LocalStore> localStore_;
|
||||
|
@ -22,13 +22,11 @@
|
||||
|
||||
using namespace facebook::eden;
|
||||
using folly::io::Cursor;
|
||||
using folly::test::TemporaryDirectory;
|
||||
|
||||
namespace {
|
||||
class FakeBackingStoreTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
testDir_ = std::make_unique<TemporaryDirectory>("eden_test");
|
||||
localStore_ = std::make_shared<MemoryLocalStore>();
|
||||
store_ = std::make_unique<FakeBackingStore>(localStore_);
|
||||
}
|
||||
@ -36,10 +34,8 @@ class FakeBackingStoreTest : public ::testing::Test {
|
||||
void TearDown() override {
|
||||
store_.reset();
|
||||
localStore_.reset();
|
||||
testDir_.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<TemporaryDirectory> testDir_;
|
||||
std::shared_ptr<LocalStore> localStore_;
|
||||
std::unique_ptr<FakeBackingStore> store_;
|
||||
};
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include <unistd.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "eden/fs/testharness/TempFile.h"
|
||||
|
||||
using facebook::eden::basename;
|
||||
using facebook::eden::dirname;
|
||||
using folly::StringPiece;
|
||||
@ -556,7 +558,7 @@ class TmpWorkingDir {
|
||||
}
|
||||
|
||||
AbsolutePath oldDir{getcwd()};
|
||||
folly::test::TemporaryDirectory dir{"eden_test"};
|
||||
folly::test::TemporaryDirectory dir = makeTempDir();
|
||||
std::string pathStr{dir.path().string()};
|
||||
AbsolutePathPiece path{pathStr};
|
||||
};
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <random>
|
||||
|
||||
#include "eden/fs/testharness/TempFile.h"
|
||||
|
||||
using folly::ByteRange;
|
||||
using folly::checkUnixError;
|
||||
using folly::errnoStr;
|
||||
@ -76,7 +78,7 @@ void testSendDataAndFiles(DataSize dataSize, size_t numFiles) {
|
||||
auto socket1 = make_unique<FutureUnixSocket>(&evb, std::move(sockets.first));
|
||||
auto socket2 = make_unique<FutureUnixSocket>(&evb, std::move(sockets.second));
|
||||
|
||||
auto tmpFile = TemporaryFile("eden_test");
|
||||
auto tmpFile = makeTempFile();
|
||||
struct stat tmpFileStat;
|
||||
if (fstat(tmpFile.fd(), &tmpFileStat) != 0) {
|
||||
ADD_FAILURE() << "fstat failed: " << errnoStr(errno);
|
||||
|
Loading…
Reference in New Issue
Block a user