diff --git a/test/tap/constants b/test/tap/constants new file mode 100644 index 000000000..cc385c79f --- /dev/null +++ b/test/tap/constants @@ -0,0 +1,13 @@ +# This file should be modified locally according to proxysql configuration. +# All TAP tests depend on these environment variables. +# +# Usage: source this file before running TAP tests +# $ . constants +# or +# $ source constants +# +export TAP_HOST=127.0.0.1 +export TAP_PORT=6033 +export TAP_USERNAME=root +export TAP_PASSWORD=REDACTED +export TAP_WORKDIR=./tests/ diff --git a/test/tap/tests/Makefile b/test/tap/tests/Makefile index be7a0eb6d..d16445bb1 100644 --- a/test/tap/tests/Makefile +++ b/test/tap/tests/Makefile @@ -79,39 +79,16 @@ all: tests .PHONY: clean clean: - rm -f basic-t set_character_set-t charset_unsigned_int-t select_config_file-t sqlite3-t galera_1_timeout_count galera_2_timeout_no_count aurora test_set_character_results-t test_ps_large_result-t set_testing-t test_firewall-t test_default_value_transaction_isolation-t || true + rm -f *-t galera_1_timeout_count galera_2_timeout_no_count aurora || true OPT=-O2 -Wl,--no-as-needed -SRC=basic-t.cpp set_character_set-t.cpp charset_unsigned_int-t.cpp select_config_file-t.cpp sqlite3-t.cpp galera_1_timeout_count.cpp galera_2_timeout_no_count.cpp aurora.cpp test_set_character_results-t.cpp test_ps_large_result-t.cpp set_testing-t.cpp test_firewall-t.cpp test_default_value_transaction_isolation-t.cpp - -tests: basic-t set_character_set-t charset_unsigned_int-t select_config_file-t sqlite3-t test_set_character_results-t test_ps_large_result-t set_testing-t test_firewall-t test_default_value_transaction_isolation-t +tests: $(patsubst %.cpp,%,$(wildcard *-t.cpp)) testgalera: galera_1_timeout_count galera_2_timeout_no_count testaurora: aurora -sqlite3-t: $(TAP_LIBDIR)/libtap.a sqlite3-t.cpp - g++ sqlite3-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) $(MYLIBS) -lpthread -ldl -std=c++11 -ltap $(STATIC_LIBS) -o sqlite3-t - -basic-t: $(TAP_LIBDIR)/libtap.a - g++ basic-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 -ltap $(STATIC_LIBS) -o basic-t - -set_character_set-t: set_character_set-t.cpp $(TAP_LIBDIR)/libtap.a - g++ set_character_set-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 -ltap -ldl $(MYLIBS) $(STATIC_LIBS) -o set_character_set-t - -charset_unsigned_int-t: charset_unsigned_int-t.cpp $(TAP_LIBDIR)/libtap.a - g++ charset_unsigned_int-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 -ltap -ldl $(MYLIBS) $(STATIC_LIBS) -o charset_unsigned_int-t - -select_config_file-t: select_config_file-t.cpp $(TAP_LIBDIR)/libtap.a - g++ select_config_file-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 -ltap -ldl $(MYLIBS) $(STATIC_LIBS) -o select_config_file-t - -test_set_character_results-t: test_set_character_results-t.cpp $(TAP_LIBDIR)/libtap.a - g++ test_set_character_results-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -ldl -lpthread $(STATIC_LIBS) -o test_set_character_results-t - -test_ps_large_result-t: test_ps_large_result-t.cpp $(TAP_LIBDIR)/libtap.a - g++ test_ps_large_result-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -ldl -lpthread $(STATIC_LIBS) -o test_ps_large_result-t - -test_firewall-t: test_firewall-t.cpp $(TAP_LIBDIR)/libtap.a - g++ test_firewall-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -ldl -lpthread $(STATIC_LIBS) -o test_firewall-t +%-t:%-t.cpp $(TAP_LIBDIR)/libtap.a + $(CXX) $^ $(INCLUDEDIRS) $(LDIRS) $(OPT) $(MYLIBS) -lpthread -ldl -std=c++11 -ltap $(STATIC_LIBS) -o $@ galera_1_timeout_count: galera_1_timeout_count.cpp $(TAP_LIBDIR)/libtap.a g++ -DTEST_GALERA -DDEBUG galera_1_timeout_count.cpp ../tap/SQLite3_Server.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o galera_1_timeout_count -DGITVERSION=\"$(GIT_VERSION)\" @@ -122,9 +99,3 @@ galera_2_timeout_no_count: galera_2_timeout_no_count.cpp $(TAP_LIBDIR)/libtap.a aurora: aurora.cpp $(TAP_LIBDIR)/libtap.a g++ -DTEST_AURORA -DDEBUG aurora.cpp ../tap/SQLite3_Server.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o aurora -DGITVERSION=\"$(GIT_VERSION)\" -set_testing-t: set_testing-t.cpp $(TAP_LIBDIR)/libtap.a - g++ set_testing-t.cpp -Wall $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -pthread -ldl $(STATIC_LIBS) -o set_testing-t - -test_default_value_transaction_isolation-t: test_default_value_transaction_isolation-t.cpp $(TAP_LIBDIR)/libtap.a - g++ test_default_value_transaction_isolation-t.cpp -Wall $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -ltap -pthread -ldl $(STATIC_LIBS) -o test_default_value_transaction_isolation-t - diff --git a/test/tap/tests/select_config_file-t.cpp b/test/tap/tests/select_config_file-t.cpp deleted file mode 100644 index 9f2c17f97..000000000 --- a/test/tap/tests/select_config_file-t.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include "tap.h" -#include "command_line.h" -#include "utils.h" - -int select_config_file(MYSQL* mysql, std::string& resultset) { - if (mysql_query(mysql, "select config file")) { - fprintf(stderr, "File %s, line %d, Error: 2 %s\n", - __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } - - MYSQL_RES *result; - MYSQL_ROW row; - result = mysql_store_result(mysql); - if (result) { - row = mysql_fetch_row(result); - resultset = row[0]; - mysql_free_result(result); - } else { - fprintf(stderr, "error\n"); - } - -} - - -int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - - plan(1); - diag("Testing SELECT CONFIG INTO OUTFILE"); - - MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - - if (!mysql_real_connect(mysql, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } - - MYSQL_QUERY(mysql, "delete from global_variables"); - MYSQL_QUERY(mysql, "delete from mysql_users"); - MYSQL_QUERY(mysql, "delete from mysql_servers"); - MYSQL_QUERY(mysql, "delete from mysql_query_rules"); - MYSQL_QUERY(mysql, "delete from mysql_replication_hostgroups"); - MYSQL_QUERY(mysql, "delete from mysql_group_replication_hostgroups"); - MYSQL_QUERY(mysql, "delete from mysql_galera_hostgroups"); - MYSQL_QUERY(mysql, "delete from mysql_aws_aurora_hostgroups"); - MYSQL_QUERY(mysql, "delete from scheduler"); - MYSQL_QUERY(mysql, "delete from restapi_routes"); - MYSQL_QUERY(mysql, "delete from proxysql_servers"); - - MYSQL_QUERY(mysql, "insert into proxysql_servers (hostname, port, weight, comment) values ('hostname', 3333, 12, 'comment');"); - MYSQL_QUERY(mysql, "insert into scheduler (id, active, interval_ms, filename, arg1, arg2, arg3, arg4, arg5, comment) values " - " (1,1,1000,'filename','a1','a2','a3','a4','a5','comment');"); - MYSQL_QUERY(mysql, "insert into restapi_routes values " - " (1,1,1000,'GET', 'test','./scripts/script.py','comment');"); - MYSQL_QUERY(mysql, "insert into mysql_aws_aurora_hostgroups (writer_hostgroup, reader_hostgroup, active, aurora_port, " - " domain_name, max_lag_ms, check_interval_ms, check_timeout_ms, writer_is_also_reader, new_reader_weight, " - " add_lag_ms, min_lag_ms, lag_num_checks, comment) " - " values (1,2,1,3,'.domain.net',20,106,107,1,9,10,20,1,'comment');"); - MYSQL_QUERY(mysql, "insert into mysql_galera_hostgroups (writer_hostgroup, backup_writer_hostgroup, reader_hostgroup, offline_hostgroup, " - " active, max_writers, writer_is_also_reader, max_transactions_behind, comment) values (1,2,3,4,1,23,1,1,'comment');"); - MYSQL_QUERY(mysql, "insert into mysql_group_replication_hostgroups (writer_hostgroup, backup_writer_hostgroup, reader_hostgroup, offline_hostgroup, " - " active, max_writers, writer_is_also_reader, max_transactions_behind, comment) values (1,2,3,4,1,23,1,1,'comment');"); - MYSQL_QUERY(mysql, "insert into mysql_replication_hostgroups (writer_hostgroup, reader_hostgroup, check_type, comment) " - " values (10,20,'read_only','Master / Slave App 1');"); - MYSQL_QUERY(mysql, "insert into mysql_servers (hostgroup_id, hostname, port, gtid_port, status, weight, compression, max_connections, " - " max_replication_lag, use_ssl, max_latency_ms, comment) values (0,'127.0.0.1',3306,0,'ONLINE',1,0,1000,0,0,0,'comment2');"); - MYSQL_QUERY(mysql, "insert into mysql_query_rules (rule_id, active, username, schemaname, flagIN, client_addr, proxy_addr, proxy_port, digest, " - " match_digest, match_pattern, negate_match_pattern, re_modifiers, flagOUT, replace_pattern, destination_hostgroup, cache_ttl, cache_empty_result, " - " cache_timeout, reconnect, timeout, retries, delay, next_query_flagIN, mirror_flagOUT, mirror_hostgroup, " - " error_msg, OK_msg, sticky_conn, multiplex, gtid_from_hostgroup, log, apply, comment) values " - " (1, 1, 'user', 'schema', 0, '.domain.com', '.proxy.com', 3333, 'ABC1', 'ABC', '^SELECT *', 0, 'CASE', 0, 1, 1, " - " 1, 1, 100, 1, 1, 100, 100, 0, 0, 1, 'Error', 'OK', 0, 0, 0, 0, 0, 'comm1')"); - MYSQL_QUERY(mysql, "insert into mysql_users (username, password, active, use_ssl, default_hostgroup, default_schema, schema_locked, " - " transaction_persistent, fast_forward, backend, frontend, max_connections, comment) values " - " ('user', 'password', 1, 0, 0, 'schema', 1, 0, 1, 1, 1, 10, 'comm1')"); - - MYSQL_QUERY(mysql, "update global_variables set variable_value='admin' where variable_name like 'admin-%'"); - MYSQL_QUERY(mysql, "update global_variables set variable_value='mysql' where variable_name like 'mysql-%'"); - - MYSQL_QUERY(mysql, "load mysql servers to runtime"); - - std::string resultset; - resultset.reserve(100000); - select_config_file(mysql, resultset); - - { - std::ifstream inFile; - inFile.open(std::string(cl.workdir) + "/proxysql_reference_select_config_file.cnf"); //open the input file - - std::stringstream strStream; - strStream << inFile.rdbuf(); //read the file - std::string str = strStream.str(); //str holds the content of the file - - ok(!str.compare(resultset), "Files are equal"); -#if 0 - std::ofstream f; - f.open("out.txt", std::ios::out); - f << resultset; - f.close(); -#endif - - } - -#if 0 - std::ofstream out("output.cnf"); - out << resultset; - out.close(); -#endif - - MYSQL_QUERY(mysql, "load mysql variables from disk"); - MYSQL_QUERY(mysql, "load mysql variables to runtime"); - MYSQL_QUERY(mysql, "load admin variables from disk"); - MYSQL_QUERY(mysql, "load admin variables to runtime"); - MYSQL_QUERY(mysql, "load mysql users from disk"); - MYSQL_QUERY(mysql, "load mysql users to runtime"); - MYSQL_QUERY(mysql, "load mysql servers from disk"); - MYSQL_QUERY(mysql, "load mysql servers to runtime"); - MYSQL_QUERY(mysql, "load scheduler from disk"); - MYSQL_QUERY(mysql, "load scheduler to runtime"); - MYSQL_QUERY(mysql, "load restapi from disk"); - MYSQL_QUERY(mysql, "load restapi to runtime"); - MYSQL_QUERY(mysql, "load proxysql servers from disk"); - MYSQL_QUERY(mysql, "load proxysql servers to runtime"); - - mysql_close(mysql); - - return exit_status(); -} -