Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct test of OptionsImpl argc type (Was: Correct type for std::array size() result) #9290

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions source/server/options_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

namespace Envoy {
namespace {
std::vector<std::string> toArgsVector(std::size_t argc, const char* const* argv) {
std::vector<std::string> toArgsVector(int argc, const char* const* argv) {
std::vector<std::string> args;
for (size_t i = 0; i < argc; ++i) {
for (int i = 0; i < argc; ++i) {
args.emplace_back(argv[i]);
}
return args;
}
} // namespace

OptionsImpl::OptionsImpl(std::size_t argc, const char* const* argv,
OptionsImpl::OptionsImpl(int argc, const char* const* argv,
const HotRestartVersionCb& hot_restart_version_cb,
spdlog::level::level_enum default_log_level)
: OptionsImpl(toArgsVector(argc, argv), hot_restart_version_cb, default_log_level) {}
Expand Down
3 changes: 1 addition & 2 deletions source/server/options_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class OptionsImpl : public Server::Options, protected Logger::Loggable<Logger::I
* @throw MalformedArgvException if something is wrong with the arguments (invalid flag or flag
* value). The caller should call exit(1) after any necessary cleanup.
*/
OptionsImpl(std::size_t argc, const char* const* argv,
const HotRestartVersionCb& hot_restart_version_cb,
OptionsImpl(int argc, const char* const* argv, const HotRestartVersionCb& hot_restart_version_cb,
spdlog::level::level_enum default_log_level);

/**
Expand Down
4 changes: 2 additions & 2 deletions test/server/options_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ TEST_F(OptionsImplTest, OptionsAreInSyncWithProto) {
TEST_F(OptionsImplTest, OptionsFromArgv) {
const std::array<const char*, 3> args{"envoy", "-c", "hello"};
std::unique_ptr<OptionsImpl> options = std::make_unique<OptionsImpl>(
args.size(), args.data(), [](bool) { return "1"; }, spdlog::level::warn);
static_cast<int>(args.size()), args.data(), [](bool) { return "1"; }, spdlog::level::warn);
wrowe marked this conversation as resolved.
Show resolved Hide resolved
// Spot check that the arguments were parsed.
EXPECT_EQ("hello", options->configPath());
}

TEST_F(OptionsImplTest, OptionsFromArgvPrefix) {
const std::array<const char*, 5> args{"envoy", "-c", "hello", "--admin-address-path", "goodbye"};
std::unique_ptr<OptionsImpl> options = std::make_unique<OptionsImpl>(
args.size() - 2, // Pass in only a prefix of the args
static_cast<int>(args.size()) - 2, // Pass in only a prefix of the args
args.data(), [](bool) { return "1"; }, spdlog::level::warn);
EXPECT_EQ("hello", options->configPath());
// This should still have the default value since the extra arguments are
Expand Down