2018-10-02 18:36:11 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
## Helper functions
|
|
|
|
|
|
|
|
function wait_for_server {
|
|
|
|
port=$1
|
|
|
|
while ! nc -z -w 1 127.0.0.1 $port; do
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function echo_info { printf "\033[1;36m~~ $1 ~~\033[0m\n"; }
|
|
|
|
function echo_success { printf "\033[1;32m~~ $1 ~~\033[0m\n\n"; }
|
|
|
|
function echo_failure { printf "\033[1;31m~~ $1 ~~\033[0m\n\n"; }
|
|
|
|
|
|
|
|
|
|
|
|
## Environment setup
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
cd "$DIR"
|
|
|
|
|
|
|
|
# Create a temporary directory for output files
|
|
|
|
tmpdir=/tmp/mg_client/output
|
|
|
|
if [ -d $tmpdir ]; then
|
|
|
|
rm -rf $tmpdir
|
|
|
|
fi
|
|
|
|
mkdir -p $tmpdir
|
|
|
|
cd $tmpdir
|
|
|
|
|
|
|
|
# Find memgraph binaries.
|
|
|
|
memgraph_dir="$DIR/../../build"
|
|
|
|
if [ ! -d $memgraph_dir ]; then
|
|
|
|
memgraph_dir="$DIR/../../build_release"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Find mg_client binaries.
|
|
|
|
client_dir="$memgraph_dir/tools/src"
|
|
|
|
if [ ! -d $client_dir ]; then
|
|
|
|
echo_failure "mg-client directory not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-10-15 21:03:16 +08:00
|
|
|
# Find tests dir.
|
2018-10-02 18:36:11 +08:00
|
|
|
tests_dir="$DIR/client"
|
|
|
|
if [ ! -d $tests_dir ]; then
|
2018-10-15 21:03:16 +08:00
|
|
|
echo_failure "Directory with tests not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Find tests input files.
|
|
|
|
input_dir="$tests_dir/input"
|
|
|
|
if [ ! -d $input_dir ]; then
|
|
|
|
echo_failure "Directory with tests input files not found"
|
2018-10-02 18:36:11 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
## Startup
|
|
|
|
|
|
|
|
# Start the memgraph process and wait for it to start.
|
|
|
|
echo_info "Starting memgraph"
|
|
|
|
$memgraph_dir/memgraph &> /dev/null &
|
|
|
|
pid=$!
|
|
|
|
wait_for_server 7687
|
|
|
|
echo_success "Started memgraph"
|
|
|
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
|
|
|
echo_info "Running tests"
|
|
|
|
echo # Blank line
|
|
|
|
|
|
|
|
client_flags="--use-ssl=false"
|
|
|
|
test_code=0
|
2018-10-15 21:03:16 +08:00
|
|
|
for output_dir in $tests_dir/output_*; do
|
|
|
|
for filename in $input_dir/*; do
|
|
|
|
test_name=$(basename $filename)
|
|
|
|
test_name=${test_name%.*}
|
|
|
|
output_name="$test_name.txt"
|
|
|
|
|
|
|
|
output_format=$(basename $output_dir)
|
|
|
|
output_format=${output_format#*_}
|
|
|
|
run_flags="$client_flags --output-format=$output_format"
|
|
|
|
|
|
|
|
echo_info "Running test '$test_name' with $output_format output"
|
|
|
|
$client_dir/mg_client $run_flags < $filename > $tmpdir/$test_name
|
|
|
|
diff -b $tmpdir/$test_name $output_dir/$output_name
|
|
|
|
test_code=$?
|
|
|
|
if [ $test_code -ne 0 ]; then
|
|
|
|
echo_failure "Test '$test_name' with $output_format output failed"
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo_success "Test '$test_name' with $output_format output passed"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Clear database for each test.
|
|
|
|
$client_dir/mg_client $client_flags <<< "MATCH (n) DETACH DELETE n;" \
|
|
|
|
&> /dev/null || exit 1
|
|
|
|
done
|
2018-10-02 18:36:11 +08:00
|
|
|
if [ $test_code -ne 0 ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
echo_info "Starting test cleanup"
|
|
|
|
|
|
|
|
# Shutdown the memgraph process.
|
|
|
|
kill $pid
|
|
|
|
wait -n
|
|
|
|
code_mg=$?
|
|
|
|
|
|
|
|
# Check memgraph exit code.
|
|
|
|
if [ $code_mg -ne 0 ]; then
|
|
|
|
echo_failure "The memgraph process didn't terminate properly!"
|
|
|
|
exit $code_mg
|
|
|
|
fi
|
|
|
|
echo_success "Test cleanup done"
|
|
|
|
|
|
|
|
exit $test_code
|