Skip to content

test: Add EXPECT_THAT_THROWS_MESSAGE, allowing arbitrary string matchers#6561

Merged
mattklein123 merged 2 commits intoenvoyproxy:masterfrom
jamessynge:expect_that_throws_exception
Apr 12, 2019
Merged

test: Add EXPECT_THAT_THROWS_MESSAGE, allowing arbitrary string matchers#6561
mattklein123 merged 2 commits intoenvoyproxy:masterfrom
jamessynge:expect_that_throws_exception

Conversation

@jamessynge
Copy link
Contributor

This was inspired by the same problem that #6558 is fixing, namely
an overly strict string match. Elisha wanted a more focused fix, so
I'm offering this for the next such case, enabling a test in
test/common/router/config_impl_test.cc such as:

EXPECT_THAT_THROWS_MESSAGE(
TestConfigImpl(parseRouteConfigurationFromV2Yaml(yaml), factory_context_, true),
EnvoyException,
AllOf(HasSubstr("Unable to parse"),
HasSubstr("virtual_hosts[0].routes[0].route.cors.enabled.value"),
HasSubstr("invalid value 0 for type TYPE_BOOL")));

I've modified the existing EXPECT_THROWS.* macros to use this macro,
and added documentation of each of those macros.

Signed-off-by: James Synge jamessynge@google.com

This was inspired by the same problem that PR#6448 is fixing, namely
an overly strict string match. Elisha wanted a more focused fix, so
I'm offering this for the next such case, enabling a test in
test/common/router/config_impl_test.cc such as:

EXPECT_THAT_THROWS_MESSAGE(
    TestConfigImpl(parseRouteConfigurationFromV2Yaml(yaml), factory_context_, true),
    EnvoyException,
    AllOf(HasSubstr("Unable to parse"),
          HasSubstr("virtual_hosts[0].routes[0].route.cors.enabled.value"),
          HasSubstr("invalid value 0 for type TYPE_BOOL")));

Signed-off-by: James Synge <jamessynge@google.com>
Signed-off-by: James Synge <jamessynge@google.com>
@jamessynge jamessynge marked this pull request as ready for review April 11, 2019 20:24
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is awesome.

@mattklein123 mattklein123 merged commit a9b49bf into envoyproxy:master Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants