Add more tests
This commit is contained in:
@ -1,13 +1,34 @@
|
|||||||
add_executable(test_hash testhash.c)
|
add_executable(test_hash testhash.c)
|
||||||
add_executable(test_spinlock testspinlock.c)
|
add_executable(test_spinlock testspinlock.c)
|
||||||
add_executable(test_filter testfilter.c)
|
add_executable(test_filter testfilter.c)
|
||||||
|
add_executable(test_buffer testbuffer.c)
|
||||||
|
add_executable(test_dcb testdcb.c)
|
||||||
|
add_executable(test_modutil testmodutil.c)
|
||||||
|
add_executable(test_poll testpoll.c)
|
||||||
|
add_executable(test_service testservice.c)
|
||||||
|
add_executable(test_server testserver.c)
|
||||||
|
add_executable(test_users testusers.c)
|
||||||
add_executable(test_adminusers testadminusers.c)
|
add_executable(test_adminusers testadminusers.c)
|
||||||
target_link_libraries(test_hash fullcore)
|
target_link_libraries(test_hash fullcore)
|
||||||
target_link_libraries(test_spinlock fullcore)
|
target_link_libraries(test_spinlock fullcore)
|
||||||
target_link_libraries(test_filter fullcore)
|
target_link_libraries(test_filter fullcore)
|
||||||
|
target_link_libraries(test_buffer fullcore)
|
||||||
|
target_link_libraries(test_dcb fullcore)
|
||||||
|
target_link_libraries(test_modutil fullcore)
|
||||||
|
target_link_libraries(test_poll fullcore)
|
||||||
|
target_link_libraries(test_service fullcore)
|
||||||
|
target_link_libraries(test_server fullcore)
|
||||||
|
target_link_libraries(test_users fullcore)
|
||||||
target_link_libraries(test_adminusers fullcore)
|
target_link_libraries(test_adminusers fullcore)
|
||||||
add_test(TestHash test_hash)
|
add_test(TestHash test_hash)
|
||||||
add_test(TestSpinlock test_spinlock)
|
add_test(TestSpinlock test_spinlock)
|
||||||
add_test(TestFilter test_filter)
|
add_test(TestFilter test_filter)
|
||||||
|
add_test(TestBuffer test_buffer)
|
||||||
|
add_test(TestDCB test_dcb)
|
||||||
|
add_test(TestModutil test_modutil)
|
||||||
|
add_test(TestPoll test_poll)
|
||||||
|
add_test(TestService test_service)
|
||||||
|
add_test(TestServer test_server)
|
||||||
|
add_test(TestUsers test_users)
|
||||||
add_test(TestAdminUsers test_adminusers)
|
add_test(TestAdminUsers test_adminusers)
|
||||||
|
|
||||||
|
|||||||
89
server/core/test/testserver.c
Normal file
89
server/core/test/testserver.c
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of MaxScale. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2014
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @verbatim
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 08-10-2014 Martin Brampton Initial implementation
|
||||||
|
*
|
||||||
|
* @endverbatim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <server.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test1 Allocate a server and do lots of other things
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
test1()
|
||||||
|
{
|
||||||
|
SERVER *server;
|
||||||
|
int result;
|
||||||
|
char *status;
|
||||||
|
|
||||||
|
/* Server tests */
|
||||||
|
ss_dfprintf(stderr,
|
||||||
|
"testserver : creating server called MyServer");
|
||||||
|
server = server_alloc("MyServer", "HTTPD", 9876);
|
||||||
|
ss_info_dassert(NULL != service, "New server with valid protocol and port must not be null");
|
||||||
|
ss_info_dassert(0 != service_isvalid(service), "Service must be valid after creation");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nTest Parameter for Server.");
|
||||||
|
ss_info_dassert(NULL == serverGetParameter(server, "name"), "Parameter should be null when not set");
|
||||||
|
serverAddParameter(server, "name", "value");
|
||||||
|
ss_info_dassert(0 == strcmp("value", serverGetParameter(server, "name")), "Parameter should be returned correctly");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nTesting Unique Name for Server.");
|
||||||
|
ss_info_dassert(NULL == server_find_by_unique_name("uniquename"), "Should not find non-existent unique name.");
|
||||||
|
server_set_unique_name(server, "uniquename");
|
||||||
|
ss_info_dassert(server == server_find_by_unique_name("uniquename"), "Should find by unique name.");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nTesting Status Setting for Server.");
|
||||||
|
status = server_status(server);
|
||||||
|
ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down prior to being set.");
|
||||||
|
if (NULL != status) free(status);
|
||||||
|
server_set_status(server, SERVER_MASTER);
|
||||||
|
status = server_status(server);
|
||||||
|
ss_info_dassert(0 == strcmp("Master, Down", status), "Should find correct status.");
|
||||||
|
server_clear_status(server, SERVER_MASTER);
|
||||||
|
ss_info_dassert(0 == strcmp("Down", status), "Status of Server should be Down after status cleared.");
|
||||||
|
if (NULL != status) free(status);
|
||||||
|
ss_dfprintf(stderr, "\t..done\nRun Prints for Server and all Servers.");
|
||||||
|
printServer(server);
|
||||||
|
printAllServers();
|
||||||
|
ss_dfprintf(stderr, "\t..done\nFreeing Server.");
|
||||||
|
ss_info_dassert(0 != server_free(server), "Free should succeed");
|
||||||
|
ss_dfprintf(stderr, "\t..done\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
result += test1();
|
||||||
|
|
||||||
|
exit(result);
|
||||||
|
}
|
||||||
@ -46,7 +46,7 @@ int result;
|
|||||||
/* Service tests */
|
/* Service tests */
|
||||||
ss_dfprintf(stderr,
|
ss_dfprintf(stderr,
|
||||||
"testservice : creating service called MyService with router nonexistent");
|
"testservice : creating service called MyService with router nonexistent");
|
||||||
service = service_alloc("MyService", "nonexistent");
|
service = service_alloc("MyService", "non-existent");
|
||||||
ss_info_dassert(NULL == service, "New service with invalid router should be null");
|
ss_info_dassert(NULL == service, "New service with invalid router should be null");
|
||||||
ss_info_dassert(0 == service_isvalid(service), "Service must not be valid after incorrect creation");
|
ss_info_dassert(0 == service_isvalid(service), "Service must not be valid after incorrect creation");
|
||||||
ss_dfprintf(stderr, "\t..done\nValid service creation, router testroute.");
|
ss_dfprintf(stderr, "\t..done\nValid service creation, router testroute.");
|
||||||
|
|||||||
81
server/core/test/testusers.c
Normal file
81
server/core/test/testusers.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* This file is distributed as part of MaxScale. It is free
|
||||||
|
* software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation,
|
||||||
|
* version 2.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Copyright SkySQL Ab 2014
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @verbatim
|
||||||
|
* Revision History
|
||||||
|
*
|
||||||
|
* Date Who Description
|
||||||
|
* 08-10-2014 Martin Brampton Initial implementation
|
||||||
|
*
|
||||||
|
* @endverbatim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <users.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test1 Allocate table of users and mess around with it
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
test1()
|
||||||
|
{
|
||||||
|
USERS *users;
|
||||||
|
int result, count;
|
||||||
|
|
||||||
|
/* Poll tests */
|
||||||
|
ss_dfprintf(stderr,
|
||||||
|
"testusers : Initialise the user table.");
|
||||||
|
users = users_alloc();
|
||||||
|
ss_info_dassert(NULL != servers, "Allocating user table should not return NULL.")
|
||||||
|
ss_dfprintf(stderr, "\t..done\nAdd a user");
|
||||||
|
count = users_add(users, "username", "authorisation");
|
||||||
|
ss_info_dassert(1 == count, "Should add one user");
|
||||||
|
ss_info_dassert(strcmp("authorisation", users_fetch(users, "username")), "User authorisation should be correct");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nPrint users");
|
||||||
|
usersPrint(users);
|
||||||
|
ss_dfprintf(stderr, "\t..done\nUpdate a user");
|
||||||
|
count = users_update(users, "username", "newauth");
|
||||||
|
ss_info_dassert(1 == count, "Should update just one user");
|
||||||
|
ss_info_dassert(strcmp("newauth", users_fetch(users, "username")), "User authorisation should be correctly updated");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nDelete a user.");
|
||||||
|
count = users_delete(users, "username");
|
||||||
|
ss_info_dassert(1 == count, "Should delete just one user");
|
||||||
|
ss_dfprintf(stderr, "\t..done\nFree user table.");
|
||||||
|
users_free(users);
|
||||||
|
ss_dfprintf(stderr, "\t..done\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
result += test1();
|
||||||
|
|
||||||
|
exit(result);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user