From f513683d014facd0278fdef790d1b39b083431c4 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Sat, 15 Apr 2023 11:00:01 +0800 Subject: [PATCH] ci: fix cargo target dir for integration test --- .gitignore | 1 + Makefile | 3 +++ cli/test.sh | 43 ++++++++++++++++++++++++++------------- cli/tests/base.sql | 2 +- cli/tests/base.sql.output | 4 ---- tests/docker-compose.yaml | 9 +++++--- 6 files changed, 40 insertions(+), 22 deletions(-) mode change 100644 => 100755 cli/test.sh delete mode 100644 cli/tests/base.sql.output diff --git a/.gitignore b/.gitignore index 69516bf07..8d4453113 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ target/ Cargo.lock /tests/data +*.output /dist diff --git a/Makefile b/Makefile index b7ac87c83..63c6911e7 100644 --- a/Makefile +++ b/Makefile @@ -21,3 +21,6 @@ integration-tests: integration-tests-flight-sql: make -C tests test-flight-sql + +integration-bendsql: + make -C tests test-bendsql diff --git a/cli/test.sh b/cli/test.sh old mode 100644 new mode 100755 index 930738b4b..2d9b7da51 --- a/cli/test.sh +++ b/cli/test.sh @@ -1,26 +1,41 @@ #!/bin/sh -port=8000 -extra="" -if [ $1 = "flight" ];then - port=8900 - extra="--flight" -fi +CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-./target} +DATABEND_USER=${DATABEND_USER:-root} +DATABEND_PASSWORD=${DATABEND_PASSWORD:-} +DATABEND_HOST=${DATABEND_HOST:-localhost} + +case $1 in +"flight") + echo + echo "==> Testing Flight SQL handler" + export BENDSQL_DSN="databend+flight://${DATABEND_USER}:${DATABEND_PASSWORD}@${DATABEND_HOST}:8900/?sslmode=disable" + ;; +"http") + echo + echo "==> Testing REST API handler" + export BENDSQL_DSN="databend+http://${DATABEND_USER}:${DATABEND_PASSWORD}@${DATABEND_HOST}:8000/?sslmode=disable" + ;; +*) + echo "Usage: $0 [flight|http]" + exit 1 + ;; +esac cargo build --bin bendsql -for f in `ls cli/tests/*.sql`;do - echo "Testing -- ${f}" - suite=`echo $f | sed -e 's#cli/tests/##' | sed -e 's#.sql##'` - cat $f | ./target/debug/bendsql -u ${DATABEND_USER} -p ${DATABEND_PASSWORD} --port ${port} -h${DATABEND_HOST} ${extra} > /tmp/${suite}.output 2>&1 - diff /tmp/${suite}.output cli/tests/${suite}.result - +for tf in cli/tests/*.sql; do + echo " Running test -- ${tf}" + suite=$(basename "${tf}" | sed -e 's#.sql##') + "${CARGO_TARGET_DIR}/debug/bendsql" <"${tf}" >"cli/tests/${suite}.output" 2>&1 + diff "cli/tests/${suite}.output" "cli/tests/${suite}.result" + ret_code=$? if [ $ret_code -ne 0 ]; then exit 1 fi done -rm /tmp/*.output +rm cli/tests/*.output -echo "Tests $1 passed" +echo "--> Tests $1 passed" diff --git a/cli/tests/base.sql b/cli/tests/base.sql index 74627cd93..406359316 100644 --- a/cli/tests/base.sql +++ b/cli/tests/base.sql @@ -1,7 +1,7 @@ create table test(a string, b int, d boolean); insert into test values('a', 1, true); insert into test values('b', 2, false); -select * from test; +select * from test order by a desc; truncate table test; insert into test select to_string(number), number, false from numbers(100000); diff --git a/cli/tests/base.sql.output b/cli/tests/base.sql.output deleted file mode 100644 index 2933533f2..000000000 --- a/cli/tests/base.sql.output +++ /dev/null @@ -1,4 +0,0 @@ -"b" 2 "false" -"a" 1 "true" -0 99999 100000 -"bye" diff --git a/tests/docker-compose.yaml b/tests/docker-compose.yaml index 21b75e85c..6f79fb2ff 100644 --- a/tests/docker-compose.yaml +++ b/tests/docker-compose.yaml @@ -24,9 +24,10 @@ services: timeout: 1s test: image: rust - command: cargo test --target-dir /target --test * + command: cargo test --test * working_dir: /workspace environment: + - CARGO_TARGET_DIR=/target - RUST_BACKTRACE=1 - TEST_DATABEND_DSN=databend://databend:databend@databend:8000/default?sslmode=disable volumes: @@ -39,9 +40,10 @@ services: condition: service_healthy test-flight-sql: image: rust - command: cargo test --target-dir /target --features flight-sql --test driver + command: cargo test --features flight-sql --test driver working_dir: /workspace environment: + - CARGO_TARGET_DIR=/target - RUST_BACKTRACE=1 - TEST_DATABEND_DSN=databend+flight://databend:databend@databend:8900/default?sslmode=disable volumes: @@ -54,9 +56,10 @@ services: condition: service_healthy test-bendsql: image: rust - command: bash cli/test.sh http && bash cli/test.sh flight + command: bash -c './cli/test.sh http && ./cli/test.sh flight' working_dir: /workspace environment: + - CARGO_TARGET_DIR=/target - RUST_BACKTRACE=1 - DATABEND_USER=databend - DATABEND_PASSWORD=databend