Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ int Configuration::ParseArguments(int ac, char** av) {
"Enable verbose logging")
("option,o",
boost::program_options::value<std::vector<std::string>>()
->multitoken()->zero_tokens()->composing(),
->composing(),
"Explicit configuration option, e.g. "
"-o CredentialsFile=/tmp/token.json")
"-o CredentialsFile=/tmp/token.json "
"(can be specified multiple times)")
;
boost::program_options::options_description hidden_desc;
hidden_desc.add_options()
Expand Down Expand Up @@ -174,7 +175,7 @@ int Configuration::ParseArguments(int ac, char** av) {
std::stringstream option_stream;
const std::vector<std::string> options =
flags["option"].as<std::vector<std::string>>();
for (const std::string& option: options) {
for (const std::string& option : options) {
std::size_t separator_pos = option.find("=");
if (separator_pos == std::string::npos) {
std::cerr << "Invalid option " << option;
Expand Down Expand Up @@ -278,10 +279,10 @@ void Configuration::ParseConfiguration(std::istream& input) {
config["KubernetesUseWatch"].as<bool>(kubernetes_use_watch_);
kubernetes_cluster_level_metadata_ =
config["KubernetesClusterLevelMetadata"].as<bool>(
kKubernetesDefaultClusterLevelMetadata);
kubernetes_cluster_level_metadata_);
kubernetes_service_metadata_ =
config["KubernetesServiceMetadata"].as<bool>(
kKubernetesDefaultServiceMetadata);
kubernetes_service_metadata_);
instance_id_ =
config["InstanceId"].as<std::string>(instance_id_);
instance_zone_ =
Expand Down
1 change: 1 addition & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class Configuration {
}

private:
friend class ConfigurationArgumentParserTest;
friend int ::main(int, char**); // Calls ParseArguments.

void ParseConfigFile(const std::string& filename);
Expand Down
31 changes: 31 additions & 0 deletions test/configuration_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,35 @@ TEST(ConfigurationTest, BlankLine) {
EXPECT_EQ(true, config.MetadataReporterPurgeDeleted());
}

class ConfigurationArgumentParserTest : public ::testing::Test {
protected:
static int ParseArguments(Configuration* config, int ac, char** av) {
return config->ParseArguments(ac, av);
}
};

TEST_F(ConfigurationArgumentParserTest, CommandLineOverride) {
Configuration config(std::istringstream(
"ProjectId: TestProjectId\n"
"MetadataApiNumThreads: 13\n"
));
// First, a sanity check.
EXPECT_EQ("TestProjectId", config.ProjectId());
EXPECT_EQ(13, config.MetadataApiNumThreads());
EXPECT_EQ(false, config.MetadataReporterPurgeDeleted());

char* arguments[] = {
"/path/to/metadatad",
"-o",
"ProjectId=NewProjectId",
"-o",
"MetadataReporterPurgeDeleted=true",
};
ParseArguments(&config, sizeof(arguments) / sizeof(char*), arguments);

EXPECT_EQ("NewProjectId", config.ProjectId());
EXPECT_EQ(13, config.MetadataApiNumThreads());
EXPECT_EQ(true, config.MetadataReporterPurgeDeleted());
}

} // namespace google