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

router check tool: add flag for only printing failed tests #8160

Merged
merged 22 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
50 changes: 21 additions & 29 deletions test/tools/router_check/router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool RouterCheckTool::compareEntriesInJson(const std::string& expected_route_jso
ToolConfig tool_config = ToolConfig::create(check_config);
tool_config.route_ = config_->route(*tool_config.headers_, tool_config.random_value_);
std::string test_name = check_config->getString("test_name", "");
tests_.push_back(std::pair<std::string, std::vector<std::string>>(test_name, {}));
tests_.emplace_back(std::pair<std::string, std::vector<std::string>>(test_name, {}));
Json::ObjectSharedPtr validate = check_config->getObject("validate");
using checkerFunc = std::function<bool(ToolConfig&, const std::string&)>;
const std::unordered_map<std::string, checkerFunc> checkers = {
Expand Down Expand Up @@ -154,18 +154,7 @@ bool RouterCheckTool::compareEntriesInJson(const std::string& expected_route_jso
}
}
}
// Output failure details to stdout if details_ flag is set to true
for (const auto& test_result : tests_) {
// All test names are printed if the details_ flag is true unless only_show_failures_ is also
// true.
if ((details_ && !only_show_failures_) ||
(only_show_failures_ && !test_result.second.empty())) {
std::cout << test_result.first << std::endl;
for (const auto& failure : test_result.second) {
std::cerr << failure << std::endl;
}
}
}
printResults();
return no_failures;
}

Expand All @@ -186,7 +175,7 @@ bool RouterCheckTool::compareEntries(const std::string& expected_routes) {
tool_config.route_ = config_->route(*tool_config.headers_, tool_config.random_value_);

const std::string& test_name = check_config.test_name();
tests_.push_back(std::pair<std::string, std::vector<std::string>>(test_name, {}));
tests_.emplace_back(std::pair<std::string, std::vector<std::string>>(test_name, {}));
LisaLudique marked this conversation as resolved.
Show resolved Hide resolved
const envoy::RouterCheckToolSchema::ValidationAssert& validate = check_config.validate();

using checkerFunc =
Expand All @@ -209,19 +198,7 @@ bool RouterCheckTool::compareEntries(const std::string& expected_routes) {
}
}
}
// Output failure details to stdout if details_ flag is set to true
for (const auto& test_result : tests_) {
// All test names are printed if the details_ flag is true unless only_show_failures_ is also
// true.
if ((details_ && !only_show_failures_) ||
(only_show_failures_ && !test_result.second.empty())) {
std::cout << test_result.first << std::endl;
for (const auto& failure : test_result.second) {
std::cerr << failure << std::endl;
}
}
}

printResults();
return no_failures;
}

Expand Down Expand Up @@ -437,11 +414,26 @@ bool RouterCheckTool::compareResults(const std::string& actual, const std::strin
if (expected == actual) {
return true;
}
tests_.back().second.push_back("expected: [" + expected + "], actual: [" + actual +
"], test type: " + test_type);
tests_.back().second.emplace_back("expected: [" + expected + "], actual: [" + actual +
"], test type: " + test_type);
return false;
}

void RouterCheckTool::printResults() {
// Output failure details to stdout if details_ flag is set to true
for (const auto& test_result : tests_) {
// All test names are printed if the details_ flag is true unless only_show_failures_ is also
// true.
if ((details_ && !only_show_failures_) ||
(only_show_failures_ && !test_result.second.empty())) {
std::cout << test_result.first << std::endl;
for (const auto& failure : test_result.second) {
std::cerr << failure << std::endl;
}
}
}
}

// The Mock for runtime value checks.
// This is a simple implementation to mimic the actual runtime checks in Snapshot.featureEnabled
bool RouterCheckTool::runtimeMock(const std::string& key,
Expand Down
4 changes: 4 additions & 0 deletions test/tools/router_check/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class RouterCheckTool : Logger::Loggable<Logger::Id::testing> {
bool compareResults(const std::string& actual, const std::string& expected,
const std::string& test_type);

void printResults();

bool runtimeMock(const std::string& key, const envoy::type::FractionalPercent& default_value,
uint64_t random_value);

Expand All @@ -151,6 +153,8 @@ class RouterCheckTool : Logger::Loggable<Logger::Id::testing> {

bool only_show_failures_{false};

// The first member of each pair is the name of the test.
// The second member is a list of any failing results for that test as strings.
std::vector<std::pair<std::string, std::vector<std::string>>> tests_;
LisaLudique marked this conversation as resolved.
Show resolved Hide resolved

// TODO(hennna): Switch away from mocks following work done by @rlazarus in github issue #499.
Expand Down