-
-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/integration-tests: move mysql-client-tests to integration-tests
- Loading branch information
1 parent
d08a454
commit 503665c
Showing
34 changed files
with
1,447 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mysql-client-tests/c/mysql-client-tests | ||
mysql-client-tests/java/MySQLConnectorTest.class | ||
mysql-client-tests/cpp/_build/**/* | ||
mysql-client-tests/cpp/_build | ||
integration-tests/mysql-client-tests/c/mysql-client-tests | ||
integration-tests/mysql-client-tests/java/MySQLConnectorTest.class | ||
integration-tests/mysql-client-tests/cpp/_build/**/* | ||
integration-tests/mysql-client-tests/cpp/_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
c/mysql-connector-c-test | ||
cpp/_build | ||
java/MySQLConnectorTest.class | ||
java/mysql-connector-java-8.0.21.jar | ||
node/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## MySQL Client Tests | ||
We created smoke tests for Dolt's MySQL client integrations and we run these tests through Github Actions | ||
on pull requests. | ||
|
||
These tests can be run locally using Docker. From the root directory of this repo, run: | ||
```bash | ||
$ docker build -t mysql-client-tests -f MySQLDockerfile . | ||
$ docker run mysql-client-tests:latest | ||
``` | ||
|
||
The `docker build` step will take a few minutes to complete as it needs to install all of the | ||
dependencies in the image. | ||
|
||
Running the built container will produce output like: | ||
```bash | ||
$ docker run mysql-client-tests:latest | ||
updating dolt config for tests: | ||
Config successfully updated. | ||
Config successfully updated. | ||
Config successfully updated. | ||
Config successfully updated. | ||
Running mysql-client-tests: | ||
1..4 | ||
ok 1 python mysql.connector client | ||
ok 2 python pymysql client | ||
ok 3 mysql-connector-java client | ||
ok 4 node mysql client | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CFLAGS := $(shell pkg-config --cflags mysqlclient) | ||
LDFLAGS := $(shell pkg-config --libs mysqlclient) | ||
|
||
all: mysql-connector-c-test | ||
|
||
mysql-connector-c-test: mysql-connector-c-test.c | ||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f mysql-connector-c-test |
170 changes: 170 additions & 0 deletions
170
integration-tests/mysql-client-tests/c/mysql-connector-c-test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <memory.h> | ||
#include <mysql.h> | ||
|
||
#define QUERIES_SIZE 5 | ||
|
||
char *queries[QUERIES_SIZE] = | ||
{ | ||
"create table test (pk int, `value` int, primary key(pk))", | ||
"describe test", | ||
"select * from test", | ||
"insert into test (pk, `value`) values (0,0)", | ||
"select * from test" | ||
}; | ||
|
||
typedef struct statement_t { | ||
char *query; | ||
MYSQL_BIND bind[10]; | ||
int expect_prepare_error; | ||
int expect_exec_error; | ||
} statement; | ||
|
||
void test_statement(MYSQL *con, statement *stmt) { | ||
MYSQL_STMT *mstmt = mysql_stmt_init(con); | ||
if (!mstmt) { | ||
fprintf(stderr, "failed to init stmt: %s\n", mysql_error(con)); | ||
exit(1); | ||
} | ||
if ( mysql_stmt_prepare(mstmt, stmt->query, strlen(stmt->query)) ) { | ||
if ( !stmt->expect_prepare_error) { | ||
fprintf(stderr, "failed to prepare stmt: %s: %s\n", stmt->query, mysql_stmt_error(mstmt)); | ||
exit(1); | ||
} else { | ||
goto close; | ||
} | ||
} | ||
if ( mysql_stmt_bind_param(mstmt, stmt->bind) ) { | ||
fprintf(stderr, "failed to bind stmt: %s: %s\n", stmt->query, mysql_stmt_error(mstmt)); | ||
exit(1); | ||
} | ||
if ( mysql_stmt_execute(mstmt) ) { | ||
if ( !stmt->expect_exec_error) { | ||
fprintf(stderr, "failed to execute stmt: %s: %s\n", stmt->query, mysql_stmt_error(mstmt)); | ||
exit(1); | ||
} | ||
} | ||
close: | ||
if ( mysql_stmt_close(mstmt) ) { | ||
fprintf(stderr, "failed to close stmt: %s: %s\n", stmt->query, mysql_error(con)); | ||
exit(1); | ||
} | ||
} | ||
|
||
statement LAST_STATEMENT = { | ||
}; | ||
|
||
int main(int argc, char **argv) { | ||
|
||
char* user = argv[1]; | ||
int port = atoi(argv[2]); | ||
char* db = argv[3]; | ||
|
||
MYSQL *con = mysql_init(NULL); | ||
|
||
if ( con == NULL ) { | ||
fprintf(stderr, "%s\n", mysql_error(con)); | ||
exit(1); | ||
} | ||
|
||
if ( mysql_real_connect(con, | ||
"127.0.0.1", | ||
user, | ||
"", | ||
db, | ||
port, | ||
NULL, | ||
0 ) == NULL) { | ||
fprintf(stderr, "%s\n", mysql_error(con)); | ||
mysql_close(con); | ||
exit(1); | ||
} | ||
|
||
for ( int i = 0; i < QUERIES_SIZE; i++ ) { | ||
if ( mysql_query(con, queries[i]) ) { | ||
printf("QUERY FAILED: %s\n", queries[i]); | ||
fprintf(stderr, "%s\n", mysql_error(con)); | ||
mysql_close(con); | ||
exit(1); | ||
} else { | ||
// Not checking validity of results for now | ||
MYSQL_RES* result = mysql_use_result(con); | ||
mysql_free_result(result); | ||
} | ||
} | ||
|
||
int pk = 1; | ||
int value = 12; | ||
unsigned long string_len = 16; | ||
statement statements[] = { | ||
{ | ||
.query = "select * from test where pk = ?", | ||
.bind = { | ||
[0] = { | ||
.buffer_type = MYSQL_TYPE_LONG, | ||
.buffer = (void *)(&pk), | ||
.buffer_length = sizeof(pk), | ||
}, | ||
}, | ||
}, | ||
{ | ||
.query = "select * from test where pk = ?", | ||
.bind = { | ||
[0] = { | ||
.buffer_type = MYSQL_TYPE_LONG, | ||
.buffer = (void *)(&pk), | ||
.buffer_length = sizeof(pk), | ||
.is_unsigned = 1, | ||
}, | ||
}, | ||
}, | ||
{ | ||
.query = "insert into test values (?, ?)", | ||
.bind = { | ||
[0] = { | ||
.buffer_type = MYSQL_TYPE_LONG, | ||
.buffer = (void *)(&pk), | ||
.buffer_length = sizeof(pk), | ||
}, | ||
[1] = { | ||
.buffer_type = MYSQL_TYPE_LONG, | ||
.buffer = (void *)(&value), | ||
.buffer_length = sizeof(value), | ||
}, | ||
}, | ||
}, | ||
{ | ||
.query = "update test set `value` = ?", | ||
.bind = { | ||
[0] = { | ||
.buffer_type = MYSQL_TYPE_STRING, | ||
.buffer = (void *)"test string here", | ||
.buffer_length = string_len, | ||
.length = &string_len, | ||
}, | ||
}, | ||
.expect_exec_error = 1, | ||
}, | ||
{ | ||
.query = "select * from test SYNTAX ERROR where pk = ?", | ||
.bind = { | ||
[0] = { | ||
.buffer_type = MYSQL_TYPE_LONG, | ||
.buffer = (void *)(&pk), | ||
.buffer_length = sizeof(pk), | ||
}, | ||
}, | ||
.expect_prepare_error = 1, | ||
}, | ||
LAST_STATEMENT, | ||
}; | ||
|
||
for (int i = 0; statements[i].query; i++) { | ||
test_statement(con, &statements[i]); | ||
} | ||
|
||
mysql_close(con); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(DoltCxxConnectorTest | ||
VERSION 0.1 | ||
DESCRIPTION "A smoke test for mysql-connector-c++ connecting to Dolt" | ||
LANGUAGES CXX) | ||
|
||
add_executable(test_mysql_connector_cxx mysql-connector-cpp-test.cpp) | ||
set_property(TARGET test_mysql_connector_cxx PROPERTY CXX_STANDARD 11) | ||
|
||
if(WITH_JDBC) | ||
add_subdirectory(third_party/mysql-connector-cpp EXCLUDE_FROM_ALL) | ||
target_link_libraries(test_mysql_connector_cxx connector-jdbc) | ||
else() | ||
find_library(LIBMYSQLCPPCONN "mysqlcppconn") | ||
target_link_libraries(test_mysql_connector_cxx "${LIBMYSQLCPPCONN}") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
MYSQL_CONCPP_DIR = /usr/local/Cellar/mysql-connector-c++/8.0.21 | ||
CPPFLAGS = -I $(MYSQL_CONCPP_DIR)/include -L $(MYSQL_CONCPP_DIR)/lib64 | ||
LDLIBS = -lmysqlcppconn8 | ||
CXX = clang++ -stdlib=libc++ | ||
CXXFLAGS = -std=c++11 | ||
|
||
all: mysql-connector-cpp-test | ||
|
||
mysql-connector-cpp-test: mysql-connector-cpp-test.cpp | ||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $^ $(LDLIBS) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f mysql-connector-cpp-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# General | ||
|
||
This code uses git submodules. You need to recursively pull all the submodules | ||
in order for it to build. | ||
|
||
# Building on OS X | ||
|
||
```sh | ||
$ brew install cmake openssl mysql-client boost | ||
$ export PATH=/usr/local/Cellar/mysql-client/8.0.21/bin/:"$PATH" | ||
$ mkdir _build | ||
$ cd _build | ||
$ cmake .. -DWITH_SSL=/usr/local/Cellar/openssl@1.1/1.1.1g/ -DWITH_JDBC=yes | ||
$ make -j 10 | ||
``` | ||
|
||
TODO: These instructions are coupled to openssl and mysql-client version that | ||
happen to be installed... | ||
|
||
# Build on Ubuntu / Debian | ||
|
||
```sh | ||
$ apt-get install g++ cmake libmysqlcppconn-dev | ||
$ mkdir _build | ||
$ cd _build | ||
$ cmake .. | ||
$ make -j 10 | ||
``` |
Oops, something went wrong.