From d79f9b3bdb1a9ee341573eb67006de0c5fbfb7fc Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Mon, 13 Oct 2025 10:32:02 -0400 Subject: Add database older version compatibility tests --- scripts/lib/test.sh | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) (limited to 'scripts/lib/test.sh') diff --git a/scripts/lib/test.sh b/scripts/lib/test.sh index 02dd6a8..accc9e4 100644 --- a/scripts/lib/test.sh +++ b/scripts/lib/test.sh @@ -14,9 +14,11 @@ source "$(dirname "${BASH_SOURCE[0]}")/path.sh" # Starts database, waits for health checks, runs tests with # environment variables, and cleans up afterward. Automatically handles # database lifecycle and generates connection strings from Docker configuration. +# Supports versioned suite names (e.g., "postgresql-15") for testing against +# specific database versions. # # ARGUMENTS: -# $1: Name of the database test suite to run (e.g., "mssql", "postgresql", "sqlite3", or "mysql") +# $1: Name of the database test suite to run (e.g., "mssql", "postgresql", "postgresql-15", "sqlite3", "mysql", "mysql-8.0") # $2: Keep database running (true/false, default: false) # # RETURN: @@ -26,6 +28,8 @@ source "$(dirname "${BASH_SOURCE[0]}")/path.sh" # EXAMPLES: # test_run_suite "mssql" # test_run_suite "postgresql" true +# test_run_suite "postgresql-15" false +# test_run_suite "mysql-8.0" # test_run_suite() { local db_test_suite_name="$1" @@ -34,9 +38,12 @@ test_run_suite() { local coverage_file="${PATH_PROJECT_DIR}/coverage-${db_test_suite_name}.out" local test_result=0 + local db_type version + read -r db_type version <<< "$(docker_parse_suite_name "$db_test_suite_name")" + log_header "$db_test_suite_name Tests" - if [[ $db_test_suite_name != "sqlite3" ]]; then + if [[ $db_type != "sqlite3" ]]; then if ! docker_ensure_container_running "$container_name" "$db_test_suite_name" "$keepdb"; then return 1 fi @@ -48,7 +55,7 @@ test_run_suite() { local test_result=1 fi - if [[ $db_test_suite_name != "sqlite3" && $keepdb == "false" ]]; then + if [[ $db_type != "sqlite3" && $keepdb == "false" ]]; then log_step "Cleaning up..." docker_stop_container "$container_name" || log_warn "Unable to clean up container" fi @@ -58,16 +65,30 @@ test_run_suite() { # Check if a test suite name is valid # +# DESCRIPTION: +# Validates test suite names. Accepts both simple names (postgresql) and +# versioned names (postgresql-15). Validates that the base database type +# is in the list of supported test suites. +# # ARGUMENTS: # $1: Test suite name to validate # # RETURN: # 0 - Valid test suite name # 1 - Invalid test suite name +# +# EXAMPLES: +# test_is_valid_suite "postgresql" # valid +# test_is_valid_suite "postgresql-15" # valid +# test_is_valid_suite "invalid" # invalid +# test_is_valid_suite() { local suite="$1" + local db_type version + read -r db_type version <<< "$(docker_parse_suite_name "$suite")" + for valid in "${BOLT_TEST_SUITES[@]}"; do - [[ "$suite" == "$valid" ]] && return 0 + [[ "$db_type" == "$valid" ]] && return 0 done return 1 } @@ -78,9 +99,11 @@ test_is_valid_suite() { # Executes Go tests with optional build tags and coverage reporting. # Tests are run with parallelism disabled (-p 1). For database tests, # automatically generates connection strings from Docker configuration. +# Supports versioned suite names (e.g., "postgresql-15") which use the +# base database type for build tags. # # ARGUMENTS: -# $1 - database_type: Database type (e.g., "mssql", "postgresql", "mysql", "sqlite3"). Defaults to empty string. +# $1 - suite_name: Suite name (e.g., "mssql", "postgresql", "postgresql-15"). Defaults to empty string. # $2 - coverage_file: Output file for coverage profile. Defaults to empty string. # # RETURN: @@ -90,18 +113,22 @@ test_is_valid_suite() { # EXAMPLES: # test_run_go_tests # test_run_go_tests "mssql" "coverage-mssql.out" +# test_run_go_tests "postgresql-15" "coverage-postgresql-15.out" # test_run_go_tests() { - local database_type="${1:-}" + local suite_name="${1:-}" local coverage_file="${2:-}" # NOTE: -p 1 is used because we want to run tests sequentially. # This is because our tests depend on shared resources e.g. a database. local cmd="go test -p 1" - if [[ -n "$database_type" ]]; then - cmd="$cmd -tags $database_type" - log_step "Running tests with tags: $database_type" + local db_type="" + if [[ -n "$suite_name" ]]; then + local version + read -r db_type version <<< "$(docker_parse_suite_name "$suite_name")" + cmd="$cmd -tags $db_type" + log_step "Running tests with tags: $db_type" else log_step "Running tests" fi @@ -112,10 +139,10 @@ test_run_go_tests() { cmd="$cmd ./..." - if [[ -n "$database_type" ]]; then + if [[ -n "$suite_name" ]]; then local dsn - dsn=$(docker_generate_dsn "$database_type") - cmd="BOLT_DB_DSN='$dsn' BOLT_DB_DRIVER='$database_type' BOLT_DB_MIGRATIONS_TABLE='bolt_migrations' $cmd" + dsn=$(docker_generate_dsn "$suite_name") + cmd="BOLT_DB_DSN='$dsn' BOLT_DB_DRIVER='$db_type' BOLT_DB_MIGRATIONS_TABLE='bolt_migrations' $cmd" fi if eval "$cmd"; then -- cgit v1.2.3