forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_protocol_integration.h
87 lines (75 loc) · 3.56 KB
/
http_protocol_integration.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include "test/integration/http_integration.h"
#include "gtest/gtest.h"
namespace Envoy {
struct HttpProtocolTestParams {
Network::Address::IpVersion version;
Http::CodecType downstream_protocol;
Http::CodecType upstream_protocol;
bool http2_new_codec_wrapper;
};
// Allows easy testing of Envoy code for HTTP/HTTP2 upstream/downstream.
//
// Usage:
//
// using MyTest = HttpProtocolIntegrationTest;
//
// INSTANTIATE_TEST_SUITE_P(Protocols, MyTest,
// testing::ValuesIn(HttpProtocolIntegrationTest::getProtocolTestParams()),
// HttpProtocolIntegrationTest::protocolTestParamsToString);
//
//
// TEST_P(MyTest, TestInstance) {
// ....
// }
class HttpProtocolIntegrationTest : public testing::TestWithParam<HttpProtocolTestParams>,
public HttpIntegrationTest {
public:
// By default returns 8 combinations of
// [HTTP upstream / HTTP downstream] x [Ipv4, IPv6]
// [HTTP upstream / HTTP2 downstream] x [IPv4, Ipv6]
// [HTTP2 upstream / HTTP downstream] x [Ipv4, IPv6]
// [HTTP2 upstream / HTTP2 downstream] x [IPv4, Ipv6]
//
// Upstream and downstream protocols may be changed via the input vectors.
// Address combinations are propagated from TestEnvironment::getIpVersionsForTest()
static std::vector<HttpProtocolTestParams> getProtocolTestParams(
const std::vector<Http::CodecType>& downstream_protocols = {Http::CodecType::HTTP1,
Http::CodecType::HTTP2},
const std::vector<Http::CodecType>& upstream_protocols = {Http::CodecType::HTTP1,
Http::CodecType::HTTP2});
// Allows pretty printed test names of the form
// FooTestCase.BarInstance/IPv4_Http2Downstream_HttpUpstream
static std::string
protocolTestParamsToString(const ::testing::TestParamInfo<HttpProtocolTestParams>& p);
HttpProtocolIntegrationTest()
: HttpIntegrationTest(
GetParam().downstream_protocol, GetParam().version,
ConfigHelper::httpProxyConfig(/*downstream_is_quic=*/GetParam().downstream_protocol ==
Http::CodecType::HTTP3)) {
config_helper_.addRuntimeOverride("envoy.reloadable_features.http2_new_codec_wrapper",
GetParam().http2_new_codec_wrapper ? "true" : "false");
}
void SetUp() override {
setDownstreamProtocol(GetParam().downstream_protocol);
setUpstreamProtocol(GetParam().upstream_protocol);
}
protected:
struct BytesCountExpectation {
BytesCountExpectation(int wire_bytes_sent, int wire_bytes_received, int header_bytes_sent,
int header_bytes_received)
: wire_bytes_sent_{wire_bytes_sent}, wire_bytes_received_{wire_bytes_received},
header_bytes_sent_{header_bytes_sent}, header_bytes_received_{header_bytes_received} {}
int wire_bytes_sent_;
int wire_bytes_received_;
int header_bytes_sent_;
int header_bytes_received_;
};
void expectUpstreamBytesSentAndReceived(BytesCountExpectation h1_expectation,
BytesCountExpectation h2_expectation,
BytesCountExpectation h3_expectation, const int id = 0);
void expectDownstreamBytesSentAndReceived(BytesCountExpectation h1_expectation,
BytesCountExpectation h2_expectation,
BytesCountExpectation h3_expectation, const int id = 0);
};
} // namespace Envoy