#!/bin/bash # Скрипт для тестирования запросов к ClickHouse. # Из файлов *.sql в заданной директории, в алфавитном порядке, отправляются все запросы. # Результаты сравниваются с эталонами. QUERIES_DIR="./queries" CLIENT_PROGRAM="clickhouse-client -n" if [ -t 1 ]; then # stdout - терминал. COLOR_RESET="\033[0m" COLOR_WHITE="\033[1;37m" COLOR_FAIL="\033[1;31m" COLOR_UNKNOWN="\033[1;30m" COLOR_OK="\033[1;32m" COLOR_SKIPPED="\033[1;34m" else COLOR_RESET="" COLOR_WHITE="" COLOR_FAIL="" COLOR_UNKNOWN="" COLOR_OK="" COLOR_SKIPPED="" fi MSG_FAIL="${COLOR_WHITE}[ ${COLOR_FAIL}FAIL${COLOR_WHITE} ]${COLOR_RESET}" MSG_UNKNOWN="${COLOR_WHITE}[ ${COLOR_UNKNOWN}UNKNOWN${COLOR_WHITE} ]${COLOR_RESET}" MSG_OK="${COLOR_WHITE}[ ${COLOR_OK}OK${COLOR_WHITE} ]${COLOR_RESET}" MSG_SKIPPED="${COLOR_WHITE}[ ${COLOR_SKIPPED}SKIPPED${COLOR_WHITE} ]${COLOR_RESET}" ERRORS=0 if [ "$1" == "--zookeeper" ]; then ZOOKEEPER=1 shift elif [ "$1" == "--no-zookeeper" ]; then ZOOKEEPER=0 shift elif grep -q ' $result_file 2> $error_file ret_code=$? else $query_file > $result_file 2> $error_file ret_code=$? fi if [ $ret_code -ne 0 ]; then ERRORS=$(($ERRORS + 1)) echo -e "$MSG_FAIL - return code $ret_code" if [ -s "$error_file" ]; then cat $error_file fi # разорвано соединение с сервером if grep -q -E "Connection refused|Attempt to read after eof" $error_file; then exit 1; fi elif [ -s "$error_file" ]; then ERRORS=$(($ERRORS + 1)) echo -e "$MSG_FAIL - having stderror:" cat $error_file elif grep -q "Exception" $result_file; then ERRORS=$(($ERRORS + 1)) echo -e "$MSG_FAIL - having exception:" cat $result_file elif [ ! -e "$reference_file" ]; then echo -e "$MSG_UNKNOWN - no reference file" else diff $reference_file $result_file > $diff_file if [ -s "$diff_file" ]; then ERRORS=$(($ERRORS + 1)) echo -e "$MSG_FAIL - result differs with reference:" cat $diff_file else echo -e "$MSG_OK" rm $error_file $result_file $diff_file fi fi done done echo if [ $ERRORS -gt 0 ]; then echo -e "${COLOR_FAIL}Having $ERRORS errors!${COLOR_RESET}" exit 1 else echo -e "${COLOR_OK}All tests passed.${COLOR_RESET}" exit 0 fi