Skip to content

Commit

Permalink
[balsa] Clean up http1 codec_impl_test. (#24762)
Browse files Browse the repository at this point in the history
[balsa] Remove unused ResponseEncoder* variables from codec_impl_test.cc and simplify some EXPECT_CALL().WillOnce(Invoke()) constructs.

Signed-off-by: Bence Béky <bnc@google.com>
  • Loading branch information
bencebeky committed Jan 6, 2023
1 parent 2cdaac4 commit e70c4b5
Showing 1 changed file with 12 additions and 43 deletions.
55 changes: 12 additions & 43 deletions test/common/http/http1/codec_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ void Http1ServerConnectionImplTest::expectTrailersTest(bool enable_trailers) {

InSequence sequence;
StrictMock<MockRequestDecoder> decoder;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder&, bool) -> RequestDecoder& { return decoder; }));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

EXPECT_CALL(decoder, decodeHeaders_(_, false));

Expand Down Expand Up @@ -278,8 +277,7 @@ void Http1ServerConnectionImplTest::testTrailersExceedLimit(std::string trailer_
max_request_headers_count_, envoy::config::core::v3::HttpProtocolOptions::ALLOW);
std::string exception_reason;
NiceMock<MockRequestDecoder> decoder;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder&, bool) -> RequestDecoder& { return decoder; }));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

if (enable_trailers) {
EXPECT_CALL(decoder, decodeHeaders_(_, false));
Expand Down Expand Up @@ -339,12 +337,7 @@ void Http1ServerConnectionImplTest::testRequestHeadersAccepted(std::string heade
initialize();

NiceMock<MockRequestDecoder> decoder;
Http::ResponseEncoder* response_encoder = nullptr;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder& encoder, bool) -> RequestDecoder& {
response_encoder = &encoder;
return decoder;
}));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

Buffer::OwnedImpl buffer("GET / HTTP/1.1\r\n");
auto status = codec_->dispatch(buffer);
Expand Down Expand Up @@ -907,12 +900,7 @@ TEST_P(Http1ServerConnectionImplTest, Http10MultipleResponses) {
{
Buffer::OwnedImpl buffer("GET /foobar HTTP/1.1\r\nHost: www.somewhere.com\r\n\r\n");

Http::ResponseEncoder* response_encoder = nullptr;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder& encoder, bool) -> RequestDecoder& {
response_encoder = &encoder;
return decoder;
}));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));
EXPECT_CALL(decoder, decodeHeaders_(_, true));
auto status = codec_->dispatch(buffer);
EXPECT_TRUE(status.ok());
Expand Down Expand Up @@ -989,8 +977,7 @@ TEST_P(Http1ServerConnectionImplTest, Http11InvalidTrailerPost) {
initialize();

MockRequestDecoder decoder;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder&, bool) -> RequestDecoder& { return decoder; }));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

EXPECT_CALL(decoder, decodeHeaders_(_, false));
// Verify that body is delivered as soon as the final chunk marker is found, even if an error is
Expand Down Expand Up @@ -1147,12 +1134,7 @@ TEST_P(Http1ServerConnectionImplTest, BadRequestNoStream) {
initialize();

MockRequestDecoder decoder;
Http::ResponseEncoder* response_encoder = nullptr;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder& encoder, bool) -> RequestDecoder& {
response_encoder = &encoder;
return decoder;
}));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));
// Check that before any headers are parsed, requests do not look like HEAD or gRPC requests.
EXPECT_CALL(decoder, sendLocalReply(_, _, _, _, _));

Expand Down Expand Up @@ -1228,12 +1210,7 @@ TEST_P(Http1ServerConnectionImplTest, FloodProtection) {
// Trying to accept a third request with two buffered responses in the queue should trigger flood
// protection.
{
Http::ResponseEncoder* response_encoder = nullptr;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](Http::ResponseEncoder& encoder, bool) -> Http::RequestDecoder& {
response_encoder = &encoder;
return decoder;
}));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

Buffer::OwnedImpl buffer("GET / HTTP/1.1\r\n\r\n");
auto status = codec_->dispatch(buffer);
Expand Down Expand Up @@ -2282,8 +2259,7 @@ TEST_P(Http1ServerConnectionImplTest,
initialize();

MockRequestDecoder decoder;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder&, bool) -> RequestDecoder& { return decoder; }));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

std::array<char, 1024> buffer;
OutputBufferStream ostream{buffer.data(), buffer.size()};
Expand Down Expand Up @@ -2321,8 +2297,7 @@ TEST_P(Http1ServerConnectionImplTest, ShouldDumpDispatchBufferWithoutAllocatingM
initialize();

NiceMock<MockRequestDecoder> decoder;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder&, bool) -> RequestDecoder& { return decoder; }));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

std::array<char, 1024> buffer;
OutputBufferStream ostream{buffer.data(), buffer.size()};
Expand Down Expand Up @@ -3227,12 +3202,8 @@ TEST_P(Http1ServerConnectionImplTest, ManyRequestHeadersSplitRejected) {

std::string exception_reason;
NiceMock<MockRequestDecoder> decoder;
Http::ResponseEncoder* response_encoder = nullptr;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(Invoke([&](ResponseEncoder& encoder, bool) -> RequestDecoder& {
response_encoder = &encoder;
return decoder;
}));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

Buffer::OwnedImpl buffer("GET / HTTP/1.1\r\n");
auto status = codec_->dispatch(buffer);

Expand Down Expand Up @@ -3893,9 +3864,7 @@ TEST_P(Http1ServerConnectionImplTest, FirstReadEOF) {
ASSERT_TRUE(status.ok());

StrictMock<MockRequestDecoder> decoder;
EXPECT_CALL(callbacks_, newStream(_, _))
.WillOnce(
Invoke([&](ResponseEncoder& /*encoder*/, bool) -> RequestDecoder& { return decoder; }));
EXPECT_CALL(callbacks_, newStream(_, _)).WillOnce(ReturnRef(decoder));

Buffer::OwnedImpl buffer("GET / HTTP/1.1\r\n\r\n");
EXPECT_CALL(decoder, decodeHeaders_(_, true));
Expand Down

0 comments on commit e70c4b5

Please sign in to comment.