MXS-1220: Make REST API locally testable

The `test_rest_api` make target creates a discardable installation of
MaxScale which is used to launch a local instance of MaxScale. This local
instance is then used to test the REST API.

This is definitely not an efficient way to test the MaxScale but it allows
local testing without virtual machines or containers.
This commit is contained in:
Markus Mäkelä
2017-05-04 15:03:36 +03:00
parent 6c220a1151
commit 6b0fabf834
3 changed files with 78 additions and 0 deletions

View File

@ -89,3 +89,5 @@ if(TEST_FEEDBACK)
add_test(TestFeedback testfeedback)
set_tests_properties(TestFeedback PROPERTIES TIMEOUT 30)
endif()
add_subdirectory(rest-api)

View File

@ -0,0 +1,3 @@
add_custom_target(test_rest_api
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_rest_api.sh ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

View File

@ -0,0 +1,73 @@
#!/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/*
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
# Start MaxScale
$maxscaledir/bin/maxscale -df $maxscaledir/maxscale.cnf >& $maxscaledir/maxscale.output &
pid=$!
# Wait for MaxScale to start
for ((i=0;i<60;i++))
do
$maxscaledir/bin/maxadmin help >& /dev/null && break
sleep 1
done
# Run tests
cd $testdir
npm test
rval=$?
# Stop MaxScale
kill $pid
wait
exit $rval