-
Notifications
You must be signed in to change notification settings - Fork 5.5k
redis: basic integration test for redis_proxy #6450
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
Merged
mattklein123
merged 4 commits into
envoyproxy:master
from
HenryYYang:msukalski/redis-integration-test
Apr 4, 2019
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8e86f82
redis: basic integration test for redis_proxy
msukalski 38b0de6
redis: basic integration test for redis_proxy (#6450)
msukalski 93a419b
redis: basic integration test for redis_proxy (#6450)
msukalski 142d6f7
redis: basic integration test for redis_proxy (#6450)
msukalski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,83 @@ | ||
| #include "test/integration/redis_proxy_integration_test.h" | ||
|
|
||
| #include <sstream> | ||
|
msukalski marked this conversation as resolved.
|
||
| #include <vector> | ||
|
|
||
| #include "extensions/filters/network/redis_proxy/command_splitter_impl.h" | ||
|
|
||
| namespace RedisCommon = Envoy::Extensions::NetworkFilters::Common::Redis; | ||
| namespace RedisCmdSplitter = Envoy::Extensions::NetworkFilters::RedisProxy::CommandSplitter; | ||
|
|
||
| namespace Envoy { | ||
| namespace { | ||
|
|
||
| std::string makeBulkStringArray(std::vector<std::string>&& command_strings) { | ||
| std::stringstream result; | ||
|
|
||
| result << "*" << command_strings.size() << "\r\n"; | ||
| for (uint64_t i = 0; i < command_strings.size(); i++) { | ||
| result << "$" << command_strings[i].size() << "\r\n"; | ||
| result << command_strings[i] << "\r\n"; | ||
| } | ||
|
|
||
| return result.str(); | ||
| } | ||
|
|
||
| INSTANTIATE_TEST_SUITE_P(IpVersions, RedisProxyIntegrationTest, | ||
| testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), | ||
| TestUtility::ipTestParamsToString); | ||
|
|
||
| void RedisProxyIntegrationTest::initialize() { | ||
| config_helper_.renameListener("redis_proxy"); | ||
| BaseIntegrationTest::initialize(); | ||
| } | ||
|
|
||
| TEST_P(RedisProxyIntegrationTest, SimpleRequestAndResponse) { | ||
|
msukalski marked this conversation as resolved.
Outdated
|
||
| initialize(); | ||
| IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("redis_proxy")); | ||
|
|
||
| std::string client_to_proxy = makeBulkStringArray({"get", "foo"}); | ||
| std::string proxy_to_server; | ||
|
|
||
| ASSERT_TRUE(client_to_proxy.size() > 0); | ||
|
msukalski marked this conversation as resolved.
Outdated
|
||
| ASSERT_TRUE(client_to_proxy.find("get") != std::string::npos); | ||
| ASSERT_TRUE(client_to_proxy.find("foo") != std::string::npos); | ||
| tcp_client->write(client_to_proxy); | ||
|
|
||
| FakeRawConnectionPtr fake_upstream_connection; | ||
| ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection)); | ||
| ASSERT_TRUE(fake_upstream_connection->waitForData(client_to_proxy.size(), &proxy_to_server)); | ||
| ASSERT_EQ(client_to_proxy, proxy_to_server); | ||
|
|
||
| std::string server_to_proxy = "$3\r\nbar\r\n"; // bulkstring reply of "bar" | ||
|
|
||
| ASSERT_TRUE(fake_upstream_connection->write(server_to_proxy)); | ||
| tcp_client->waitForData(server_to_proxy); | ||
| ASSERT_EQ(server_to_proxy, tcp_client->data()); | ||
|
|
||
| tcp_client->close(); | ||
| ASSERT_TRUE(fake_upstream_connection->close()); | ||
| } | ||
|
|
||
| TEST_P(RedisProxyIntegrationTest, InvalidRequest) { | ||
| initialize(); | ||
| IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("redis_proxy")); | ||
|
|
||
| std::string client_to_proxy = makeBulkStringArray({"foo"}); | ||
|
|
||
| ASSERT_TRUE(client_to_proxy.size() > 0); | ||
| ASSERT_TRUE(client_to_proxy.find("foo") != std::string::npos); | ||
| tcp_client->write(client_to_proxy); | ||
|
|
||
| std::stringstream error_response; | ||
| error_response << "-" << RedisCmdSplitter::Response::get().InvalidRequest << "\r\n"; | ||
| std::string proxy_to_client = error_response.str(); | ||
|
|
||
| tcp_client->waitForData(proxy_to_client); | ||
| ASSERT_EQ(proxy_to_client, tcp_client->data()); | ||
|
|
||
| tcp_client->close(); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace Envoy | ||
This file contains hidden or 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,23 @@ | ||
| #pragma once | ||
|
|
||
| #include "test/integration/integration.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace { | ||
| class RedisProxyIntegrationTest : public testing::TestWithParam<Network::Address::IpVersion>, | ||
|
msukalski marked this conversation as resolved.
Outdated
|
||
| public BaseIntegrationTest { | ||
| public: | ||
| RedisProxyIntegrationTest() : BaseIntegrationTest(GetParam(), ConfigHelper::REDIS_PROXY_CONFIG) {} | ||
|
|
||
| ~RedisProxyIntegrationTest() override { | ||
| test_server_.reset(); | ||
| fake_upstreams_.clear(); | ||
| } | ||
|
|
||
| void initialize() override; | ||
| }; | ||
|
|
||
| } // namespace | ||
| } // namespace Envoy | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.