1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

chore: removed webfuse dependency in unit tests

This commit is contained in:
Falk Werner 2020-03-01 17:44:12 +01:00
parent 107e66b65a
commit ab6a6198b1
3 changed files with 16 additions and 12 deletions

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "wf/jsonrpc/proxy.h"
#include "wf/jsonrpc/status.h"
#include "wf/timer/manager.h"
#include "webfuse/core/json_util.h"
#include <thread>
#include <chrono>
@ -13,6 +13,11 @@ using namespace std::chrono_literals;
namespace
{
int jsonrpc_get_status(json_t * error)
{
json_t * code = json_object_get(error, "code");
return (json_is_integer(code)) ? json_integer_value(code) : WF_JSONRPC_BAD_FORMAT;
}
struct SendContext
{
@ -185,7 +190,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
ASSERT_FALSE(finished_context.is_called);
ASSERT_TRUE(finished_context2.is_called);
ASSERT_EQ(WF_BAD_BUSY, wf_impl_jsonrpc_get_status(finished_context2.error));
ASSERT_EQ(WF_JSONRPC_BAD_BUSY, jsonrpc_get_status(finished_context2.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
@ -206,7 +211,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid)
ASSERT_FALSE(send_context.is_called);
ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(WF_BAD, wf_impl_jsonrpc_get_status(finished_context.error));
ASSERT_EQ(WF_JSONRPC_BAD, jsonrpc_get_status(finished_context.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);
@ -296,7 +301,7 @@ TEST(wf_jsonrpc_proxy, timeout)
wf_timer_manager_check(timer_manager);
ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(WF_BAD_TIMEOUT, wf_impl_jsonrpc_get_status(finished_context.error));
ASSERT_EQ(WF_JSONRPC_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error));
wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager);

View File

@ -1,7 +1,6 @@
#include <gtest/gtest.h>
#include "wf/jsonrpc/impl/response.h"
#include "webfuse/core/status.h"
#include "webfuse/core/json_util.h"
#include "wf/jsonrpc/status.h"
TEST(wf_json_response, init_result)
{
@ -25,15 +24,16 @@ TEST(wf_json_response, init_error)
{
json_t * message = json_object();
json_t * err = json_object();
json_object_set_new(err, "code", json_integer(WF_BAD_ACCESS_DENIED));
json_object_set_new(err, "message", json_string("access denied"));
json_object_set_new(err, "code", json_integer(42));
json_object_set_new(err, "message", json_string("Don't Panic!"));
json_object_set_new(message, "error", err);
json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message);
ASSERT_EQ(WF_BAD_ACCESS_DENIED, wf_impl_jsonrpc_get_status(response.error)) << json_string_value(json_object_get(response.error, "message"));
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
ASSERT_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id);
@ -49,7 +49,7 @@ TEST(wf_json_response, init_format_error)
struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message);
ASSERT_EQ(WF_BAD_FORMAT, wf_impl_jsonrpc_get_status(response.error));
ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(12, response.id);

View File

@ -2,7 +2,6 @@
#include <gtest/gtest.h>
#include "wf/jsonrpc/impl/response.h"
#include "webfuse/core/json_util.h"
static void response_parse_str(
@ -52,7 +51,7 @@ TEST(response_parser, test)
// valid response
response_parse_str("{\"result\": true, \"id\": 42}", &response);
ASSERT_EQ(WF_GOOD, response.error);
ASSERT_EQ(nullptr, response.error);
ASSERT_EQ(42, response.id);
ASSERT_NE(nullptr, response.result);
wf_jsonrpc_impl_response_cleanup(&response);