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

Use dynamicMetadata to construct metadataMatchCriteria() #3254

Merged
Merged
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
Prev Previous commit
More tests
This tests 3 things:

* using > 1 key/value in dynamicMetadata()
* mixing a key/value pair that overrides the route entry's config with
  another pair that doesn't override the route entry's config
* caching metadataMatchCriteria()'s result, when it has been computed
  from the request's dynamic metadata

Signed-off-by: Raul Gutierrez Segales <[email protected]>
  • Loading branch information
Raul Gutierrez Segales committed May 3, 2018
commit 8b7bb04f24d718205b7d9814275e6e7a0931a0ff
25 changes: 21 additions & 4 deletions test/common/router/router_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ class RouterTestBase : public testing::Test {
ProtobufWkt::Struct request_struct, route_struct;
ProtobufWkt::Value val;

// populate metadata like RequestInfo.setDynamicMetadata() would
val.set_string_value("v3.1");
// Populate metadata like RequestInfo.setDynamicMetadata() would.
auto& fields_map = *request_struct.mutable_fields();
val.set_string_value("v3.1");
fields_map["version"] = val;
val.set_string_value("devel");
fields_map["stage"] = val;
(*callbacks_.request_info_.metadata_
.mutable_filter_metadata())[Envoy::Config::MetadataFilters::get().ENVOY_LB] =
request_struct;

// populate route entry's metadata which will be overridden
// Populate route entry's metadata which will be overridden.
val.set_string_value("v3.0");
fields_map = *request_struct.mutable_fields();
fields_map["version"] = val;
Expand All @@ -138,10 +140,25 @@ class RouterTestBase : public testing::Test {
Invoke([&](const std::string&, Upstream::ResourcePriority, Http::Protocol,
Upstream::LoadBalancerContext* context) -> Http::ConnectionPool::Instance* {
auto match = context->metadataMatchCriteria()->metadataMatchCriteria();
EXPECT_EQ(match.size(), 1);
EXPECT_EQ(match.size(), 2);
auto it = match.begin();

// Note: metadataMatchCriteria() keeps its entries sorted, so the order for checks
// below matters.

// `stage` was only set by the request, not by the route entry.
EXPECT_EQ((*it)->name(), "stage");
EXPECT_EQ((*it)->value().value().string_value(), "devel");
it++;

// `version` should be what came from the request, overriding the route entry.
EXPECT_EQ((*it)->name(), "version");
EXPECT_EQ((*it)->value().value().string_value(), "v3.1");

// When metadataMatchCriteria() is computed from dynamic metadata, the result should
// be cached.
EXPECT_EQ(context->metadataMatchCriteria(), context->metadataMatchCriteria());

return &cm_.conn_pool_;
}));
EXPECT_CALL(cm_.conn_pool_, newStream(_, _)).WillOnce(Return(&cancellable_));
Expand Down