Skip to content

Commit

Permalink
Google Test simple_re doesn't support [0-9] patterns (envoyproxy#9398)
Browse files Browse the repository at this point in the history
Replace [0-9] character group matches with \d supported by simple_re

This suggests we need Google Test to support Google re2
(and also deprecate all std::regex for re2 in Envoy)
but for the short term, solve these cases by simplifying.

See: https://github.com/google/googletest/blob/587ceaeaee6c2ccb5e565858d7fe12aaf69795e6/googletest/include/gtest/gtest-death-test.h#L106

Signed-off-by: William A Rowe Jr <[email protected]>
Signed-off-by: Yechiel Kalmenson <[email protected]>
Signed-off-by: Sunjay Bhatia <[email protected]>
  • Loading branch information
wrowe authored and mattklein123 committed Dec 31, 2019
1 parent 3bcbd1e commit 52859d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/common/common/regex_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ TEST(Utility, ParseRegex) {
envoy::type::matcher::RegexMatcher matcher;
matcher.mutable_google_re2()->mutable_max_program_size()->set_value(1);
matcher.set_regex("/asdf/.*");
#ifndef GTEST_USES_SIMPLE_RE
EXPECT_THROW_WITH_REGEX(Utility::parseRegex(matcher), EnvoyException,
"RE2 program size of [0-9]+ > max program size of 1\\.");
#else
EXPECT_THROW_WITH_REGEX(Utility::parseRegex(matcher), EnvoyException,
"RE2 program size of \\d+ > max program size of 1\\.");
#endif
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/common/tcp_proxy/tcp_proxy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1564,9 +1564,16 @@ TEST_F(TcpProxyTest, DEPRECATED_FEATURE_TEST(AccessLogBytesRxTxDuration)) {
upstream_callbacks_->onEvent(Network::ConnectionEvent::RemoteClose);
filter_.reset();

#ifndef GTEST_USES_SIMPLE_RE
EXPECT_THAT(access_log_data_,
MatchesRegex(
"bytesreceived=1 bytessent=2 datetime=[0-9-]+T[0-9:.]+Z nonzeronum=[1-9][0-9]*"));
#else
EXPECT_THAT(access_log_data_,
MatchesRegex("bytesreceived=1 bytessent=2 "
"datetime=\\d+-\\d+-\\d+T\\d+:\\d+:\\d+\\.\\d+Z nonzeronum=\\d+"));
EXPECT_THAT(access_log_data_, Not(MatchesRegex("nonzeronum=0")));
#endif
}

TEST_F(TcpProxyTest, DEPRECATED_FEATURE_TEST(AccessLogUpstreamSSLConnection)) {
Expand Down
8 changes: 7 additions & 1 deletion test/integration/tcp_proxy_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,23 @@ TEST_P(TcpProxyIntegrationTest, AccessLog) {
} while (log_result.empty());

// Regex matching localhost:port
#ifndef GTEST_USES_SIMPLE_RE
const std::string ip_port_regex = (GetParam() == Network::Address::IpVersion::v4)
? R"EOF(127\.0\.0\.1:[0-9]+)EOF"
: R"EOF(\[::1\]:[0-9]+)EOF";
#else
const std::string ip_port_regex = (GetParam() == Network::Address::IpVersion::v4)
? R"EOF(127\.0\.0\.1:\d+)EOF"
: R"EOF(\[::1\]:\d+)EOF";
#endif

const std::string ip_regex =
(GetParam() == Network::Address::IpVersion::v4) ? R"EOF(127\.0\.0\.1)EOF" : R"EOF(::1)EOF";

// Test that all three addresses were populated correctly. Only check the first line of
// log output for simplicity.
EXPECT_THAT(log_result,
MatchesRegex(fmt::format("upstreamlocal={0} upstreamhost={0} downstream={1}\n.*",
MatchesRegex(fmt::format("upstreamlocal={0} upstreamhost={0} downstream={1}\r?\n.*",
ip_port_regex, ip_regex)));
}

Expand Down

0 comments on commit 52859d8

Please sign in to comment.