Refactor REST API test script into a npm test framework

The script can now be used to run an arbitrary set of Node.js tests as
long as they define the `test` npm target. Refactored REST API tests to
fit into this framework.
This commit is contained in:
Markus Mäkelä
2017-07-13 14:57:19 +03:00
parent 01fa1a827a
commit 173a97ae70
5 changed files with 21 additions and 9 deletions

View File

@ -1,3 +1,6 @@
add_custom_target(test_rest_api
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_rest_api.sh ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_SOURCE_DIR}/test/run_npm_test.sh
${CMAKE_SOURCE_DIR} # Path to MaxScale sources
${CMAKE_CURRENT_SOURCE_DIR} # Path to test sources
${CMAKE_BINARY_DIR}/rest-api/ # Location where tests are built and run
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

View File

@ -1,37 +0,0 @@
version: '2'
services:
server1:
image: mariadb:10.1
network_mode: "host"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: Y
volumes:
- ./sql/master:/docker-entrypoint-initdb.d
command: mysqld --log-bin=binlog --binlog-format=ROW --server-id=3000 --port=3000 --log-slave-updates
server2:
image: mariadb:10.1
network_mode: "host"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: Y
volumes:
- ./sql/slave:/docker-entrypoint-initdb.d
command: mysqld --log-bin=binlog --binlog-format=ROW --server-id=3001 --port=3001 --log-slave-updates
server3:
image: mariadb:10.1
network_mode: "host"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: Y
volumes:
- ./sql/slave:/docker-entrypoint-initdb.d
command: mysqld --log-bin=binlog --binlog-format=ROW --server-id=3002 --port=3002 --log-slave-updates
server4:
image: mariadb:10.1
network_mode: "host"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: Y
volumes:
- ./sql/slave:/docker-entrypoint-initdb.d
command: mysqld --log-bin=binlog --binlog-format=ROW --server-id=3003 --port=3003 --log-slave-updates

View File

@ -1,14 +0,0 @@
RESET MASTER;
CREATE DATABASE test;
CREATE USER 'maxuser'@'127.0.0.1' IDENTIFIED BY 'maxpwd';
CREATE USER 'maxuser'@'%' IDENTIFIED BY 'maxpwd';
GRANT ALL ON *.* TO 'maxuser'@'127.0.0.1' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'maxuser'@'%' WITH GRANT OPTION;
CREATE USER 'skysql'@'127.0.0.1' IDENTIFIED BY 'skysql';
CREATE USER 'skysql'@'%' IDENTIFIED BY 'skysql';
GRANT ALL ON *.* TO 'skysql'@'127.0.0.1' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'skysql'@'%' WITH GRANT OPTION;
SET GLOBAL max_connections=10000;

View File

@ -1,3 +0,0 @@
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=3000, MASTER_USER='maxuser', MASTER_PASSWORD='maxpwd', MASTER_LOG_POS=4, MASTER_LOG_FILE='binlog.000001', MASTER_CONNECT_RETRY=1;
START SLAVE;
SET GLOBAL max_connections=10000;

View File

@ -1,83 +0,0 @@
#!/bin/bash
# This script builds and installs MaxScale, starts a MaxScale instance, runs the
# tests use npm and stops MaxScale.
#
# This is definitely not the most efficient way to test the binaries but it's a
# guaranteed method of creating a consistent and "safe" testing environment.
#
# TODO: Install and start a local MariaDB server for testing purposes
srcdir=$1
maxscaledir=$PWD/maxscale_test/
testdir=$PWD/local_test/
mkdir -p $testdir && cd $testdir
# Currently all tests that use npm are for the REST API
cp -t $testdir -r $srcdir/server/core/test/rest-api/*
# Bring MariaDB servers up, this is an asynchronous process
docker-compose up -d || exit 1
# Install dependencies
npm install
mkdir -p $maxscaledir && cd $maxscaledir
# Configure and install MaxScale
cmake $srcdir -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX=$maxscaledir \
-DBUILD_TESTS=Y \
-DMAXSCALE_VARDIR=$maxscaledir \
-DCMAKE_BUILD_TYPE=Debug \
-DWITH_SCRIPTS=N \
-DWITH_MAXSCALE_CNF=N \
-DBUILD_CDC=Y \
-DTARGET_COMPONENT=all \
-DDEFAULT_MODULE_CONFIGDIR=$maxscaledir \
-DDEFAULT_ADMIN_USER=`whoami`
make install
# Create required directories (we could run the postinst script but it's a bit too invasive)
mkdir -p $maxscaledir/lib64/maxscale
mkdir -p $maxscaledir/bin
mkdir -p $maxscaledir/share/maxscale
mkdir -p $maxscaledir/share/doc/MaxScale/maxscale
mkdir -p $maxscaledir/log/maxscale
mkdir -p $maxscaledir/lib/maxscale
mkdir -p $maxscaledir/cache/maxscale
mkdir -p $maxscaledir/run/maxscale
chmod 0755 $maxscaledir/log/maxscale
chmod 0755 $maxscaledir/lib/maxscale
chmod 0755 $maxscaledir/cache/maxscale
chmod 0755 $maxscaledir/run/maxscale
# Go to the test directory
cd $testdir
# This variable is used to start and stop MaxScale before each test
export MAXSCALE_DIR=$maxscaledir
# Wait until the servers are up
for node in server1 server2 server3 server4
do
printf "Waiting for $node to start... "
for ((i=0; i<60; i++))
do
docker-compose exec $node mysql -umaxuser -pmaxpwd -e "select 1" >& /dev/null && break
sleep 1
done
echo "Done!"
done
# Run tests
npm test
rval=$?
# Stop MariaDB servers
docker-compose down -v
exit $rval