FlipperResponder: no response = success
Summary: If an exception is thrown from the plugin, FlipperClient.cpp will catch it and respond with an error response. If the object goes out of scope with no response being returned, then return a success response in the destructor. Reviewed By: passy Differential Revision: D14024259 fbshipit-source-id: 52e419dd23fc3882e8b92b593e8c1e1ea90e2b26
This commit is contained in:
committed by
Facebook Github Bot
parent
dfbd12cd63
commit
ff076d9dcd
@@ -18,6 +18,9 @@ namespace test {
|
||||
|
||||
using folly::dynamic;
|
||||
|
||||
void assertIsSuccess(folly::dynamic d);
|
||||
void assertIsError(folly::dynamic d);
|
||||
|
||||
TEST(FlipperResponderImplTest, testSuccessWrapper) {
|
||||
auto dynamicSingle =
|
||||
yarpl::single::Single<folly::dynamic>::create([](auto observer) mutable {
|
||||
@@ -30,6 +33,7 @@ TEST(FlipperResponderImplTest, testSuccessWrapper) {
|
||||
|
||||
to->awaitTerminalEvent();
|
||||
auto output = to->getOnSuccessValue();
|
||||
assertIsSuccess(output);
|
||||
EXPECT_EQ(output["success"]["my"], "object");
|
||||
}
|
||||
|
||||
@@ -45,9 +49,37 @@ TEST(FlipperResponderImplTest, testErrorWrapper) {
|
||||
|
||||
to->awaitTerminalEvent();
|
||||
auto output = to->getOnSuccessValue();
|
||||
assertIsError(output);
|
||||
EXPECT_EQ(output["error"]["my"], "object");
|
||||
}
|
||||
|
||||
TEST(FlipperResponderImplTest, testNoExplicitResponseReturnsSuccess) {
|
||||
auto to = yarpl::single::SingleTestObserver<folly::dynamic>::create();
|
||||
{
|
||||
auto dynamicSingle = yarpl::single::Single<folly::dynamic>::create(
|
||||
[](auto observer) mutable {
|
||||
observer->onSubscribe(yarpl::single::SingleSubscriptions::empty());
|
||||
auto responder = std::make_shared<FlipperResponderImpl>(observer);
|
||||
});
|
||||
dynamicSingle->subscribe(to);
|
||||
}
|
||||
|
||||
to->awaitTerminalEvent();
|
||||
auto output = to->getOnSuccessValue();
|
||||
assertIsSuccess(output);
|
||||
EXPECT_TRUE(output["success"].empty());
|
||||
}
|
||||
|
||||
void assertIsSuccess(folly::dynamic d) {
|
||||
EXPECT_NE(d.find("success"), d.items().end());
|
||||
EXPECT_EQ(d.find("error"), d.items().end());
|
||||
}
|
||||
|
||||
void assertIsError(folly::dynamic d) {
|
||||
EXPECT_NE(d.find("error"), d.items().end());
|
||||
EXPECT_EQ(d.find("success"), d.items().end());
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace flipper
|
||||
} // namespace facebook
|
||||
|
||||
Reference in New Issue
Block a user