From 02e742f29e231f82bf11a3d286b06a4dfa598479 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 9 Mar 2015 14:17:40 +0200 Subject: [PATCH] Added unit test for feedback service. --- server/core/config.c | 2 +- server/core/test/CMakeLists.txt | 6 ++- server/core/test/testfeedback.c | 86 +++++++++++++++++++++++++++++++++ server/include/notification.h | 2 + server/test/MaxScale_test.cnf | 7 +++ 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 server/core/test/testfeedback.c diff --git a/server/core/config.c b/server/core/config.c index c7c0158e7..d9534aeff 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -1291,7 +1291,7 @@ handle_feedback_item(const char *name, const char *value) int i; if (strcmp(name, "feedback_enable") == 0) { - feedback.feedback_enable = atoi(value); + feedback.feedback_enable = config_truth_value(value); } else if (strcmp(name, "feedback_user_info") == 0) { diff --git a/server/core/test/CMakeLists.txt b/server/core/test/CMakeLists.txt index 2a0977088..0cff62772 100644 --- a/server/core/test/CMakeLists.txt +++ b/server/core/test/CMakeLists.txt @@ -12,6 +12,7 @@ add_executable(test_server testserver.c) add_executable(test_users testusers.c) add_executable(test_adminusers testadminusers.c) add_executable(testmemlog testmemlog.c) +add_executable(testfeedback testfeedback.c) target_link_libraries(test_mysql_users MySQLClient fullcore) target_link_libraries(test_hash fullcore) target_link_libraries(test_hint fullcore) @@ -26,6 +27,7 @@ target_link_libraries(test_server fullcore) target_link_libraries(test_users fullcore) target_link_libraries(test_adminusers fullcore) target_link_libraries(testmemlog fullcore) +target_link_libraries(testfeedback fullcore) add_test(testMySQLUsers test_mysql_users) add_test(TestHash test_hash) add_test(TestHint test_hint) @@ -40,6 +42,7 @@ add_test(TestServer test_server) add_test(TestUsers test_users) add_test(TestAdminUsers test_adminusers) add_test(TestMemlog testmemlog) +add_test(TestFeedback testfeedback) set_tests_properties(testMySQLUsers TestHash TestHint @@ -53,4 +56,5 @@ set_tests_properties(testMySQLUsers TestServer TestUsers TestAdminUsers - TestMemlog PROPERTIES ENVIRONMENT MAXSCALE_HOME=${CMAKE_BINARY_DIR}/) + TestMemlog + TestFeedback PROPERTIES ENVIRONMENT MAXSCALE_HOME=${CMAKE_BINARY_DIR}/) diff --git a/server/core/test/testfeedback.c b/server/core/test/testfeedback.c new file mode 100644 index 000000000..cb363e39e --- /dev/null +++ b/server/core/test/testfeedback.c @@ -0,0 +1,86 @@ +/* + * 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 MariaDB Corporation Ab 2014 + */ + +/** + * + * @verbatim + * Revision History + * + * Date Who Description + * 09-03-2015 Markus Mäkelä Initial implementation + * + * @endverbatim + */ + +#define FAILTEST(s) printf("TEST FAILED: " s "\n");return 1; + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + FEEDBACK_CONF* fc; + char* home; + char* cnf; + GWBUF* buf; + regex_t re; + + hkinit(); + home = getenv("MAXSCALE_HOME"); + + if(home == NULL) + { + FAILTEST("MAXSCALE_HOME was not defined."); + } + printf("Home: %s\n",home); + + cnf = malloc(strlen(home) + strlen("/etc/MaxScale.cnf") + 1); + strcpy(cnf,home); + strcat(cnf,"/etc/MaxScale.cnf"); + + printf("Config: %s\n",cnf); + + config_load(cnf); + + if((fc = config_get_feedback_data()) == NULL || + fc->feedback_user_info == NULL) + { + FAILTEST("Configuration was NULL."); + } + + regcomp(&re,fc->feedback_user_info,0); + + config_enable_feedback_task(); + module_create_feedback_report(&buf,NULL,fc); + printf("%s",(char*)buf->start); + + if(regexec(&re,(char*)buf->start,0,NULL,0)) + { + FAILTEST("Regex match of 'user_info' failed."); + } + + config_disable_feedback_task(); + return 0; +} diff --git a/server/include/notification.h b/server/include/notification.h index 349edd707..6a7f07bac 100644 --- a/server/include/notification.h +++ b/server/include/notification.h @@ -39,6 +39,8 @@ #define _NOTIFICATION_SEND_ERROR 2 #define _NOTIFICATION_REPORT_ROW_LEN 255 +#include + /** * The configuration and usage information data for feeback service */ diff --git a/server/test/MaxScale_test.cnf b/server/test/MaxScale_test.cnf index aeaea2d69..f6887c3e0 100644 --- a/server/test/MaxScale_test.cnf +++ b/server/test/MaxScale_test.cnf @@ -1,6 +1,13 @@ [maxscale] threads=4 +[feedback] +feedback_enable=true +feedback_user_info=user_info +feedback_url=http://127.0.0.1:8080/load.php +feedback_timeout=60 +feedback_connect_timeout=60 + [MySQL Monitor] type=monitor module=mysqlmon