From 173a97ae703c63e2b8ef4e151efacb5b50a2e489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 13 Jul 2017 14:57:19 +0300 Subject: [PATCH] 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. --- server/core/test/rest-api/CMakeLists.txt | 5 +++- .../test/rest-api => test}/docker-compose.yml | 0 .../test_rest_api.sh => test/run_npm_test.sh | 25 +++++++++++++------ .../rest-api => test}/sql/master/users.sql | 0 .../sql/slave/replication.sql | 0 5 files changed, 21 insertions(+), 9 deletions(-) rename {server/core/test/rest-api => test}/docker-compose.yml (100%) rename server/core/test/rest-api/test_rest_api.sh => test/run_npm_test.sh (81%) rename {server/core/test/rest-api => test}/sql/master/users.sql (100%) rename {server/core/test/rest-api => test}/sql/slave/replication.sql (100%) diff --git a/server/core/test/rest-api/CMakeLists.txt b/server/core/test/rest-api/CMakeLists.txt index d7e871584..2b4b34b31 100644 --- a/server/core/test/rest-api/CMakeLists.txt +++ b/server/core/test/rest-api/CMakeLists.txt @@ -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}) diff --git a/server/core/test/rest-api/docker-compose.yml b/test/docker-compose.yml similarity index 100% rename from server/core/test/rest-api/docker-compose.yml rename to test/docker-compose.yml diff --git a/server/core/test/rest-api/test_rest_api.sh b/test/run_npm_test.sh similarity index 81% rename from server/core/test/rest-api/test_rest_api.sh rename to test/run_npm_test.sh index 86ddc4978..8ea72ea37 100755 --- a/server/core/test/rest-api/test_rest_api.sh +++ b/test/run_npm_test.sh @@ -1,22 +1,31 @@ #!/bin/bash -# This script builds and installs MaxScale, starts a MaxScale instance, runs the -# tests use npm and stops MaxScale. +# This script builds and installs MaxScale, starts a MariaDB cluster and runs any +# tests that define a `npm test` target # # 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 +if [ $# -lt 3 ] +then + echo "USAGE: $0 " + exit 1 +fi srcdir=$1 -maxscaledir=$PWD/maxscale_test/ -testdir=$PWD/local_test/ +testsrc=$2 +testdir=$3 +maxscaledir=$PWD/maxscale_test/ + +# Create the test directory 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/* +# Copy the common test files (docker-compose.yml etc.) +cp -t $testdir -r $srcdir/test/* + +# Copy test sources to test workspace +cp -t $testdir -r $testsrc/* # Bring MariaDB servers up, this is an asynchronous process docker-compose up -d || exit 1 diff --git a/server/core/test/rest-api/sql/master/users.sql b/test/sql/master/users.sql similarity index 100% rename from server/core/test/rest-api/sql/master/users.sql rename to test/sql/master/users.sql diff --git a/server/core/test/rest-api/sql/slave/replication.sql b/test/sql/slave/replication.sql similarity index 100% rename from server/core/test/rest-api/sql/slave/replication.sql rename to test/sql/slave/replication.sql