Envoy uses the Google Test framework for tests, including Google Mock for mocks and matchers. See the documentation on those pages for information on the various classes, macros, and matchers that Envoy uses from those frameworks.
Envoy contains an integration testing framework, for testing downstream-Envoy-upstream communication. See the framework's README for more information.
Envoy includes some custom Google Mock matchers to make test expectation statements simpler to write and easier to understand.
Tests that a HeaderMap argument contains exactly one header with the given key, whose value satisfies the given expectation. The expectation can be a matcher, or a string that the value should equal.
Examples:
EXPECT_THAT(response->headers(), HeaderValueOf(Headers::get().Server, "envoy"));
using testing::HasSubstr;
EXPECT_THAT(request->headers(),
HeaderValueOf(Headers::get().AcceptEncoding, HasSubstr("gzip")));
Tests that a HeaderMap argument has the provided HTTP status code. The status code can be passed in as a string or an integer.
Example:
EXPECT_THAT(response->headers(), HttpStatusIs("200"));
HeaderMapEqualRef
tests that two HeaderMap
arguments are equal.
HeaderMapEqual
is the same, but it compares two pointers to HeaderMap
s, and
the matcher's argument must be a HeaderMapPtr
.
Example:
EXPECT_THAT(response->headers(), HeaderMapEqualRef(expected_headers));
Tests that one HeaderMap
argument contains every header in another
HeaderMap
.
Example:
EXPECT_THAT(response->headers(), IsSubsetOfHeaders(required_headers));