Added unit test for feedback service.

This commit is contained in:
Markus Makela 2015-03-09 14:17:40 +02:00
parent e1a6b1de08
commit 02e742f29e
5 changed files with 101 additions and 2 deletions

View File

@ -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)
{

View File

@ -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}/)

View File

@ -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 <stdio.h>
#include <notification.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <housekeeper.h>
#include <buffer.h>
#include <regex.h>
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;
}

View File

@ -39,6 +39,8 @@
#define _NOTIFICATION_SEND_ERROR 2
#define _NOTIFICATION_REPORT_ROW_LEN 255
#include <stdint.h>
/**
* The configuration and usage information data for feeback service
*/

View File

@ -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