Skip to content

Commit

Permalink
/integration-tests: move mysql-client-tests to integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeegoddd committed Mar 15, 2021
1 parent d08a454 commit 503665c
Show file tree
Hide file tree
Showing 34 changed files with 1,447 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
[submodule "proto/third_party/grpc-go"]
path = proto/third_party/grpc-go
url = https://github.com/grpc/grpc-go.git
[submodule "mysql-client-tests/cpp/third_party/mysql-connector-cpp"]
path = mysql-client-tests/cpp/third_party/mysql-connector-cpp
url = https://github.com/mysql/mysql-connector-cpp.git
[submodule "integration-tests/mysql-client-tests/cpp/third_party/mysql-connector-cpp"]
path = integration-tests/mysql-client-tests/cpp/third_party/mysql-connector-cpp
url = https://github.com/mysql/mysql-connector-cpp
12 changes: 6 additions & 6 deletions MySQLDockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ RUN curl -L -o /mysql-client-tests/java/mysql-connector-java-8.0.21.jar \
https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.21/mysql-connector-java-8.0.21.jar

# install node deps
COPY ./mysql-client-tests/node/package.json /mysql-client-tests/node/
COPY ./mysql-client-tests/node/package-lock.json /mysql-client-tests/node/
COPY ./integration-tests/mysql-client-tests/node/package.json /mysql-client-tests/node/
COPY ./integration-tests/mysql-client-tests/node/package-lock.json /mysql-client-tests/node/
WORKDIR /mysql-client-tests/node
RUN npm install

# install cpan dependencies
RUN cpanm DBD::mysql

# install ruby dependencies
COPY ./mysql-client-tests/ruby/Gemfile /mysql-client-tests/ruby/
COPY ./mysql-client-tests/ruby/Gemfile.lock /mysql-client-tests/ruby/
COPY ./integration-tests/mysql-client-tests/ruby/Gemfile /mysql-client-tests/ruby/
COPY ./integration-tests/mysql-client-tests/ruby/Gemfile.lock /mysql-client-tests/ruby/
WORKDIR /mysql-client-tests/ruby
RUN gem install bundler -v 2.1.4
RUN bundle install
Expand All @@ -92,8 +92,8 @@ COPY ./go/ .
ENV GOFLAGS="-mod=readonly"
RUN go build -o /usr/local/bin/dolt ./cmd/dolt

COPY ./mysql-client-tests /mysql-client-tests
COPY ./mysql-client-tests-entrypoint.sh /mysql-client-tests/entrypoint.sh
COPY ./integration-tests/mysql-client-tests /mysql-client-tests
COPY ./integration-tests/mysql-client-tests/mysql-client-tests-entrypoint.sh /mysql-client-tests/entrypoint.sh

WORKDIR /mysql-client-tests
ENTRYPOINT ["/mysql-client-tests/entrypoint.sh"]
8 changes: 4 additions & 4 deletions MySQLDockerfile.dockerignore
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
5 changes: 5 additions & 0 deletions integration-tests/mysql-client-tests/.gitignore
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/
28 changes: 28 additions & 0 deletions integration-tests/mysql-client-tests/README.md
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
```
11 changes: 11 additions & 0 deletions integration-tests/mysql-client-tests/c/Makefile
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 integration-tests/mysql-client-tests/c/mysql-connector-c-test.c
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;
}
17 changes: 17 additions & 0 deletions integration-tests/mysql-client-tests/cpp/CMakeLists.txt
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()
14 changes: 14 additions & 0 deletions integration-tests/mysql-client-tests/cpp/Makefile
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
28 changes: 28 additions & 0 deletions integration-tests/mysql-client-tests/cpp/README.md
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
```
Loading

0 comments on commit 503665c

Please sign in to comment.