mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-20 03:35:55 +00:00
@@ -52,6 +52,19 @@ TEST_F(RPCDefaultProcessorTest, ValidInput)
|
||||
ASSERT_TRUE(ret); // no error
|
||||
}
|
||||
|
||||
TEST_F(RPCDefaultProcessorTest, NoInputVaildCall)
|
||||
{
|
||||
HandlerWithoutInputMock handler;
|
||||
RPCng::detail::DefaultProcessor<HandlerWithoutInputMock> processor;
|
||||
|
||||
auto const data = InOutFake{"works"};
|
||||
auto const input = json::parse(R"({})");
|
||||
EXPECT_CALL(handler, process()).WillOnce(Return(data));
|
||||
|
||||
auto const ret = processor(handler, input);
|
||||
ASSERT_TRUE(ret); // no error
|
||||
}
|
||||
|
||||
TEST_F(RPCDefaultProcessorTest, InvalidInput)
|
||||
{
|
||||
HandlerMock handler;
|
||||
|
||||
37
unittests/rpc/handlers/PingTest.cpp
Normal file
37
unittests/rpc/handlers/PingTest.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of clio: https://github.com/XRPLF/clio
|
||||
Copyright (c) 2023, the clio developers.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <rpc/common/AnyHandler.h>
|
||||
#include <rpc/ngHandlers/Ping.h>
|
||||
#include <util/Fixtures.h>
|
||||
|
||||
using namespace RPCng;
|
||||
|
||||
class RPCHandlerTest : public NoLoggerFixture
|
||||
{
|
||||
};
|
||||
|
||||
// example handler tests
|
||||
TEST_F(RPCHandlerTest, Ping)
|
||||
{
|
||||
auto const handler = AnyHandler{PingHandler{}};
|
||||
auto const output = handler.process(boost::json::parse(R"({})"));
|
||||
ASSERT_TRUE(output);
|
||||
EXPECT_EQ(output.value(), boost::json::parse(R"({})"));
|
||||
}
|
||||
@@ -50,6 +50,16 @@ TEST_F(RPCTestHandlerTest, HandlerSuccess)
|
||||
EXPECT_EQ(val.as_object().at("computed").as_string(), "world_10");
|
||||
}
|
||||
|
||||
TEST_F(RPCTestHandlerTest, NoInputHandlerSuccess)
|
||||
{
|
||||
auto const handler = AnyHandler{NoInputHandlerFake{}};
|
||||
auto const output = handler.process(json::parse(R"({})"));
|
||||
ASSERT_TRUE(output);
|
||||
|
||||
auto const val = output.value();
|
||||
EXPECT_EQ(val.as_object().at("computed").as_string(), "test");
|
||||
}
|
||||
|
||||
TEST_F(RPCTestHandlerTest, HandlerErrorHandling)
|
||||
{
|
||||
auto const handler = AnyHandler{HandlerFake{}};
|
||||
|
||||
@@ -98,6 +98,19 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class NoInputHandlerFake
|
||||
{
|
||||
public:
|
||||
using Output = TestOutput;
|
||||
using Result = RPCng::HandlerReturnType<Output>;
|
||||
|
||||
Result
|
||||
process() const
|
||||
{
|
||||
return Output{"test"};
|
||||
}
|
||||
};
|
||||
|
||||
// example handler that returns custom error
|
||||
class FailingHandlerFake
|
||||
{
|
||||
@@ -165,4 +178,12 @@ struct HandlerMock
|
||||
MOCK_METHOD(Result, process, (Input), (const));
|
||||
};
|
||||
|
||||
struct HandlerWithoutInputMock
|
||||
{
|
||||
using Output = InOutFake;
|
||||
using Result = RPCng::HandlerReturnType<Output>;
|
||||
|
||||
MOCK_METHOD(Result, process, (), (const));
|
||||
};
|
||||
|
||||
} // namespace unittests::detail
|
||||
|
||||
Reference in New Issue
Block a user