From e2c30be0ce16c75ac646d68450f51382159409cb Mon Sep 17 00:00:00 2001 From: Xin Zhuang Date: Fri, 30 Aug 2019 14:04:30 -0400 Subject: [PATCH 1/2] move utility methods to base class Signed-off-by: Xin Zhuang --- test/integration/http_integration.cc | 34 ++++++++++++++++++ test/integration/http_integration.h | 14 ++++++++ .../scoped_rds_integration_test.cc | 35 ------------------- 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/test/integration/http_integration.cc b/test/integration/http_integration.cc index 62d2eb45ba41..62090c09d7c9 100644 --- a/test/integration/http_integration.cc +++ b/test/integration/http_integration.cc @@ -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(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(static_cast(&response->headers()))); + + EXPECT_EQ(response->body(), expected_body); +} + uint64_t HttpIntegrationTest::waitForNextUpstreamRequest(const std::vector& upstream_indices) { uint64_t upstream_with_request; diff --git a/test/integration/http_integration.h b/test/integration/http_integration.h index bbeda044911e..8dbd462cbf21 100644 --- a/test/integration/http_integration.h +++ b/test/integration/http_integration.h @@ -138,6 +138,20 @@ class HttpIntegrationTest : public BaseIntegrationTest { // Close |codec_client_| and |fake_upstream_connection_| cleanly. void cleanupUpstreamAndDownstream(); + // Verifie 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); diff --git a/test/integration/scoped_rds_integration_test.cc b/test/integration/scoped_rds_integration_test.cc index 1cefe11ac397..4bcc2a38997b 100644 --- a/test/integration/scoped_rds_integration_test.cc +++ b/test/integration/scoped_rds_integration_test.cc @@ -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(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(static_cast(&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. From 87c36717a7d1b0ae724c65e2d9de6f755c4def4c Mon Sep 17 00:00:00 2001 From: Xin Zhuang Date: Fri, 30 Aug 2019 14:23:20 -0400 Subject: [PATCH 2/2] fix typo Signed-off-by: Xin Zhuang --- test/integration/http_integration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/http_integration.h b/test/integration/http_integration.h index 8dbd462cbf21..1a2193556e65 100644 --- a/test/integration/http_integration.h +++ b/test/integration/http_integration.h @@ -138,7 +138,7 @@ class HttpIntegrationTest : public BaseIntegrationTest { // Close |codec_client_| and |fake_upstream_connection_| cleanly. void cleanupUpstreamAndDownstream(); - // Verifie the response_headers contains the expected_headers, and response body matches given + // 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,