Skip to content
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
6 changes: 6 additions & 0 deletions source/common/common/stl_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ template <class T> std::ostream& operator<<(std::ostream& out, const std::vector
return out;
}

// Overload std::operator<< to output a pair.
template <class T1, class T2>
std::ostream& operator<<(std::ostream& out, const std::pair<T1, T2>& v) {
out << "pair(" << v.first << ", " << v.second << ")";
return out;
}
} // namespace std
9 changes: 8 additions & 1 deletion test/common/common/stl_helpers_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

namespace Envoy {

TEST(StlHelpersTest, TestOutputToStreamOperator) {
TEST(StlHelpersTest, TestPairOutputToStreamOperator) {
std::stringstream os;
std::pair<int, std::string> v{10, "five"};
os << v;
EXPECT_EQ("pair(10, five)", os.str());
}

TEST(StlHelpersTest, TestVectorOutputToStreamOperator) {
std::stringstream os;
std::vector<int> v{1, 2, 3, 4, 5};
os << v;
Expand Down
24 changes: 24 additions & 0 deletions test/extensions/filters/common/ext_authz/test_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ namespace Filters {
namespace Common {
namespace ExtAuthz {

// NOLINTNEXTLINE(readability-identifier-naming)
void PrintTo(const ResponsePtr& ptr, std::ostream* os) {
if (ptr != nullptr) {
PrintTo(*ptr, os);
} else {
(*os) << "null";
}
}

// NOLINTNEXTLINE(readability-identifier-naming)
void PrintTo(const Response& response, std::ostream* os) {
(*os) << "\n{\n check_status: " << int(response.status)
<< "\n headers_to_append: " << response.headers_to_append
<< "\n headers_to_set: " << response.headers_to_set
<< "\n headers_to_add: " << response.headers_to_add
<< "\n response_headers_to_add: " << response.response_headers_to_add
<< "\n response_headers_to_set: " << response.response_headers_to_set
<< "\n headers_to_remove: " << response.headers_to_remove
<< "\n query_parameters_to_set: " << response.query_parameters_to_set
<< "\n query_parameters_to_remove: " << response.query_parameters_to_remove
<< "\n body: " << response.body << "\n status_code: " << int(response.status_code)
<< "\n dynamic_metadata: " << response.dynamic_metadata.DebugString() << "\n}\n";
}

CheckResponsePtr TestCommon::makeCheckResponse(Grpc::Status::GrpcStatus response_status,
envoy::type::v3::StatusCode http_status_code,
const std::string& body,
Expand Down
27 changes: 21 additions & 6 deletions test/extensions/filters/common/ext_authz/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace Filters {
namespace Common {
namespace ExtAuthz {

// NOLINTNEXTLINE(readability-identifier-naming)
void PrintTo(const ResponsePtr& ptr, std::ostream* os);

// NOLINTNEXTLINE(readability-identifier-naming)
void PrintTo(const Response& response, std::ostream* os);

struct KeyValueOption {
std::string key;
std::string value;
Expand Down Expand Up @@ -99,35 +105,44 @@ MATCHER_P(AuthzOkResponse, response, "") {
if (arg->status != response.status) {
return false;
}
// Compare headers_to_append.

if (!TestCommon::compareHeaderVector(response.headers_to_append, arg->headers_to_append)) {
return false;
}

// Compare headers_to_add.
if (!TestCommon::compareHeaderVector(response.headers_to_add, arg->headers_to_add)) {
return false;
}

// Compare response_headers_to_add.
if (!TestCommon::compareHeaderVector(response.response_headers_to_add,
arg->response_headers_to_add)) {
return false;
}

// Compare query_parameters_to_set.
if (!TestCommon::compareHeaderVector(response.response_headers_to_set,
arg->response_headers_to_set)) {
return false;
}

if (!TestCommon::compareQueryParamsVector(response.query_parameters_to_set,
arg->query_parameters_to_set)) {
return false;
}

// Compare query_parameters_to_remove.
if (!TestCommon::compareVectorOfUnorderedStrings(response.query_parameters_to_remove,
arg->query_parameters_to_remove)) {
return false;
}

return TestCommon::compareVectorOfHeaderName(response.headers_to_remove, arg->headers_to_remove);
if (!TestCommon::compareVectorOfHeaderName(response.headers_to_remove, arg->headers_to_remove)) {
return false;
}

if (!TestUtility::protoEqual(arg->dynamic_metadata, response.dynamic_metadata)) {
return false;
}

return true;
}

MATCHER_P(ContainsPairAsHeader, pair, "") {
Expand Down