mirror of
https://github.com/facebook/sapling.git
synced 2025-01-06 21:48:36 +03:00
move the ConfigSource enum to a thrift file
Summary: Move the ConfigSource enum definition to a thrift file. This will let us return ConfigSource values over thrift APIs in the future. This also allows us to use thrift's `TEnumTraits` functionality to determine the maximum enum value, rather than having to maintain a separate `kConfigSourceLastIndex` variable. As part of this change I also renamed the enum values to be CamelCase to match our current C++ style recommendations and to avoid possibly conflicting with macros defined in other headers (`DEFAULT` seemed particularly susceptible to collision). Reviewed By: strager Differential Revision: D15572120 fbshipit-source-id: 8fbd03da221a9f75ef670dee1eb250eb198a5bd0
This commit is contained in:
parent
799d2d6834
commit
897764d81c
@ -1,3 +1,15 @@
|
||||
# Copyright (c) 2019-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
add_thrift_cpp2_library(
|
||||
eden_config_thrift
|
||||
eden_config.thrift
|
||||
)
|
||||
|
||||
file(GLOB CONFIG_SRCS "*.cpp")
|
||||
add_library(
|
||||
eden_config STATIC
|
||||
@ -6,6 +18,7 @@ add_library(
|
||||
target_link_libraries(
|
||||
eden_config
|
||||
PUBLIC
|
||||
eden_config_thrift
|
||||
eden_utils
|
||||
)
|
||||
target_include_directories(
|
||||
|
@ -18,27 +18,11 @@
|
||||
#include <folly/Range.h>
|
||||
|
||||
#include "eden/fs/config/FieldConverter.h"
|
||||
#include "eden/fs/config/gen-cpp2/eden_config_types.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace eden {
|
||||
|
||||
/**
|
||||
* ConfigSource identifies the point of origin of a config setting.
|
||||
* It is ordered from low to high precedence. Higher precedence
|
||||
* configuration values over-ride lower precedence values. A config
|
||||
* setting of COMMAND_LINE takes precedence over all other settings.
|
||||
* NOTE: ConfigSource enum values are used to access array elements. Thus,
|
||||
* they should be ordered from 0 to kConfigSourceLastIndex, with increments
|
||||
* of 1.
|
||||
*/
|
||||
enum class ConfigSource {
|
||||
DEFAULT = 0,
|
||||
SYSTEM_CONFIG_FILE = 1,
|
||||
USER_CONFIG_FILE = 2,
|
||||
COMMAND_LINE = 3,
|
||||
};
|
||||
constexpr size_t kConfigSourceLastIndex = 3;
|
||||
|
||||
class ConfigSettingBase;
|
||||
|
||||
/**
|
||||
@ -133,7 +117,7 @@ class ConfigSetting : public ConfigSettingBase {
|
||||
T value,
|
||||
ConfigSettingManager* configSettingManager)
|
||||
: ConfigSettingBase(key, configSettingManager) {
|
||||
getSlot(ConfigSource::DEFAULT).emplace(std::move(value));
|
||||
getSlot(ConfigSource::Default).emplace(std::move(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,7 +164,7 @@ class ConfigSetting : public ConfigSettingBase {
|
||||
folly::StringPiece stringValue,
|
||||
const std::map<std::string, std::string>& attrMap,
|
||||
ConfigSource newSource) override {
|
||||
if (newSource == ConfigSource::DEFAULT) {
|
||||
if (newSource == ConfigSource::Default) {
|
||||
return folly::makeUnexpected<std::string>(
|
||||
"Convert ignored for default value");
|
||||
}
|
||||
@ -194,15 +178,15 @@ class ConfigSetting : public ConfigSettingBase {
|
||||
* Set the value with the identified source.
|
||||
*/
|
||||
void setValue(T newVal, ConfigSource newSource, bool force = false) {
|
||||
if (force || newSource != ConfigSource::DEFAULT) {
|
||||
if (force || newSource != ConfigSource::Default) {
|
||||
getSlot(newSource).emplace(std::move(newVal));
|
||||
}
|
||||
}
|
||||
|
||||
/** Clear the value for the passed ConfigSource. The operation will be
|
||||
* ignored for ConfigSource::DEFAULT. */
|
||||
* ignored for ConfigSource::Default. */
|
||||
void clearValue(ConfigSource source) override {
|
||||
if (source != ConfigSource::DEFAULT && getSlot(source).has_value()) {
|
||||
if (source != ConfigSource::Default && getSlot(source).has_value()) {
|
||||
getSlot(source).reset();
|
||||
}
|
||||
}
|
||||
@ -210,6 +194,9 @@ class ConfigSetting : public ConfigSettingBase {
|
||||
virtual ~ConfigSetting() {}
|
||||
|
||||
private:
|
||||
static constexpr size_t kConfigSourceLastIndex =
|
||||
static_cast<size_t>(apache::thrift::TEnumTraits<ConfigSource>::max());
|
||||
|
||||
std::optional<T>& getSlot(ConfigSource source) {
|
||||
return configValueArray_[static_cast<size_t>(source)];
|
||||
}
|
||||
@ -221,14 +208,14 @@ class ConfigSetting : public ConfigSettingBase {
|
||||
* Get the index of the highest priority source that is populated.
|
||||
*/
|
||||
size_t getHighestPriorityIdx() const {
|
||||
for (auto idx = static_cast<size_t>(kConfigSourceLastIndex);
|
||||
idx > static_cast<size_t>(ConfigSource::DEFAULT);
|
||||
for (auto idx = kConfigSourceLastIndex;
|
||||
idx > static_cast<size_t>(ConfigSource::Default);
|
||||
--idx) {
|
||||
if (configValueArray_[idx].has_value()) {
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
return static_cast<size_t>(ConfigSource::DEFAULT);
|
||||
return static_cast<size_t>(ConfigSource::Default);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,13 +47,13 @@ namespace eden {
|
||||
|
||||
std::string EdenConfig::toString(facebook::eden::ConfigSource cs) const {
|
||||
switch (cs) {
|
||||
case ConfigSource::DEFAULT:
|
||||
case ConfigSource::Default:
|
||||
return "default";
|
||||
case ConfigSource::COMMAND_LINE:
|
||||
case ConfigSource::CommandLine:
|
||||
return "command-line";
|
||||
case ConfigSource::USER_CONFIG_FILE:
|
||||
case ConfigSource::UserConfig:
|
||||
return userConfigPath_.c_str();
|
||||
case ConfigSource::SYSTEM_CONFIG_FILE:
|
||||
case ConfigSource::SystemConfig:
|
||||
return systemConfigPath_.c_str();
|
||||
}
|
||||
throw std::invalid_argument(
|
||||
@ -119,12 +119,12 @@ EdenConfig::EdenConfig(
|
||||
systemConfigDir_(systemConfigDir) {
|
||||
// Force set defaults that require passed arguments
|
||||
edenDir_.setValue(
|
||||
userHomePath_ + kDefaultEdenDirectory, ConfigSource::DEFAULT, true);
|
||||
userHomePath_ + kDefaultEdenDirectory, ConfigSource::Default, true);
|
||||
userIgnoreFile_.setValue(
|
||||
userHomePath + kDefaultUserIgnoreFile, ConfigSource::DEFAULT, true);
|
||||
userHomePath + kDefaultUserIgnoreFile, ConfigSource::Default, true);
|
||||
systemIgnoreFile_.setValue(
|
||||
systemConfigDir_ + kDefaultSystemIgnoreFile, ConfigSource::DEFAULT, true);
|
||||
clientCertificate_.setValue(kUnspecifiedDefault, ConfigSource::DEFAULT, true);
|
||||
systemConfigDir_ + kDefaultSystemIgnoreFile, ConfigSource::Default, true);
|
||||
clientCertificate_.setValue(kUnspecifiedDefault, ConfigSource::Default, true);
|
||||
}
|
||||
|
||||
EdenConfig::EdenConfig(const EdenConfig& source) {
|
||||
@ -335,17 +335,14 @@ static void getConfigStat(
|
||||
}
|
||||
|
||||
void EdenConfig::loadSystemConfig() {
|
||||
clearAll(ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
clearAll(ConfigSource::SystemConfig);
|
||||
loadConfig(
|
||||
systemConfigPath_,
|
||||
ConfigSource::SYSTEM_CONFIG_FILE,
|
||||
&systemConfigFileStat_);
|
||||
systemConfigPath_, ConfigSource::SystemConfig, &systemConfigFileStat_);
|
||||
}
|
||||
|
||||
void EdenConfig::loadUserConfig() {
|
||||
clearAll(ConfigSource::USER_CONFIG_FILE);
|
||||
loadConfig(
|
||||
userConfigPath_, ConfigSource::USER_CONFIG_FILE, &userConfigFileStat_);
|
||||
clearAll(ConfigSource::UserConfig);
|
||||
loadConfig(userConfigPath_, ConfigSource::UserConfig, &userConfigFileStat_);
|
||||
}
|
||||
|
||||
void EdenConfig::loadConfig(
|
||||
|
26
eden/fs/config/eden_config.thrift
Normal file
26
eden/fs/config/eden_config.thrift
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2016-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace cpp2 facebook.eden
|
||||
namespace java com.facebook.eden.thrift
|
||||
namespace py facebook.eden.eden_config
|
||||
|
||||
/**
|
||||
* ConfigSource identifies the point of origin of a config setting.
|
||||
* It is ordered from low to high precedence. Higher precedence
|
||||
* configuration values over-ride lower precedence values. A config
|
||||
* setting of CommandLine takes precedence over all other settings.
|
||||
*/
|
||||
enum ConfigSource {
|
||||
Default = 0
|
||||
SystemConfig = 1
|
||||
UserConfig = 2
|
||||
CommandLine = 3
|
||||
}
|
@ -27,7 +27,7 @@ TEST(ConfigSettingTest, initStateCheck) {
|
||||
|
||||
// Initial should be default
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getConfigKey(), dirKey);
|
||||
}
|
||||
|
||||
@ -39,16 +39,16 @@ TEST(ConfigSettingTest, configSetStringValue) {
|
||||
folly::StringPiece systemConfigDir{"/SYSTEM_CONFIG_SETTING"};
|
||||
std::map<std::string, std::string> attrMap;
|
||||
auto rslt = testDir.setStringValue(
|
||||
systemConfigDir, attrMap, ConfigSource::USER_CONFIG_FILE);
|
||||
systemConfigDir, attrMap, ConfigSource::UserConfig);
|
||||
EXPECT_EQ(rslt.hasError(), false);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::USER_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::UserConfig);
|
||||
EXPECT_EQ(testDir.getValue(), systemConfigDir);
|
||||
|
||||
folly::StringPiece userConfigDir{"/USER_CONFIG_SETTING"};
|
||||
rslt = testDir.setStringValue(
|
||||
userConfigDir, attrMap, ConfigSource::USER_CONFIG_FILE);
|
||||
rslt =
|
||||
testDir.setStringValue(userConfigDir, attrMap, ConfigSource::UserConfig);
|
||||
EXPECT_EQ(rslt.hasError(), false);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::USER_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::UserConfig);
|
||||
EXPECT_EQ(testDir.getValue(), userConfigDir);
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ TEST(ConfigSettingTest, configSetAssign) {
|
||||
|
||||
// Check the copy states first, so we know where starting point is.
|
||||
EXPECT_EQ(copyOfTestDir.getConfigKey(), otherKey);
|
||||
EXPECT_EQ(copyOfTestDir.getSource(), ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(copyOfTestDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(copyOfTestDir.getValue(), otherDir);
|
||||
|
||||
auto dirKey = "dirKey"_sp;
|
||||
@ -72,11 +72,11 @@ TEST(ConfigSettingTest, configSetAssign) {
|
||||
|
||||
std::map<std::string, std::string> attrMap;
|
||||
auto rslt = testDir.setStringValue(
|
||||
systemConfigDir, attrMap, ConfigSource::USER_CONFIG_FILE);
|
||||
systemConfigDir, attrMap, ConfigSource::UserConfig);
|
||||
EXPECT_EQ(rslt.hasError(), false);
|
||||
|
||||
EXPECT_EQ(testDir.getConfigKey(), dirKey);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::USER_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::UserConfig);
|
||||
EXPECT_EQ(testDir.getValue(), systemConfigDir);
|
||||
|
||||
copyOfTestDir.copyFrom(testDir);
|
||||
@ -84,11 +84,11 @@ TEST(ConfigSettingTest, configSetAssign) {
|
||||
|
||||
// Check all attributes copied.
|
||||
EXPECT_EQ(copyOfTestDir.getConfigKey(), dirKey);
|
||||
EXPECT_EQ(copyOfTestDir.getSource(), ConfigSource::USER_CONFIG_FILE);
|
||||
EXPECT_EQ(copyOfTestDir.getSource(), ConfigSource::UserConfig);
|
||||
EXPECT_EQ(copyOfTestDir.getValue(), systemConfigDir);
|
||||
|
||||
// Check references still valid
|
||||
copyOfTestDir.clearValue(ConfigSource::DEFAULT);
|
||||
copyOfTestDir.clearValue(ConfigSource::Default);
|
||||
}
|
||||
|
||||
TEST(ConfigSettingTest, configSetInvalidStringValue) {
|
||||
@ -99,19 +99,19 @@ TEST(ConfigSettingTest, configSetInvalidStringValue) {
|
||||
folly::StringPiece systemConfigDir{"/SYSTEM_CONFIG_SETTING"};
|
||||
std::map<std::string, std::string> attrMap;
|
||||
auto rslt = testDir.setStringValue(
|
||||
systemConfigDir, attrMap, ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
systemConfigDir, attrMap, ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(rslt.hasError(), false);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getValue(), systemConfigDir);
|
||||
|
||||
folly::StringPiece userConfigDir{"INVALID USER_CONFIG_SETTING"};
|
||||
rslt = testDir.setStringValue(
|
||||
userConfigDir, attrMap, ConfigSource::USER_CONFIG_FILE);
|
||||
rslt =
|
||||
testDir.setStringValue(userConfigDir, attrMap, ConfigSource::UserConfig);
|
||||
EXPECT_EQ(rslt.hasError(), true);
|
||||
EXPECT_EQ(
|
||||
rslt.error(),
|
||||
"Cannot convert value 'INVALID USER_CONFIG_SETTING' to an absolute path");
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getValue(), systemConfigDir);
|
||||
}
|
||||
|
||||
@ -124,17 +124,17 @@ TEST(ConfigSettingTest, configSetEnvSubTest) {
|
||||
std::map<std::string, std::string> attrMap;
|
||||
attrMap["HOME"] = "/home/bob";
|
||||
attrMap["USER"] = "bob";
|
||||
auto rslt = testDir.setStringValue(
|
||||
userConfigDir, attrMap, ConfigSource::USER_CONFIG_FILE);
|
||||
auto rslt =
|
||||
testDir.setStringValue(userConfigDir, attrMap, ConfigSource::UserConfig);
|
||||
EXPECT_EQ(rslt.hasError(), false);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::USER_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::UserConfig);
|
||||
EXPECT_EQ(testDir.getValue(), "/home/bob/test_dir");
|
||||
|
||||
folly::StringPiece homeUserConfigDir{"/home/${USER}/test_dir"};
|
||||
rslt = testDir.setStringValue(
|
||||
homeUserConfigDir, attrMap, ConfigSource::USER_CONFIG_FILE);
|
||||
homeUserConfigDir, attrMap, ConfigSource::UserConfig);
|
||||
EXPECT_EQ(rslt.hasError(), false);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::USER_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::UserConfig);
|
||||
EXPECT_EQ(testDir.getValue(), "/home/bob/test_dir");
|
||||
}
|
||||
|
||||
@ -144,17 +144,17 @@ TEST(ConfigSettingTest, configSettingIgnoreDefault) {
|
||||
ConfigSetting<AbsolutePath> testDir{dirKey, defaultDir, nullptr};
|
||||
// Initial should be default
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
|
||||
// Setting default value should be ignored
|
||||
AbsolutePath notDefaultDir{"/NOT_THE_DEFAULT_DIR"};
|
||||
testDir.setValue(notDefaultDir, ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
testDir.setValue(notDefaultDir, ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
|
||||
// Clearing the default value should be ignored
|
||||
testDir.clearValue(ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
testDir.clearValue(ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
}
|
||||
|
||||
@ -164,15 +164,15 @@ TEST(ConfigSettingTest, configSettingClearNonExistingSource) {
|
||||
ConfigSetting<AbsolutePath> testDir{dirKey, defaultDir, nullptr};
|
||||
|
||||
// Initially, it should be default value
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
|
||||
// Clear unset priorities
|
||||
testDir.clearValue(ConfigSource::COMMAND_LINE);
|
||||
testDir.clearValue(ConfigSource::USER_CONFIG_FILE);
|
||||
testDir.clearValue(ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
testDir.clearValue(ConfigSource::DEFAULT);
|
||||
testDir.clearValue(ConfigSource::CommandLine);
|
||||
testDir.clearValue(ConfigSource::UserConfig);
|
||||
testDir.clearValue(ConfigSource::SystemConfig);
|
||||
testDir.clearValue(ConfigSource::Default);
|
||||
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
}
|
||||
|
||||
@ -184,17 +184,17 @@ TEST(ConfigSettingTest, configSettingSetAndClearTest) {
|
||||
AbsolutePath systemEdenDir{"/SYSTEM_DIR"};
|
||||
|
||||
// Initially, it should be default value
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
|
||||
// Over-ride default
|
||||
testDir.setValue(systemEdenDir, ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
testDir.setValue(systemEdenDir, ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getValue(), systemEdenDir);
|
||||
|
||||
// Clear the over-ride
|
||||
testDir.clearValue(ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
testDir.clearValue(ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
}
|
||||
|
||||
@ -207,21 +207,21 @@ TEST(ConfigSettingTest, configSetOverRiddenSource) {
|
||||
AbsolutePath systemEdenDir{"/SYSTEM_DIR"};
|
||||
|
||||
// Initially, it should be default value
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
|
||||
// Set the highest priority item
|
||||
testDir.setValue(cliEdenDir, ConfigSource::COMMAND_LINE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::COMMAND_LINE);
|
||||
testDir.setValue(cliEdenDir, ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getValue(), cliEdenDir);
|
||||
|
||||
// Set a middle priority item (results same as above)
|
||||
testDir.setValue(systemEdenDir, ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::COMMAND_LINE);
|
||||
testDir.setValue(systemEdenDir, ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getValue(), cliEdenDir);
|
||||
|
||||
// Clear current highest priority
|
||||
testDir.clearValue(ConfigSource::COMMAND_LINE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
testDir.clearValue(ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getValue(), systemEdenDir);
|
||||
}
|
||||
|
||||
@ -235,36 +235,36 @@ TEST(ConfigSettingTest, configClearOverRiddenSource) {
|
||||
AbsolutePath systemEdenDir{"/SYSTEM_DIR"};
|
||||
|
||||
// Initially, it should be default value
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
|
||||
// Set next higher over-ride priority
|
||||
testDir.setValue(systemEdenDir, ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
testDir.setValue(systemEdenDir, ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getValue(), systemEdenDir);
|
||||
|
||||
// Set next higher over-ride priority
|
||||
testDir.setValue(userEdenDir, ConfigSource::USER_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::USER_CONFIG_FILE);
|
||||
testDir.setValue(userEdenDir, ConfigSource::UserConfig);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::UserConfig);
|
||||
EXPECT_EQ(testDir.getValue(), userEdenDir);
|
||||
|
||||
// Set next higher over-ride priority
|
||||
testDir.setValue(cliEdenDir, ConfigSource::COMMAND_LINE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::COMMAND_LINE);
|
||||
testDir.setValue(cliEdenDir, ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getValue(), cliEdenDir);
|
||||
|
||||
// Clear the middle priority item (no effect on source/value)
|
||||
testDir.clearValue(ConfigSource::USER_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::COMMAND_LINE);
|
||||
testDir.clearValue(ConfigSource::UserConfig);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getValue(), cliEdenDir);
|
||||
|
||||
// Clear the middle priority item (no effect on source/value)
|
||||
testDir.clearValue(ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::COMMAND_LINE);
|
||||
testDir.clearValue(ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getValue(), cliEdenDir);
|
||||
|
||||
// Clear highest priority - back to default
|
||||
testDir.clearValue(ConfigSource::COMMAND_LINE);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::DEFAULT);
|
||||
testDir.clearValue(ConfigSource::CommandLine);
|
||||
EXPECT_EQ(testDir.getSource(), ConfigSource::Default);
|
||||
EXPECT_EQ(testDir.getValue(), defaultDir);
|
||||
}
|
||||
|
@ -149,12 +149,12 @@ TEST_F(EdenConfigTest, simpleSetGetTest) {
|
||||
edenConfig->setSystemConfigPath(updatedSystemConfigPath);
|
||||
|
||||
// Configuration
|
||||
edenConfig->setUserIgnoreFile(ignoreFile, ConfigSource::COMMAND_LINE);
|
||||
edenConfig->setSystemIgnoreFile(systemIgnoreFile, ConfigSource::COMMAND_LINE);
|
||||
edenConfig->setEdenDir(edenDir, ConfigSource::COMMAND_LINE);
|
||||
edenConfig->setUserIgnoreFile(ignoreFile, ConfigSource::CommandLine);
|
||||
edenConfig->setSystemIgnoreFile(systemIgnoreFile, ConfigSource::CommandLine);
|
||||
edenConfig->setEdenDir(edenDir, ConfigSource::CommandLine);
|
||||
edenConfig->setClientCertificate(
|
||||
clientCertificate, ConfigSource::COMMAND_LINE);
|
||||
edenConfig->setUseMononoke(useMononoke, ConfigSource::COMMAND_LINE);
|
||||
clientCertificate, ConfigSource::CommandLine);
|
||||
edenConfig->setUseMononoke(useMononoke, ConfigSource::CommandLine);
|
||||
|
||||
// Config path
|
||||
EXPECT_EQ(edenConfig->getUserConfigPath(), updatedUserConfigPath);
|
||||
@ -192,13 +192,13 @@ TEST_F(EdenConfigTest, cloneTest) {
|
||||
systemConfigPath);
|
||||
|
||||
// Configuration
|
||||
edenConfig->setUserIgnoreFile(ignoreFile, ConfigSource::COMMAND_LINE);
|
||||
edenConfig->setUserIgnoreFile(ignoreFile, ConfigSource::CommandLine);
|
||||
edenConfig->setSystemIgnoreFile(
|
||||
systemIgnoreFile, ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
edenConfig->setEdenDir(edenDir, ConfigSource::USER_CONFIG_FILE);
|
||||
systemIgnoreFile, ConfigSource::SystemConfig);
|
||||
edenConfig->setEdenDir(edenDir, ConfigSource::UserConfig);
|
||||
edenConfig->setClientCertificate(
|
||||
clientCertificate, ConfigSource::USER_CONFIG_FILE);
|
||||
edenConfig->setUseMononoke(useMononoke, ConfigSource::USER_CONFIG_FILE);
|
||||
clientCertificate, ConfigSource::UserConfig);
|
||||
edenConfig->setUseMononoke(useMononoke, ConfigSource::UserConfig);
|
||||
|
||||
EXPECT_EQ(edenConfig->getUserName(), testUser_);
|
||||
EXPECT_EQ(edenConfig->getUserID(), userID);
|
||||
@ -227,9 +227,9 @@ TEST_F(EdenConfigTest, cloneTest) {
|
||||
EXPECT_EQ(configCopy->getClientCertificate(), clientCertificate);
|
||||
EXPECT_EQ(configCopy->getUseMononoke(), useMononoke);
|
||||
|
||||
configCopy->clearAll(ConfigSource::USER_CONFIG_FILE);
|
||||
configCopy->clearAll(ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
configCopy->clearAll(ConfigSource::COMMAND_LINE);
|
||||
configCopy->clearAll(ConfigSource::UserConfig);
|
||||
configCopy->clearAll(ConfigSource::SystemConfig);
|
||||
configCopy->clearAll(ConfigSource::CommandLine);
|
||||
|
||||
EXPECT_EQ(configCopy->getUserIgnoreFile(), defaultUserIgnoreFilePath_);
|
||||
EXPECT_EQ(configCopy->getSystemIgnoreFile(), defaultSystemIgnoreFilePath_);
|
||||
@ -257,34 +257,32 @@ TEST_F(EdenConfigTest, clearAllTest) {
|
||||
|
||||
// We will set the config on 3 properties, each with different sources
|
||||
// We will then run for each source to check results
|
||||
edenConfig->setUserIgnoreFile(
|
||||
fromUserConfigPath, ConfigSource::USER_CONFIG_FILE);
|
||||
edenConfig->setUserIgnoreFile(fromUserConfigPath, ConfigSource::UserConfig);
|
||||
edenConfig->setSystemIgnoreFile(
|
||||
fromSystemConfigPath, ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
edenConfig->setEdenDir(fromCommandLine, ConfigSource::COMMAND_LINE);
|
||||
edenConfig->setEdenDir(fromUserConfigPath, ConfigSource::USER_CONFIG_FILE);
|
||||
edenConfig->setEdenDir(
|
||||
fromSystemConfigPath, ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
fromSystemConfigPath, ConfigSource::SystemConfig);
|
||||
edenConfig->setEdenDir(fromCommandLine, ConfigSource::CommandLine);
|
||||
edenConfig->setEdenDir(fromUserConfigPath, ConfigSource::UserConfig);
|
||||
edenConfig->setEdenDir(fromSystemConfigPath, ConfigSource::SystemConfig);
|
||||
|
||||
// Check over-rides
|
||||
EXPECT_EQ(edenConfig->getUserIgnoreFile(), fromUserConfigPath);
|
||||
EXPECT_EQ(edenConfig->getSystemIgnoreFile(), fromSystemConfigPath);
|
||||
EXPECT_EQ(edenConfig->getEdenDir(), fromCommandLine);
|
||||
|
||||
// Clear USER_CONFIG_FILE and check
|
||||
edenConfig->clearAll(ConfigSource::USER_CONFIG_FILE);
|
||||
// Clear UserConfig and check
|
||||
edenConfig->clearAll(ConfigSource::UserConfig);
|
||||
EXPECT_EQ(edenConfig->getUserIgnoreFile(), defaultUserIgnoreFilePath_);
|
||||
EXPECT_EQ(edenConfig->getSystemIgnoreFile(), fromSystemConfigPath);
|
||||
EXPECT_EQ(edenConfig->getEdenDir(), fromCommandLine);
|
||||
|
||||
// Clear SYSTEM_CONFIG_FILE and check
|
||||
edenConfig->clearAll(ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
// Clear SystemConfig and check
|
||||
edenConfig->clearAll(ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(edenConfig->getUserIgnoreFile(), defaultUserIgnoreFilePath_);
|
||||
EXPECT_EQ(edenConfig->getSystemIgnoreFile(), defaultSystemIgnoreFilePath_);
|
||||
EXPECT_EQ(edenConfig->getEdenDir(), fromCommandLine);
|
||||
|
||||
// Clear COMMAND_LINE and check
|
||||
edenConfig->clearAll(ConfigSource::COMMAND_LINE);
|
||||
// Clear CommandLine and check
|
||||
edenConfig->clearAll(ConfigSource::CommandLine);
|
||||
EXPECT_EQ(edenConfig->getUserIgnoreFile(), defaultUserIgnoreFilePath_);
|
||||
EXPECT_EQ(edenConfig->getSystemIgnoreFile(), defaultSystemIgnoreFilePath_);
|
||||
EXPECT_EQ(edenConfig->getEdenDir(), defaultEdenDirPath_);
|
||||
@ -311,14 +309,13 @@ TEST_F(EdenConfigTest, overRideNotAllowedTest) {
|
||||
AbsolutePath ignoreFile{"/USER_IGNORE_FILE"};
|
||||
AbsolutePath systemIgnoreFile{"/SYSTEM_IGNORE_FILE"};
|
||||
|
||||
edenConfig->setUserIgnoreFile(cliIgnoreFile, ConfigSource::COMMAND_LINE);
|
||||
edenConfig->setUserIgnoreFile(cliIgnoreFile, ConfigSource::CommandLine);
|
||||
EXPECT_EQ(edenConfig->getUserIgnoreFile(), cliIgnoreFile);
|
||||
|
||||
edenConfig->setUserIgnoreFile(
|
||||
cliIgnoreFile, ConfigSource::SYSTEM_CONFIG_FILE);
|
||||
edenConfig->setUserIgnoreFile(cliIgnoreFile, ConfigSource::SystemConfig);
|
||||
EXPECT_EQ(edenConfig->getUserIgnoreFile(), cliIgnoreFile);
|
||||
|
||||
edenConfig->setUserIgnoreFile(ignoreFile, ConfigSource::USER_CONFIG_FILE);
|
||||
edenConfig->setUserIgnoreFile(ignoreFile, ConfigSource::UserConfig);
|
||||
EXPECT_EQ(edenConfig->getUserIgnoreFile(), cliIgnoreFile);
|
||||
}
|
||||
|
||||
|
@ -44,11 +44,11 @@ void findEdenDir(EdenConfig& config) {
|
||||
boost::filesystem::create_directories(boostPath);
|
||||
auto resolvedDir = facebook::eden::realpath(boostPath.string());
|
||||
|
||||
// Updating the value in the config using ConfigSource COMMAND_LINE also
|
||||
// Updating the value in the config using ConfigSource::CommandLine also
|
||||
// makes sure that any future updates to the config file do not affect the
|
||||
// value we use. Once we start we want to always use a fixed location for
|
||||
// the eden directory.
|
||||
config.setEdenDir(resolvedDir, ConfigSource::COMMAND_LINE);
|
||||
config.setEdenDir(resolvedDir, ConfigSource::CommandLine);
|
||||
} catch (const std::exception& ex) {
|
||||
throw ArgumentError(
|
||||
"error creating ", boostPath.string(), ": ", folly::exceptionStr(ex));
|
||||
|
@ -68,7 +68,7 @@ unique_ptr<EdenServer> TestServer::createServer(AbsolutePathPiece tmpDir) {
|
||||
tmpDir + "etc"_pc,
|
||||
tmpDir + "etc/edenfs.rc"_relpath);
|
||||
auto privHelper = make_unique<FakePrivHelper>();
|
||||
config->setEdenDir(edenDir, ConfigSource::COMMAND_LINE);
|
||||
config->setEdenDir(edenDir, ConfigSource::CommandLine);
|
||||
|
||||
return make_unique<EdenServer>(userInfo, std::move(privHelper), config);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user