chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:32:25 +08:00
commit e014feafe1
2285 changed files with 1131979 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
script_dir=$(dirname "$0")
cd $script_dir/../
ERRORS_FOUND=0
for FILENAME_WITH_EXT in *.bats; do
FILENAME=${FILENAME_WITH_EXT%".bats"}
while read -r LINE; do
if [[ ! "$LINE" =~ "@test \"$FILENAME:" ]] && [[ -n "$LINE" ]]; then
TESTNAME=$(echo "$LINE" | cut -d'"' -f 2)
echo -e "ERROR: test \"$TESTNAME\" in \"$FILENAME_WITH_EXT\" must start with \"$FILENAME:\" in the title"
ERRORS_FOUND=1
fi
done <<< $(grep '@test "' "$FILENAME_WITH_EXT")
while read -r LINE; do
if [[ ! "$LINE" =~ "@test '$FILENAME:" ]] && [[ -n "$LINE" ]]; then
TESTNAME=$(echo "$LINE" | cut -d"'" -f 2)
echo -e "ERROR: test \"$TESTNAME\" in \"$FILENAME_WITH_EXT\" must start with \"$FILENAME:\" in the title"
ERRORS_FOUND=1
fi
done <<< $(grep "@test '" "$FILENAME_WITH_EXT")
done
if [[ $ERRORS_FOUND -eq 1 ]]; then
exit 1
fi
exit 0
+72
View File
@@ -0,0 +1,72 @@
load setup/windows-compat
load setup/query-server-common
if [ -z "$BATS_TMPDIR" ]; then
export BATS_TMPDIR=$HOME/batstmp/
mkdir $BATS_TMPDIR
fi
nativebatsdir() { echo `nativepath $BATS_TEST_DIRNAME/$1`; }
batshelper() { echo `nativebatsdir helper/$1`; }
setup_common() {
psql --version
export PATH=$PATH:~/go/bin
cd $BATS_TMPDIR
# remove directory if exists
# reruns recycle pids
rm -rf "dolt-repo-$$"
# Append the directory name with the pid of the calling process so
# multiple tests can be run in parallel on the same machine
mkdir "dolt-repo-$$"
cd "dolt-repo-$$"
nativevar DOLTGRES_DATA_DIR "$(pwd)" /p
if [ -z "$DOLT_TEST_RETRIES" ]; then
export BATS_TEST_RETRIES="$DOLT_TEST_RETRIES"
fi
}
teardown_common() {
# rm -rf can fail with a "directory not empty" error in some cases. This seems to be a misleading
# error message; the real error is that a file is still in use. Instead of waiting longer for
# any processes to finish, we just ignore any error removing temp files and use 'true' as the last
# command in this function to ensure that teardown_common doesn't fail a test just because we
# couldn't delete any temporary test files.
stop_sql_server
rm -rf "$BATS_TMPDIR/dolt-repo-$$"
true
}
query_server() {
nativevar PGPASSWORD "password" /w
psql -U "${SQL_USER:-postgres}" -h localhost -p $PORT "$@" postgres
}
query_server_for_db() {
nativevar PGPASSWORD "password" /w
local db_name=${1:-postgres}
shift
psql -U "${SQL_USER:-postgres}" -h localhost -p $PORT "$@" $db_name
}
log_status_eq() {
if ! [ "$status" -eq $1 ]; then
echo "status: expected $1, received $status"
printf "output:\n$output"
exit 1
fi
}
log_output_has() {
if ! [[ "$output" =~ $1 ]]; then
echo "output did not have $1"
printf "output:\n$output"
exit 1
fi
}
nativevar DOLT_ROOT_PATH $BATS_TMPDIR/config-$$ /p
+144
View File
@@ -0,0 +1,144 @@
SERVER_REQS_INSTALLED="FALSE"
SERVER_PID=""
DEFAULT_DB=""
PASSWORD=""
USERNAME=""
# wait_for_connection(<PORT>, <TIMEOUT IN MS>) attempts to connect to the sql-server at the specified
# port on localhost, using the $SQL_USER (or 'postgres' if unspecified) as the user name, and trying once
# per second until the millisecond timeout is reached. If a connection is successfully established,
# this function returns 0. If a connection was not able to be established within the timeout period,
# this function returns 1.
wait_for_connection() {
port=$1
timeout=$2
end_time=$((SECONDS+($timeout/1000)))
USERNAME="${USERNAME:=postgres}"
PASSWORD="${PASSWORD:=password}"
nativevar PGPASSWORD "$PASSWORD" /w
while [ $SECONDS -lt $end_time ]; do
run psql -U $USERNAME -h localhost -p $port -c "SELECT 1;" $DEFAULT_DB
if [ $status -eq 0 ]; then
echo "Connected successfully!"
return 0
else
echo "$output"
fi
sleep 1
done
echo "Failed to connect to database $DEFAULT_DB on port $port within $timeout ms."
return 1
}
start_sql_server() {
DEFAULT_DB="$1"
logFile=$2
USERNAME=$3
PASSWORD=$4
if [ -n "$DEFAULT_DB" ]; then
nativevar DOLTGRES_DB "$DEFAULT_DB" /w
fi
if [ -n "$PASSWORD" ]; then
nativevar PGPASSWORD "password" /w
nativevar DOLTGRES_PASSWORD "$PASSWORD" /w
else
nativevar PGPASSWORD "$PASSWORD" /w
PASSWORD="password"
fi
if [ -n "$USERNAME" ]; then
nativevar DOLTGRES_USER "$USERNAME" /w
if [ -z "$DEFAULT_DB" ]; then
DEFAULT_DB="$USERNAME"
fi
else
USERNAME="postgres"
fi
DEFAULT_DB="${DEFAULT_DB:=postgres}"
PORT=$( definePORT )
CONFIG=$( defineCONFIG $PORT )
echo "$CONFIG" > config.yaml
if [[ $logFile ]]
then
doltgres -data-dir=. -config=config.yaml> $logFile 2>&1 &
else
doltgres -data-dir=. -config=config.yaml &
fi
SERVER_PID=$!
wait_for_connection $PORT 7500
}
# like start_sql_server, but the second argument is a string with all arguments to doltgres. The
# port argument is handled separately: if the variable $PORT is not defined and the --port argument
# is not included in the argument list, a random port is chosen for $PORT and the argument --port is
# appended to the argument list.
start_sql_server_with_args() {
DEFAULT_DB=""
nativevar DEFAULT_DB "$DEFAULT_DB" /w
nativevar PGPASSWORD "password" /w
echo "running doltgres $@"
doltgres "$@" &
SERVER_PID=$!
wait_for_connection $PORT 7500
}
# stop_sql_server stops the SQL server. For cases where it's important
# to wait for the process to exit after the kill signal (e.g. waiting
# for an async replication push), pass 1.
# kill the process if it's still running
stop_sql_server() {
# Clean up any mysql.sock file in the default, global location
if [ -f "/tmp/mysql.sock" ]; then rm -f /tmp/mysql.sock; fi
if [ -f "/tmp/postgres.sock" ]; then rm -f /tmp/mysql.sock; fi
if [ -f "/tmp/dolt.$PORT.sock" ]; then rm -f /tmp/dolt.$PORT.sock; fi
wait=$1
if [ ! -z "$SERVER_PID" ]; then
# ignore failures of kill command in the case the server is already dead
run kill $SERVER_PID
if [ $wait ]; then
while ps -p $SERVER_PID > /dev/null; do
sleep .1;
done
fi;
fi
SERVER_PID=
PORT=
}
definePORT() {
for i in {0..99}
do
port=$((RANDOM % 4096 + 2048))
# nc (netcat) returns 0 when it _can_ connect to a port (therefore in use), 1 otherwise.
run nc -z localhost $port
if [ "$status" -eq 1 ]; then
echo $port
break
fi
done
}
defineCONFIG() {
PORT=$1
cat <<EOF
log_level: debug
behavior:
read_only: false
disable_client_multi_statements: false
dolt_transaction_commit: false
listener:
host: localhost
port: $PORT
EOF
}
+25
View File
@@ -0,0 +1,25 @@
nativepath() { echo "$1"; }
nativevar() { eval export "$1"="$2"; }
skiponwindows() { :; }
IS_WINDOWS=${IS_WINDOWS:-false}
WINDOWS_BASE_DIR=${WINDOWS_BASE_DIR:-/mnt/c}
if [ -d "$WINDOWS_BASE_DIR"/Windows/System32 ] || [ "$IS_WINDOWS" == true ]; then
IS_WINDOWS=true
if [ ! -d "$WINDOWS_BASE_DIR"/batstmp ]; then
mkdir "$WINDOWS_BASE_DIR"/batstmp
fi
BATS_TMPDIR=`TMPDIR="$WINDOWS_BASE_DIR"/batstmp mktemp -d -t dolt-bats-tests-XXXXXX`
export BATS_TMPDIR
nativepath() {
wslpath -w "$1"
}
nativevar() {
eval export "$1"="$2"
export WSLENV="$WSLENV:$1$3"
}
skiponwindows() {
skip "$1"
}
fi