Add rest tests.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
NADAL Jean-Baptiste
2020-01-13 16:09:57 +01:00
parent 9ffd1a4e55
commit da29aa6516
12 changed files with 206 additions and 89 deletions

70
src/tests/test_rest.c Normal file
View File

@@ -0,0 +1,70 @@
/*!
* test_rest.c
*
* Copyright (c) 2015-2020, NADAL Jean-Baptiste. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* @Author: NADAL Jean-Baptiste
* @Date: 08/01/2020
*
*/
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
/*--------------------------------------------------------------------------*/
int my_test_handler(short event, restd_conn_t *conn, void *userdata)
{
restd_http_response(conn, 200, "application/json", "{\"status\":\"error\"}", 18);
return RESTD_CLOSE; // Close connection.
}
TEST("Rest - create free\t")
{
restd_server_t *rest_server;
rest_server = restd_server_new();
ASSERT_NOT_NULL(rest_server);
restd_server_set_option(rest_server, "server.port", "7777");
restd_server_register_hook_on_path(rest_server, "POST", "/api/v1/test", my_test_handler, NULL);
restd_server_free(rest_server);
}
TEST("Rest - create free\t")
{
restd_server_t *rest_server;
rest_server = restd_server_new();
ASSERT_NOT_NULL(rest_server);
restd_server_set_option(rest_server, "server.port", "7777");
restd_server_register_hook_on_path(rest_server, "POST", "/api/v1/test", my_test_handler, NULL);
restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test", my_test_handler, NULL);
restd_server_register_hook_on_path(rest_server, "GET", "/api/v1/test/:id", my_test_handler, NULL);
restd_server_register_hook_on_path(rest_server, "PUT", "/api/v1/test/:id", my_test_handler, NULL);
restd_server_register_hook_on_path(rest_server, "DELETE", "/api/v1/test/:id", my_test_handler, NULL);
restd_server_free(rest_server);
}