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

cleanup: move test utility methods in ScopedRdsIntegrationTest to base class HttpIntegrationTest #8108

Merged
merged 2 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 34 additions & 0 deletions test/integration/http_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,40 @@ void HttpIntegrationTest::cleanupUpstreamAndDownstream() {
}
}

void HttpIntegrationTest::sendRequestAndVerifyResponse(
const Http::TestHeaderMapImpl& request_headers, const int request_size,
const Http::TestHeaderMapImpl& response_headers, const int response_size,
const int backend_idx) {
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = sendRequestAndWaitForResponse(request_headers, request_size, response_headers,
response_size, backend_idx);
verifyResponse(std::move(response), "200", response_headers, std::string(response_size, 'a'));

EXPECT_TRUE(upstream_request_->complete());
EXPECT_EQ(request_size, upstream_request_->bodyLength());
cleanupUpstreamAndDownstream();
}

void HttpIntegrationTest::verifyResponse(IntegrationStreamDecoderPtr response,
const std::string& response_code,
const Http::TestHeaderMapImpl& expected_headers,
const std::string& expected_body) {
EXPECT_TRUE(response->complete());
EXPECT_EQ(response_code, response->headers().Status()->value().getStringView());
expected_headers.iterate(
[](const Http::HeaderEntry& header, void* context) -> Http::HeaderMap::Iterate {
auto response_headers = static_cast<Http::HeaderMap*>(context);
const Http::HeaderEntry* entry =
response_headers->get(Http::LowerCaseString{std::string(header.key().getStringView())});
EXPECT_NE(entry, nullptr);
EXPECT_EQ(header.value().getStringView(), entry->value().getStringView());
return Http::HeaderMap::Iterate::Continue;
},
const_cast<void*>(static_cast<const void*>(&response->headers())));

EXPECT_EQ(response->body(), expected_body);
}

uint64_t
HttpIntegrationTest::waitForNextUpstreamRequest(const std::vector<uint64_t>& upstream_indices) {
uint64_t upstream_with_request;
Expand Down
14 changes: 14 additions & 0 deletions test/integration/http_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ class HttpIntegrationTest : public BaseIntegrationTest {
// Close |codec_client_| and |fake_upstream_connection_| cleanly.
void cleanupUpstreamAndDownstream();

// Verifies the response_headers contains the expected_headers, and response body matches given
// body string.
void verifyResponse(IntegrationStreamDecoderPtr response, const std::string& response_code,
const Http::TestHeaderMapImpl& expected_headers,
const std::string& expected_body);

// Helper that sends a request to Envoy, and verifies if Envoy response headers and body size is
// the same as the expected headers map.
// Requires the "http" port has been registered.
void sendRequestAndVerifyResponse(const Http::TestHeaderMapImpl& request_headers,
const int request_size,
const Http::TestHeaderMapImpl& response_headers,
const int response_size, const int backend_idx);

// Check for completion of upstream_request_, and a simple "200" response.
void checkSimpleRequestSuccess(uint64_t expected_request_size, uint64_t expected_response_size,
IntegrationStreamDecoder* response);
Expand Down
35 changes: 0 additions & 35 deletions test/integration/scoped_rds_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,41 +94,6 @@ class ScopedRdsIntegrationTest : public HttpIntegrationTest,
HttpIntegrationTest::initialize();
}

// TODO(stevenzzzz): move these utility methods to base classes to share with other tests.
// Helper that verifies if given headers are in the response header map.
void verifyResponse(IntegrationStreamDecoderPtr response, const std::string& response_code,
const Http::TestHeaderMapImpl& expected_headers,
const std::string& expected_body) {
EXPECT_TRUE(response->complete());
EXPECT_EQ(response_code, response->headers().Status()->value().getStringView());
expected_headers.iterate(
[](const Http::HeaderEntry& header, void* context) -> Http::HeaderMap::Iterate {
auto response_headers = static_cast<Http::HeaderMap*>(context);
const Http::HeaderEntry* entry = response_headers->get(
Http::LowerCaseString{std::string(header.key().getStringView())});
EXPECT_NE(entry, nullptr);
EXPECT_EQ(header.value().getStringView(), entry->value().getStringView());
return Http::HeaderMap::Iterate::Continue;
},
const_cast<void*>(static_cast<const void*>(&response->headers())));
EXPECT_EQ(response->body(), expected_body);
}

// Helper that sends a request to Envoy, and verifies if Envoy response headers and body size is
// the same as the expected headers map.
void sendRequestAndVerifyResponse(const Http::TestHeaderMapImpl& request_headers,
const int request_size,
const Http::TestHeaderMapImpl& response_headers,
const int response_size, const int backend_idx) {
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = sendRequestAndWaitForResponse(request_headers, request_size, response_headers,
response_size, backend_idx);
verifyResponse(std::move(response), "200", response_headers, std::string(response_size, 'a'));
EXPECT_TRUE(upstream_request_->complete());
EXPECT_EQ(request_size, upstream_request_->bodyLength());
cleanupUpstreamAndDownstream();
}

void createUpstreams() override {
HttpIntegrationTest::createUpstreams();
// Create the SRDS upstream.
Expand Down