Skip to content

Commit 658c103

Browse files
authored
transcoding: Basic integration test (istio#314)
* Basic integration test * Addressed comments
1 parent 36f4e29 commit 658c103

File tree

5 files changed

+213
-1
lines changed

5 files changed

+213
-1
lines changed

WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bind(
6868
git_repository(
6969
name = "envoy",
7070
remote = "https://github.com/lyft/envoy.git",
71-
commit = "8f9d56fb92b68ad157bd55d9003ddd433720c7e1",
71+
commit = "090050f9c7c31b014224afe80fe77b422fcf0990",
7272
)
7373

7474
load("@envoy//bazel:repositories.bzl", "envoy_dependencies")

src/envoy/transcoding/BUILD

+21
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,24 @@ cc_test(
8888
"//src/envoy/transcoding/test:bookstore_descriptor",
8989
],
9090
)
91+
92+
cc_test(
93+
name = "integration_test",
94+
srcs = [
95+
"integration_test.cc",
96+
],
97+
deps = [
98+
"filter_lib",
99+
"//src/envoy/transcoding/test:bookstore_proto",
100+
"@envoy//source/common/grpc:codec_lib",
101+
"@envoy//test/integration:integration_lib",
102+
"@envoy//test/mocks/http:http_mocks",
103+
"@envoy//test/mocks/upstream:upstream_mocks",
104+
"@envoy//test/test_common:utility_lib",
105+
"@envoy//test:main",
106+
],
107+
data = [
108+
"//src/envoy/transcoding/test:bookstore_descriptor",
109+
"//src/envoy/transcoding/test:integration.json",
110+
],
111+
)
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* Copyright 2017 Istio Authors. All Rights Reserved.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
#include "test/integration/integration.h"
17+
#include "common/grpc/codec.h"
18+
#include "common/grpc/common.h"
19+
#include "src/envoy/transcoding/test/bookstore.pb.h"
20+
21+
#include "gtest/gtest.h"
22+
23+
class TranscodingIntegrationTest : public BaseIntegrationTest,
24+
public testing::Test {
25+
public:
26+
/**
27+
* Global initializer for all integration tests.
28+
*/
29+
void SetUp() override {
30+
fake_upstreams_.emplace_back(
31+
new FakeUpstream(0, FakeHttpConnection::Type::HTTP2));
32+
registerPort("upstream_0",
33+
fake_upstreams_.back()->localAddress()->ip()->port());
34+
createTestServer("src/envoy/transcoding/test/integration.json", {"http"});
35+
}
36+
37+
/**
38+
* Global destructor for all integration tests.
39+
*/
40+
void TearDown() override {
41+
test_server_.reset();
42+
fake_upstreams_.clear();
43+
}
44+
};
45+
46+
TEST_F(TranscodingIntegrationTest, BasicUnary) {
47+
IntegrationCodecClientPtr codec_client;
48+
FakeHttpConnectionPtr fake_upstream_connection;
49+
IntegrationStreamDecoderPtr response(
50+
new IntegrationStreamDecoder(*dispatcher_));
51+
52+
codec_client =
53+
makeHttpConnection(lookupPort("http"), Http::CodecClient::Type::HTTP1);
54+
Http::StreamEncoder& encoder = codec_client->startRequest(
55+
Http::TestHeaderMapImpl{{":method", "POST"},
56+
{":path", "/shelf"},
57+
{":authority", "host"},
58+
{"content-type", "application/json"}},
59+
*response);
60+
Buffer::OwnedImpl request_data{"{\"theme\": \"Children\"}"};
61+
codec_client->sendData(encoder, request_data, true);
62+
63+
fake_upstream_connection =
64+
fake_upstreams_[0]->waitForHttpConnection(*dispatcher_);
65+
FakeStreamPtr request_stream = fake_upstream_connection->waitForNewStream();
66+
67+
request_stream->waitForEndStream(*dispatcher_);
68+
69+
Grpc::Decoder grpc_decoder;
70+
std::vector<Grpc::Frame> frames;
71+
grpc_decoder.decode(request_stream->body(), frames);
72+
EXPECT_EQ(1, frames.size());
73+
74+
bookstore::CreateShelfRequest csr;
75+
csr.ParseFromArray(frames[0].data_->linearize(frames[0].length_),
76+
frames[0].length_);
77+
EXPECT_EQ("Children", csr.shelf().theme());
78+
79+
request_stream->encodeHeaders(
80+
Http::TestHeaderMapImpl{{"content-type", "application/grpc"},
81+
{":status", "200"}},
82+
false);
83+
84+
bookstore::Shelf response_pb;
85+
response_pb.set_id(20);
86+
response_pb.set_theme("Children");
87+
88+
auto response_data = Grpc::Common::serializeBody(response_pb);
89+
request_stream->encodeData(*response_data, false);
90+
91+
request_stream->encodeTrailers(
92+
Http::TestHeaderMapImpl{{"grpc-status", "0"}, {"grpc-message", ""}});
93+
94+
response->waitForEndStream();
95+
EXPECT_TRUE(request_stream->complete());
96+
EXPECT_TRUE(response->complete());
97+
EXPECT_EQ("{\"id\":\"20\",\"theme\":\"Children\"}", response->body());
98+
99+
codec_client->close();
100+
fake_upstream_connection->close();
101+
fake_upstream_connection->waitForDisconnect();
102+
}

src/envoy/transcoding/test/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#
1717
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
1818

19+
exports_files(["integration.json"])
20+
1921
cc_proto_library(
2022
name = "bookstore_proto",
2123
srcs = ["bookstore.proto"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"listeners": [
3+
{
4+
"address": "tcp://127.0.0.1:0",
5+
"filters": [
6+
{
7+
"type": "read",
8+
"name": "http_connection_manager",
9+
"config": {
10+
"codec_type": "http1",
11+
"access_log": [
12+
{
13+
"path": "/dev/null",
14+
"filter" : {
15+
"type": "logical_or",
16+
"filters": [
17+
{
18+
"type": "status_code",
19+
"op": ">=",
20+
"value": 500
21+
},
22+
{
23+
"type": "duration",
24+
"op": ">=",
25+
"value": 1000000
26+
}
27+
]
28+
}
29+
},
30+
{
31+
"path": "/dev/null"
32+
}],
33+
"stat_prefix": "router",
34+
"route_config":
35+
{
36+
"virtual_hosts": [
37+
{
38+
"name": "redirect",
39+
"domains": [ "www.redirect.com" ],
40+
"require_ssl": "all",
41+
"routes": [
42+
{
43+
"prefix": "/",
44+
"cluster": "cluster_1"
45+
}
46+
]
47+
},
48+
{
49+
"name": "integration",
50+
"domains": [ "*" ],
51+
"routes": [
52+
{
53+
"prefix": "/",
54+
"cluster": "cluster_1"
55+
}
56+
]
57+
}
58+
]
59+
},
60+
"filters": [
61+
{ "type": "both", "name": "transcoding",
62+
"config": {
63+
"proto_descriptor": "{{ test_rundir }}/src/envoy/transcoding/test/bookstore.descriptor",
64+
"services": ["bookstore.Bookstore"]
65+
}
66+
},
67+
{ "type": "decoder", "name": "router", "config": {} }
68+
]
69+
}
70+
}]
71+
}],
72+
73+
"admin": { "access_log_path": "/dev/null", "address": "tcp://127.0.0.1:0" },
74+
"statsd_local_udp_port": 8125,
75+
76+
"cluster_manager": {
77+
"clusters": [
78+
{
79+
"name": "cluster_1",
80+
"features": "http2",
81+
"connect_timeout_ms": 5000,
82+
"type": "static",
83+
"lb_type": "round_robin",
84+
"hosts": [{"url": "tcp://127.0.0.1:{{ upstream_0 }}"}]
85+
}]
86+
}
87+
}

0 commit comments

Comments
 (0)