mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
c55781c666
Summary: Move the `UserInfo` code from `fuse/privhelper` to `utils`, and also unify the POSIX and Windows implementations of this class. This code was originally put in the `fuse/privhelper` directory since it was written at the same time as the privhelper. However, it's really a lower-level library that doesn't depend on FUSE or any of the other code in the `fuse/` subdirectory. Reviewed By: wez Differential Revision: D21296594 fbshipit-source-id: f58682f6ce86bba0328472c491bb4c0dc3370319
82 lines
2.6 KiB
C++
82 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
#include "eden/fs/testharness/TestServer.h"
|
|
|
|
#include <folly/portability/GFlags.h>
|
|
|
|
#include "eden/fs/config/EdenConfig.h"
|
|
#include "eden/fs/service/EdenServer.h"
|
|
#include "eden/fs/service/StartupLogger.h"
|
|
#include "eden/fs/telemetry/SessionInfo.h"
|
|
#include "eden/fs/testharness/FakePrivHelper.h"
|
|
#include "eden/fs/testharness/TempFile.h"
|
|
#include "eden/fs/utils/UserInfo.h"
|
|
|
|
using std::make_shared;
|
|
using std::make_unique;
|
|
using std::unique_ptr;
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
TestServer::TestServer()
|
|
: tmpDir_(makeTempDir()), server_(createServer(getTmpDir())) {
|
|
auto prepareResult = server_->prepare(make_shared<ForegroundStartupLogger>());
|
|
// We don't care about waiting for prepareResult: it just indicates when
|
|
// preparation has fully completed, but the EdenServer can begin being used
|
|
// immediately, before prepareResult completes.
|
|
//
|
|
// Maybe in the future it would be worth storing this future in a member
|
|
// variable so our caller could extract if if they want to. (It would allow
|
|
// the caller to schedule additional work once the thrift server is fully up
|
|
// and running, if the caller starts the thrift server.)
|
|
(void)prepareResult;
|
|
}
|
|
|
|
TestServer::~TestServer() {}
|
|
|
|
AbsolutePath TestServer::getTmpDir() const {
|
|
return AbsolutePath{tmpDir_.path().string()};
|
|
}
|
|
|
|
unique_ptr<EdenServer> TestServer::createServer(AbsolutePathPiece tmpDir) {
|
|
auto edenDir = tmpDir + "eden"_pc;
|
|
ensureDirectoryExists(edenDir);
|
|
|
|
// Always use an in-memory local store during tests.
|
|
// TODO: in the future we should build a better mechanism for controlling this
|
|
// rather than having to update a command line flag.
|
|
GFLAGS_NAMESPACE::SetCommandLineOptionWithMode(
|
|
"local_storage_engine_unsafe",
|
|
"memory",
|
|
GFLAGS_NAMESPACE::SET_FLAG_IF_DEFAULT);
|
|
|
|
auto userInfo = UserInfo::lookup();
|
|
userInfo.setHomeDirectory(tmpDir + "home"_pc);
|
|
auto config = make_shared<EdenConfig>(
|
|
userInfo.getUsername(),
|
|
userInfo.getUid(),
|
|
userInfo.getHomeDirectory(),
|
|
userInfo.getHomeDirectory() + ".edenrc"_pc,
|
|
tmpDir + "etc"_pc,
|
|
tmpDir + "etc/edenfs.rc"_relpath);
|
|
auto privHelper = make_unique<FakePrivHelper>();
|
|
config->edenDir.setValue(edenDir, ConfigSource::CommandLine);
|
|
|
|
return make_unique<EdenServer>(
|
|
std::vector<std::string>{"edenfs_unit_test"},
|
|
userInfo,
|
|
SessionInfo{},
|
|
std::move(privHelper),
|
|
config,
|
|
"test server");
|
|
}
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|