From eeb36bd60dc15c69e4cb4e4a66e43bfdf83fd091 Mon Sep 17 00:00:00 2001 From: Otto van der Schaaf Date: Fri, 18 Sep 2020 00:22:29 +0200 Subject: [PATCH] I forgot the last step, which is to actually teach the output formatter factory when to construct the new formatter. Sorry! - Amends a pre-existing test to avoid regression when adding new output formats in the future - Fix the issue Fixes #543 Signed-off-by: Otto van der Schaaf --- source/client/factories_impl.cc | 2 ++ test/output_transform_main_test.cc | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/source/client/factories_impl.cc b/source/client/factories_impl.cc index ba1cb9e56..6a35458f7 100644 --- a/source/client/factories_impl.cc +++ b/source/client/factories_impl.cc @@ -108,6 +108,8 @@ OutputFormatterPtr OutputFormatterFactoryImpl::create( return std::make_unique(); case nighthawk::client::OutputFormat::FORTIO: return std::make_unique(); + case nighthawk::client::OutputFormat::EXPERIMENTAL_FORTIO_PEDANTIC: + return std::make_unique(); default: NOT_REACHED_GCOVR_EXCL_LINE; } diff --git a/test/output_transform_main_test.cc b/test/output_transform_main_test.cc index 4454391b3..43df89261 100644 --- a/test/output_transform_main_test.cc +++ b/test/output_transform_main_test.cc @@ -6,6 +6,7 @@ #include "api/client/service.pb.h" +#include "client/output_formatter_impl.h" #include "client/output_transform_main.h" #include "gtest/gtest.h" @@ -54,13 +55,19 @@ TEST_F(OutputTransformMainTest, JsonNotValidating) { EXPECT_NE(main.run(), 0); } -TEST_F(OutputTransformMainTest, HappyFlow) { - std::vector argv = {"foo", "--output-format", "human"}; - nighthawk::client::Output output; - output.mutable_options()->mutable_uri()->set_value("http://127.0.0.1/"); - stream_ << Envoy::MessageUtil::getJsonStringFromMessage(output, true, true); - OutputTransformMain main(argv.size(), argv.data(), stream_); - EXPECT_EQ(main.run(), 0); +TEST_F(OutputTransformMainTest, HappyFlowForAllOutputFormats) { + for (const std::string& output_format : OutputFormatterImpl::getLowerCaseOutputFormats()) { + std::vector argv = {"foo", "--output-format", output_format.c_str()}; + nighthawk::client::Output output; + if (output_format.find("fortio") != std::string::npos) { + // The fortio output formatter mandates at least a single global result or it throws. + output.add_results()->set_name("global"); + } + output.mutable_options()->mutable_uri()->set_value("http://127.0.0.1/"); + stream_ << Envoy::MessageUtil::getJsonStringFromMessage(output, true, true); + OutputTransformMain main(argv.size(), argv.data(), stream_); + EXPECT_EQ(main.run(), 0); + } } } // namespace Client