proxygen
EchoHandlerTest.cpp File Reference

Go to the source code of this file.

Classes

class  MockEchoStats
 
class  EchoHandlerFixture
 

Functions

 TEST_F (EchoHandlerFixture, OnProperRequestSendsResponse)
 
 TEST_F (EchoHandlerFixture, ReplaysBodyProperly)
 

Function Documentation

TEST_F ( EchoHandlerFixture  ,
OnProperRequestSendsResponse   
)

Definition at line 49 of file EchoHandlerTest.cpp.

References testing::_, testing::DoAll(), EXPECT_CALL, EXPECT_EQ, proxygen::HTTPMessage::getHeaders(), proxygen::HTTPHeaders::getSingleOrEmpty(), proxygen::HTTPMessage::getStatusCode(), handler(), and testing::Return().

49  {
50  EXPECT_CALL(stats, recordRequest()).WillOnce(Return());
51  EXPECT_CALL(stats, getRequestCount()).WillOnce(Return(5));
52 
53  HTTPMessage response;
54  EXPECT_CALL(*responseHandler, sendHeaders(_)).WillOnce(
55  DoAll(SaveArg<0>(&response), Return()));
56  EXPECT_CALL(*responseHandler, sendEOM()).WillOnce(Return());
57 
58  // Since we know we dont touch request, its ok to pass `nullptr` here.
59  handler->onRequest(nullptr);
60  handler->onEOM();
61  handler->requestComplete();
62 
63  EXPECT_EQ("5", response.getHeaders().getSingleOrEmpty("Request-Number"));
64  EXPECT_EQ(200, response.getStatusCode());
65 }
uint16_t getStatusCode() const
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
const std::string & getSingleOrEmpty(const T &nameOrCode) const
Definition: HTTPHeaders.h:420
internal::DoBothAction< Action1, Action2 > DoAll(Action1 a1, Action2 a2)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
TEST_F ( EchoHandlerFixture  ,
ReplaysBodyProperly   
)

Definition at line 67 of file EchoHandlerTest.cpp.

References testing::_, b, folly::IOBuf::copyBuffer(), testing::DoAll(), EXPECT_CALL, EXPECT_EQ, proxygen::HTTPMessage::getHeaders(), proxygen::HTTPHeaders::getSingleOrEmpty(), proxygen::HTTPMessage::getStatusCode(), handler(), testing::Invoke(), and testing::Return().

67  {
68  EXPECT_CALL(stats, recordRequest()).WillOnce(Return());
69  EXPECT_CALL(stats, getRequestCount()).WillOnce(Return(5));
70 
71  HTTPMessage response;
72  folly::fbstring body;
73 
74  EXPECT_CALL(*responseHandler, sendHeaders(_)).WillOnce(
75  DoAll(SaveArg<0>(&response), Return()));
76 
77  EXPECT_CALL(*responseHandler, sendBody(_)).WillRepeatedly(
78  DoAll(
79  Invoke([&] (std::shared_ptr<folly::IOBuf> b) {
80  body += b->moveToFbString();
81  }),
82  Return()));
83 
84  EXPECT_CALL(*responseHandler, sendEOM()).WillOnce(Return());
85 
86  // Since we know we dont touch request, its ok to pass `nullptr` here.
87  handler->onRequest(nullptr);
88  handler->onBody(folly::IOBuf::copyBuffer("part1"));
89  handler->onBody(folly::IOBuf::copyBuffer("part2"));
90  handler->onEOM();
91  handler->requestComplete();
92 
93  EXPECT_EQ("5", response.getHeaders().getSingleOrEmpty("Request-Number"));
94  EXPECT_EQ(200, response.getStatusCode());
95  EXPECT_EQ("part1part2", body);
96 }
char b
uint16_t getStatusCode() const
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
const std::string & getSingleOrEmpty(const T &nameOrCode) const
Definition: HTTPHeaders.h:420
internal::DoBothAction< Action1, Action2 > DoAll(Action1 a1, Action2 a2)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
internal::ReturnAction< R > Return(R value)