forked from envoyproxy/envoy-filter-example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathecho2_integration_test.cc
More file actions
65 lines (54 loc) · 1.93 KB
/
Copy pathecho2_integration_test.cc
File metadata and controls
65 lines (54 loc) · 1.93 KB
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
#include "test/integration/integration.h"
#include "test/integration/utility.h"
namespace Envoy {
class Echo2IntegrationTest : public BaseIntegrationTest,
public testing::TestWithParam<Network::Address::IpVersion> {
// TODO(alyssawilk): make this a general util.
std::string readFileToStringForTest(const std::string& filename) {
std::ifstream file(filename);
if (file.fail()) {
std::cerr << "failed to open: " << filename << std::endl;
RELEASE_ASSERT(false);
}
std::stringstream file_string_stream;
file_string_stream << file.rdbuf();
return file_string_stream.str();
}
std::string echoConfig() {
return readFileToStringForTest(TestEnvironment::runfilesPath("echo2_server.yaml");
}
public:
Echo2IntegrationTest() : BaseIntegrationTest(GetParam(), echoConfig()) {}
// Called once by the gtest framework before any EchoIntegrationTests are run.
static void SetUpTestCase() {
}
/**
* Initializer for an individual integration test.
*/
void SetUp() override {
named_ports_ = {{"echo"}};
BaseIntegrationTest::initialize();
}
/**
* Destructor for an individual integration test.
*/
void TearDown() override {
test_server_.reset();
fake_upstreams_.clear();
}
};
INSTANTIATE_TEST_CASE_P(IpVersions, Echo2IntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()));
TEST_P(Echo2IntegrationTest, Echo) {
Buffer::OwnedImpl buffer("hello");
std::string response;
RawConnectionDriver connection(lookupPort("echo"), buffer,
[&](Network::ClientConnection&, const Buffer::Instance& data)
-> void {
response.append(TestUtility::bufferToString(data));
connection.close();
}, GetParam());
connection.run();
EXPECT_EQ("hello", response);
}
} // Envoy