From c2213689c4ccce6b99d8c70d7d4b051d6a2303e5 Mon Sep 17 00:00:00 2001 From: Otto van der Schaaf Date: Sun, 14 Feb 2021 12:30:55 +0100 Subject: [PATCH] clang-tidy: address complaints Fixes #629 Signed-off-by: Otto van der Schaaf --- .../adaptive_load_client_main.cc | 16 ++--- .../adaptive_load_client_main_test.cc | 68 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/source/adaptive_load/adaptive_load_client_main.cc b/source/adaptive_load/adaptive_load_client_main.cc index b28c2ebf5..be23d1051 100644 --- a/source/adaptive_load/adaptive_load_client_main.cc +++ b/source/adaptive_load/adaptive_load_client_main.cc @@ -65,29 +65,29 @@ AdaptiveLoadClientMain::AdaptiveLoadClientMain(int argc, const char* const* argv AdaptiveLoadController& controller, Envoy::Filesystem::Instance& filesystem) : controller_{controller}, filesystem_{filesystem} { - TCLAP::CmdLine cmd("Adaptive Load tool that finds the optimal load on the target " + TCLAP::CmdLine cmd("Adaptive Load tool that finds the optimal load on the target " // NOLINT "through a series of Nighthawk Service benchmarks.", /*delimiter=*/' ', VersionInfo::version()); TCLAP::ValueArg nighthawk_service_address( - /*flag_name=*/"", "nighthawk-service-address", + /*flag=*/"", "nighthawk-service-address", "host:port for Nighthawk Service. To enable TLS, set --use-tls.", - /*required=*/false, "localhost:8443", "string", cmd); + /*req=*/false, "localhost:8443", "string", cmd); TCLAP::SwitchArg use_tls( - /*flag_name=*/"", "use-tls", + /*flag=*/"", "use-tls", "Use TLS for the gRPC connection from this program to the Nighthawk Service. Set environment " "variable GRPC_DEFAULT_SSL_ROOTS_FILE_PATH to override the default root certificates.", cmd); TCLAP::ValueArg spec_filename( - /*flag_name=*/"", "spec-file", + /*flag=*/"", "spec-file", "Path to a textproto file describing the adaptive load session " "(nighthawk::adaptive_load::AdaptiveLoadSessionSpec).", - /*required=*/true, /*default_value=*/"", "string", cmd); + /*req=*/true, /*val=*/"", "string", cmd); TCLAP::ValueArg output_filename( - /*flag_name=*/"", "output-file", + /*flag=*/"", "output-file", "Path to write adaptive load session output textproto " "(nighthawk::adaptive_load::AdaptiveLoadSessionOutput).", - /*required=*/true, /*default_value=*/"", "string", cmd); + /*req=*/true, /*val=*/"", "string", cmd); Nighthawk::Utility::parseCommand(cmd, argc, argv); diff --git a/test/adaptive_load/adaptive_load_client_main_test.cc b/test/adaptive_load/adaptive_load_client_main_test.cc index 49fee0928..3ecef25bd 100644 --- a/test/adaptive_load/adaptive_load_client_main_test.cc +++ b/test/adaptive_load/adaptive_load_client_main_test.cc @@ -59,19 +59,19 @@ nighthawk::adaptive_load::AdaptiveLoadSessionOutput MakeBasicAdaptiveLoadSession } TEST(AdaptiveLoadClientMainTest, FailsWithNoInputs) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", }; NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain(1, argv, controller, filesystem), + EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain(1, argv.data(), controller, filesystem), Nighthawk::Client::MalformedArgvException, "Required arguments missing"); } TEST(AdaptiveLoadClientMainTest, FailsIfSpecFileNotSet) { std::string outfile = Nighthawk::TestEnvironment::runfilesPath("unused.textproto"); - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--output-file", outfile.c_str(), @@ -80,14 +80,14 @@ TEST(AdaptiveLoadClientMainTest, FailsIfSpecFileNotSet) { NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain(3, argv, controller, filesystem), + EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain(3, argv.data(), controller, filesystem), Nighthawk::Client::MalformedArgvException, "Required argument missing: spec-file"); } TEST(AdaptiveLoadClientMainTest, FailsIfOutputFileNotSet) { std::string infile = Nighthawk::TestEnvironment::runfilesPath("unused.textproto"); - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", infile.c_str(), @@ -96,7 +96,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfOutputFileNotSet) { NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain main(3, argv, controller, filesystem), + EXPECT_THROW_WITH_REGEX(AdaptiveLoadClientMain main(3, argv.data(), controller, filesystem), Nighthawk::Client::MalformedArgvException, "Required argument missing: output-file"); } @@ -104,14 +104,14 @@ TEST(AdaptiveLoadClientMainTest, FailsIfOutputFileNotSet) { TEST(AdaptiveLoadClientMainTest, FailsWithNonexistentInputFile) { std::string infile = Nighthawk::TestEnvironment::runfilesPath("nonexistent.textproto"); std::string outfile = Nighthawk::TestEnvironment::runfilesPath("unused.textproto"); - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", infile.c_str(), "--output-file", outfile.c_str(), }; NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Failed to read spec textproto file"); } @@ -120,14 +120,14 @@ TEST(AdaptiveLoadClientMainTest, FailsWithUnparseableInputFile) { std::string infile = Nighthawk::TestEnvironment::runfilesPath( "test/adaptive_load/test_data/invalid_session_spec.textproto"); std::string outfile = Nighthawk::TestEnvironment::runfilesPath("unused.textproto"); - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", infile.c_str(), "--output-file", outfile.c_str(), }; NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to parse file"); } @@ -136,7 +136,7 @@ TEST(AdaptiveLoadClientMainTest, ExitsProcessWithNonzeroStatusOnAdaptiveControll "test/adaptive_load/test_data/valid_session_spec.textproto"); std::string outfile = Nighthawk::TestEnvironment::runfilesPath( "test/adaptive_load/test_data/nonexistent-dir/out.textproto"); - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", infile.c_str(), "--output-file", outfile.c_str(), }; @@ -145,7 +145,7 @@ TEST(AdaptiveLoadClientMainTest, ExitsProcessWithNonzeroStatusOnAdaptiveControll .WillOnce(Return(absl::DataLossError("error message"))); Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_EQ(main.Run(), 1); } @@ -154,7 +154,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfCreatingOutputFileFails) { "test/adaptive_load/test_data/valid_session_spec.textproto"); std::string outfile = Nighthawk::TestEnvironment::runfilesPath( "test/adaptive_load/test_data/nonexistent-dir/out.textproto"); - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", infile.c_str(), "--output-file", outfile.c_str(), }; @@ -163,12 +163,12 @@ TEST(AdaptiveLoadClientMainTest, FailsIfCreatingOutputFileFails) { .WillOnce(Return(MakeBasicAdaptiveLoadSessionOutput())); Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to open output file"); } TEST(AdaptiveLoadClientMainTest, FailsIfOpeningOutputFileFails) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", "in-dummy.textproto", "--output-file", "out-dummy.textproto", }; @@ -184,7 +184,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfOpeningOutputFileFails) { std::string("test/adaptive_load/test_data/valid_session_spec.textproto"))); EXPECT_CALL(filesystem, fileReadToEnd(_)).WillOnce(Return(infile_contents)); - NiceMock* mock_file = new NiceMock; + auto* mock_file = new NiceMock; EXPECT_CALL(filesystem, createFile(_)) .WillOnce(Return(ByMove(std::unique_ptr>(mock_file)))); @@ -193,12 +193,12 @@ TEST(AdaptiveLoadClientMainTest, FailsIfOpeningOutputFileFails) { false, Envoy::Api::IoErrorPtr(new UnknownIoError(), [](Envoy::Api::IoError* err) { delete err; }))))); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to open output file"); } TEST(AdaptiveLoadClientMainTest, FailsIfWritingOutputFileFails) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", "in-dummy.textproto", "--output-file", "out-dummy.textproto", }; @@ -214,7 +214,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfWritingOutputFileFails) { std::string("test/adaptive_load/test_data/valid_session_spec.textproto"))); EXPECT_CALL(filesystem, fileReadToEnd(_)).WillOnce(Return(infile_contents)); - NiceMock* mock_file = new NiceMock; + auto* mock_file = new NiceMock; EXPECT_CALL(filesystem, createFile(_)) .WillOnce(Return(ByMove(std::unique_ptr>(mock_file)))); @@ -225,13 +225,13 @@ TEST(AdaptiveLoadClientMainTest, FailsIfWritingOutputFileFails) { .WillOnce(Return(ByMove(Envoy::Api::IoCallSizeResult( -1, Envoy::Api::IoErrorPtr(new UnknownIoError(), [](Envoy::Api::IoError* err) { delete err; }))))); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to write to output file"); } TEST(AdaptiveLoadClientMainTest, FailsIfClosingOutputFileFails) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", "in-dummy.textproto", "--output-file", "out-dummy.textproto", }; @@ -247,7 +247,7 @@ TEST(AdaptiveLoadClientMainTest, FailsIfClosingOutputFileFails) { std::string("test/adaptive_load/test_data/valid_session_spec.textproto"))); EXPECT_CALL(filesystem, fileReadToEnd(_)).WillOnce(Return(infile_contents)); - NiceMock* mock_file = new NiceMock; + auto* mock_file = new NiceMock; EXPECT_CALL(filesystem, createFile(_)) .WillOnce(Return(ByMove(std::unique_ptr>(mock_file)))); @@ -265,12 +265,12 @@ TEST(AdaptiveLoadClientMainTest, FailsIfClosingOutputFileFails) { false, Envoy::Api::IoErrorPtr(new UnknownIoError(), [](Envoy::Api::IoError* err) { delete err; }))))); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_THROW_WITH_REGEX(main.Run(), Nighthawk::NighthawkException, "Unable to close output file"); } TEST(AdaptiveLoadClientMainTest, WritesOutputProtoToFile) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", "in-dummy.textproto", "--output-file", "out-dummy.textproto", }; @@ -287,7 +287,7 @@ TEST(AdaptiveLoadClientMainTest, WritesOutputProtoToFile) { EXPECT_CALL(filesystem, fileReadToEnd(_)).WillOnce(Return(infile_contents)); std::string actual_outfile_contents; - NiceMock* mock_file = new NiceMock; + auto* mock_file = new NiceMock; EXPECT_CALL(filesystem, createFile(_)) .WillOnce(Return(ByMove(std::unique_ptr>(mock_file)))); @@ -307,7 +307,7 @@ TEST(AdaptiveLoadClientMainTest, WritesOutputProtoToFile) { .WillOnce(Return(ByMove(Envoy::Api::IoCallBoolResult( true, Envoy::Api::IoErrorPtr(nullptr, [](Envoy::Api::IoError*) {}))))); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); main.Run(); std::string golden_output = @@ -317,46 +317,46 @@ TEST(AdaptiveLoadClientMainTest, WritesOutputProtoToFile) { } TEST(AdaptiveLoadClientMainTest, DefaultsToInsecureConnection) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", "a", "--output-file", "b", }; NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_THAT(main.DescribeInputs(), HasSubstr("insecure")); } TEST(AdaptiveLoadClientMainTest, UsesTlsConnectionWhenSpecified) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--use-tls", "--spec-file", "a", "--output-file", "b", }; NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - AdaptiveLoadClientMain main(6, argv, controller, filesystem); + AdaptiveLoadClientMain main(6, argv.data(), controller, filesystem); EXPECT_THAT(main.DescribeInputs(), HasSubstr("TLS")); } TEST(AdaptiveLoadClientMainTest, UsesDefaultNighthawkServiceAddress) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--spec-file", "a", "--output-file", "b", }; NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - AdaptiveLoadClientMain main(5, argv, controller, filesystem); + AdaptiveLoadClientMain main(5, argv.data(), controller, filesystem); EXPECT_THAT(main.DescribeInputs(), HasSubstr("localhost:8443")); } TEST(AdaptiveLoadClientMainTest, UsesCustomNighthawkServiceAddress) { - const char* const argv[] = { + const std::vector argv = { "executable-name-here", "--nighthawk-service-address", "1.2.3.4:5678", @@ -369,7 +369,7 @@ TEST(AdaptiveLoadClientMainTest, UsesCustomNighthawkServiceAddress) { NiceMock controller; Envoy::Filesystem::Instance& filesystem = Envoy::Filesystem::fileSystemForTest(); - AdaptiveLoadClientMain main(7, argv, controller, filesystem); + AdaptiveLoadClientMain main(7, argv.data(), controller, filesystem); EXPECT_THAT(main.DescribeInputs(), HasSubstr("1.2.3.4:5678")); }