forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mobile: Add C++ stream callback integration tests (envoyproxy#34149)
Risk Level: low (tests only) Testing: integration tests Docs Changes: n/a Release Notes: n/a Platform Specific Features: n/a Signed-off-by: Fredy Wijaya <[email protected]>
- Loading branch information
Showing
9 changed files
with
253 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "test/common/integration/engine_with_test_server.h" | ||
#include "test/common/integration/test_server.h" | ||
|
||
#include "absl/synchronization/notification.h" | ||
#include "gtest/gtest.h" | ||
#include "library/cc/engine_builder.h" | ||
#include "library/common/engine_types.h" | ||
#include "library/common/http/header_utility.h" | ||
|
||
namespace Envoy { | ||
|
||
TEST(ReceiveDataTest, Success) { | ||
absl::Notification engine_running; | ||
Platform::EngineBuilder engine_builder; | ||
engine_builder.enforceTrustChainVerification(false) | ||
.setLogLevel(Logger::Logger::debug) | ||
.setOnEngineRunning([&]() { engine_running.Notify(); }); | ||
EngineWithTestServer engine_with_test_server(engine_builder, TestServerType::HTTP2_WITH_TLS, | ||
/* headers= */ {}, /* body= */ "hello world", | ||
/* trailers= */ {}); | ||
engine_running.WaitForNotification(); | ||
|
||
bool on_data_was_called = false; | ||
std::string actual_status_code; | ||
bool actual_end_stream; | ||
std::string actual_response_body; | ||
absl::Notification stream_complete; | ||
EnvoyStreamCallbacks stream_callbacks; | ||
stream_callbacks.on_headers_ = [&](const Http::ResponseHeaderMap& headers, bool end_stream, | ||
envoy_stream_intel) { | ||
actual_status_code = headers.getStatusValue(); | ||
actual_end_stream = end_stream; | ||
}; | ||
stream_callbacks.on_data_ = [&](const Buffer::Instance& buffer, uint64_t length, bool end_stream, | ||
envoy_stream_intel) { | ||
on_data_was_called = true; | ||
actual_end_stream = end_stream; | ||
actual_response_body += absl::string_view(buffer.toString().data(), length); | ||
}; | ||
stream_callbacks.on_complete_ = [&](envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
stream_callbacks.on_error_ = [&](EnvoyError, envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
stream_callbacks.on_cancel_ = [&](envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
auto stream_prototype = engine_with_test_server.engine()->streamClient()->newStreamPrototype(); | ||
Platform::StreamSharedPtr stream = stream_prototype->start(std::move(stream_callbacks)); | ||
|
||
auto headers = Http::Utility::createRequestHeaderMapPtr(); | ||
headers->addCopy(Http::LowerCaseString(":method"), "GET"); | ||
headers->addCopy(Http::LowerCaseString(":scheme"), "https"); | ||
headers->addCopy(Http::LowerCaseString(":authority"), | ||
engine_with_test_server.testServer().getAddress()); | ||
headers->addCopy(Http::LowerCaseString(":path"), "/"); | ||
stream->sendHeaders(std::move(headers), true); | ||
stream_complete.WaitForNotification(); | ||
|
||
EXPECT_TRUE(on_data_was_called); | ||
EXPECT_EQ(actual_status_code, "200"); | ||
EXPECT_TRUE(actual_end_stream); | ||
EXPECT_EQ(actual_response_body, "hello world"); | ||
} | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "test/common/integration/engine_with_test_server.h" | ||
#include "test/common/integration/test_server.h" | ||
|
||
#include "absl/synchronization/notification.h" | ||
#include "gtest/gtest.h" | ||
#include "library/cc/engine_builder.h" | ||
#include "library/common/engine_types.h" | ||
#include "library/common/http/header_utility.h" | ||
|
||
namespace Envoy { | ||
|
||
TEST(ReceiveHeadersTest, Success) { | ||
absl::Notification engine_running; | ||
Platform::EngineBuilder engine_builder; | ||
engine_builder.enforceTrustChainVerification(false) | ||
.setLogLevel(Logger::Logger::debug) | ||
.setOnEngineRunning([&]() { engine_running.Notify(); }); | ||
EngineWithTestServer engine_with_test_server(engine_builder, TestServerType::HTTP2_WITH_TLS, | ||
{{"foo", "bar"}}); | ||
engine_running.WaitForNotification(); | ||
|
||
bool on_headers_was_called = false; | ||
std::string actual_status_code; | ||
bool actual_end_stream; | ||
absl::Notification stream_complete; | ||
EnvoyStreamCallbacks stream_callbacks; | ||
stream_callbacks.on_headers_ = [&](const Http::ResponseHeaderMap& headers, bool end_stream, | ||
envoy_stream_intel) { | ||
on_headers_was_called = true; | ||
actual_status_code = headers.getStatusValue(); | ||
EXPECT_EQ("bar", headers.get(Http::LowerCaseString("foo"))[0]->value().getStringView()); | ||
actual_end_stream = end_stream; | ||
}; | ||
stream_callbacks.on_data_ = [&](const Buffer::Instance&, uint64_t /* length */, bool end_stream, | ||
envoy_stream_intel) { actual_end_stream = end_stream; }; | ||
stream_callbacks.on_complete_ = [&](envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
stream_callbacks.on_error_ = [&](EnvoyError, envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
stream_callbacks.on_cancel_ = [&](envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
auto stream_prototype = engine_with_test_server.engine()->streamClient()->newStreamPrototype(); | ||
Platform::StreamSharedPtr stream = stream_prototype->start(std::move(stream_callbacks)); | ||
|
||
auto headers = Http::Utility::createRequestHeaderMapPtr(); | ||
headers->addCopy(Http::LowerCaseString(":method"), "GET"); | ||
headers->addCopy(Http::LowerCaseString(":scheme"), "https"); | ||
headers->addCopy(Http::LowerCaseString(":authority"), | ||
engine_with_test_server.testServer().getAddress()); | ||
headers->addCopy(Http::LowerCaseString(":path"), "/"); | ||
stream->sendHeaders(std::move(headers), true); | ||
stream->sendData(std::make_unique<Buffer::OwnedImpl>("request body")); | ||
stream->close(std::make_unique<Buffer::OwnedImpl>("request body")); | ||
stream_complete.WaitForNotification(); | ||
|
||
EXPECT_TRUE(on_headers_was_called); | ||
EXPECT_EQ(actual_status_code, "200"); | ||
EXPECT_TRUE(actual_end_stream); | ||
} | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "test/common/integration/engine_with_test_server.h" | ||
#include "test/common/integration/test_server.h" | ||
|
||
#include "absl/synchronization/notification.h" | ||
#include "gtest/gtest.h" | ||
#include "library/cc/engine_builder.h" | ||
#include "library/common/engine_types.h" | ||
#include "library/common/http/header_utility.h" | ||
|
||
namespace Envoy { | ||
|
||
TEST(ReceiveTrailersTest, Success) { | ||
absl::Notification engine_running; | ||
Platform::EngineBuilder engine_builder; | ||
engine_builder.enforceTrustChainVerification(false) | ||
.setLogLevel(Logger::Logger::debug) | ||
.setOnEngineRunning([&]() { engine_running.Notify(); }); | ||
EngineWithTestServer engine_with_test_server(engine_builder, TestServerType::HTTP2_WITH_TLS, | ||
/* headers= */ {}, | ||
/* body= */ "", /* trailers= */ {{"foo", "bar"}}); | ||
engine_running.WaitForNotification(); | ||
|
||
bool on_trailers_was_called = false; | ||
std::string actual_status_code; | ||
absl::Notification stream_complete; | ||
EnvoyStreamCallbacks stream_callbacks; | ||
stream_callbacks.on_headers_ = [&](const Http::ResponseHeaderMap& headers, bool /* end_stream */, | ||
envoy_stream_intel) { | ||
actual_status_code = headers.getStatusValue(); | ||
}; | ||
stream_callbacks.on_trailers_ = [&](const Http::ResponseTrailerMap& trailers, | ||
envoy_stream_intel) { | ||
on_trailers_was_called = true; | ||
EXPECT_EQ("bar", trailers.get(Http::LowerCaseString("foo"))[0]->value().getStringView()); | ||
}; | ||
stream_callbacks.on_complete_ = [&](envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
stream_callbacks.on_error_ = [&](EnvoyError, envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
stream_callbacks.on_cancel_ = [&](envoy_stream_intel, envoy_final_stream_intel) { | ||
stream_complete.Notify(); | ||
}; | ||
auto stream_prototype = engine_with_test_server.engine()->streamClient()->newStreamPrototype(); | ||
Platform::StreamSharedPtr stream = stream_prototype->start(std::move(stream_callbacks)); | ||
|
||
auto headers = Http::Utility::createRequestHeaderMapPtr(); | ||
headers->addCopy(Http::LowerCaseString(":method"), "GET"); | ||
headers->addCopy(Http::LowerCaseString(":scheme"), "https"); | ||
headers->addCopy(Http::LowerCaseString(":authority"), | ||
engine_with_test_server.testServer().getAddress()); | ||
headers->addCopy(Http::LowerCaseString(":path"), "/"); | ||
stream->sendHeaders(std::move(headers), true); | ||
|
||
stream_complete.WaitForNotification(); | ||
|
||
EXPECT_TRUE(on_trailers_was_called); | ||
EXPECT_EQ(actual_status_code, "200"); | ||
} | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters