diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-10-13 10:32:02 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-10-13 10:32:02 -0400 |
| commit | d79f9b3bdb1a9ee341573eb67006de0c5fbfb7fc (patch) | |
| tree | e96998b3be26f5c73f13204217d059ed9c12a97a | |
| parent | Point go installation method to use latest stable version (diff) | |
| download | cli-d79f9b3bdb1a9ee341573eb67006de0c5fbfb7fc.zip | |
Add database older version compatibility tests
| -rw-r--r-- | .builds/test-mssql-compat.yml | 16 | ||||
| -rw-r--r-- | .builds/test-mysql-compat.yml | 15 | ||||
| -rw-r--r-- | .builds/test-postgresql-compat.yml | 18 | ||||
| -rw-r--r-- | scripts/lib/docker.sh | 63 | ||||
| -rw-r--r-- | scripts/lib/test.sh | 51 | ||||
| -rwxr-xr-x | scripts/test.sh | 6 |
6 files changed, 143 insertions, 26 deletions
diff --git a/.builds/test-mssql-compat.yml b/.builds/test-mssql-compat.yml new file mode 100644 index 0000000..4b62859 --- /dev/null +++ b/.builds/test-mssql-compat.yml @@ -0,0 +1,16 @@ +image: archlinux +packages: + - go + - docker + - jq +sources: + - https://git.sr.ht/~eugenetriguba/bolt +tasks: + - setup: | + sudo dockerd > /tmp/dockerd.log 2>&1 & + - test-mssql: | + cd bolt + ./scripts/test.sh mssql-2017-latest + ./scripts/test.sh mssql-2019-latest + ./scripts/test.sh mssql-2022-latest + ./scripts/test.sh mssql-2025-latest diff --git a/.builds/test-mysql-compat.yml b/.builds/test-mysql-compat.yml new file mode 100644 index 0000000..8c8d611 --- /dev/null +++ b/.builds/test-mysql-compat.yml @@ -0,0 +1,15 @@ +image: archlinux +packages: + - go + - docker + - jq +sources: + - https://git.sr.ht/~eugenetriguba/bolt +tasks: + - setup: | + sudo dockerd > /tmp/dockerd.log 2>&1 & + - test-mysql: | + cd bolt + ./scripts/test.sh mysql-5.7 + ./scripts/test.sh mysql-8 + ./scripts/test.sh mysql-9 diff --git a/.builds/test-postgresql-compat.yml b/.builds/test-postgresql-compat.yml new file mode 100644 index 0000000..89d4f4e --- /dev/null +++ b/.builds/test-postgresql-compat.yml @@ -0,0 +1,18 @@ +image: archlinux +packages: + - go + - docker + - jq +sources: + - https://git.sr.ht/~eugenetriguba/bolt +tasks: + - setup: | + sudo dockerd > /tmp/dockerd.log 2>&1 & + - test-postgresql: | + cd bolt + ./scripts/test.sh postgresql-13 + ./scripts/test.sh postgresql-14 + ./scripts/test.sh postgresql-15 + ./scripts/test.sh postgresql-16 + ./scripts/test.sh postgresql-17 + ./scripts/test.sh postgresql-18 diff --git a/scripts/lib/docker.sh b/scripts/lib/docker.sh index d2efaf5..ae037e7 100644 --- a/scripts/lib/docker.sh +++ b/scripts/lib/docker.sh @@ -15,6 +15,32 @@ readonly BOLT_MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-testpassword}" readonly BOLT_MSSQL_SA_PASSWORD="${MSSQL_SA_PASSWORD:-TestPass123!}" +# Parse database type and version from suite name +# +# DESCRIPTION: +# Extracts base database type and version from suite names. +# Handles both simple names (postgresql) and versioned names (postgresql-15). +# +# ARGUMENTS: +# $1: Suite name (e.g., "postgresql", "postgresql-15", "mysql-8.0") +# +# OUTPUTS: +# Prints "db_type version" to stdout (version is "latest" if not specified) +# +# EXAMPLES: +# docker_parse_suite_name "postgresql" # outputs: postgresql latest +# docker_parse_suite_name "postgresql-15" # outputs: postgresql 15 +# +docker_parse_suite_name() { + local suite_name="$1" + + if [[ "$suite_name" =~ ^([a-z0-9]+)-(.+)$ ]]; then + echo "${BASH_REMATCH[1]} ${BASH_REMATCH[2]}" + else + echo "$suite_name latest" + fi +} + # Generate database DSN string for a given database type # # DESCRIPTION: @@ -22,7 +48,7 @@ readonly BOLT_MSSQL_SA_PASSWORD="${MSSQL_SA_PASSWORD:-TestPass123!}" # This ensures perfect synchronization between container setup and Go test configuration. # # ARGUMENTS: -# $1: Database type (postgresql, mysql, mssql, sqlite3) +# $1: Database suite name (postgresql, mysql, mssql, sqlite3, or versioned like postgresql-15) # # OUTPUTS: # Prints the DSN string to stdout @@ -32,7 +58,9 @@ readonly BOLT_MSSQL_SA_PASSWORD="${MSSQL_SA_PASSWORD:-TestPass123!}" # 1 - Unknown database type # docker_generate_dsn() { - local db_type="$1" + local suite_name="$1" + local db_type version + read -r db_type version <<< "$(docker_parse_suite_name "$suite_name")" case "$db_type" in "postgresql") @@ -60,11 +88,13 @@ docker_generate_dsn() { # # ARGUMENTS: # $1: Container name (default: bolt_postgresql_db) +# $2: Version tag (default: latest) # docker_start_postgresql() { local container_name="${1:-bolt_postgresql_db}" + local version="${2:-latest}" - log_info "Starting PostgreSQL container '$container_name'..." + log_info "Starting PostgreSQL $version container '$container_name'..." docker run --detach \ --name "$container_name" \ @@ -76,18 +106,20 @@ docker_start_postgresql() { --env POSTGRES_DB="$BOLT_POSTGRES_DB" \ --env POSTGRES_USER="$BOLT_POSTGRES_USER" \ --env POSTGRES_PASSWORD="$BOLT_POSTGRES_PASSWORD" \ - postgres:18-alpine + "postgres:${version}" } # Start a MySQL database container # # ARGUMENTS: # $1: Container name (default: bolt_mysql_db) +# $2: Version tag (default: latest) # docker_start_mysql() { local container_name="${1:-bolt_mysql_db}" + local version="${2:-latest}" - log_info "Starting MySQL container '$container_name'..." + log_info "Starting MySQL $version container '$container_name'..." docker run --detach \ --name "$container_name" \ @@ -100,18 +132,20 @@ docker_start_mysql() { --env MYSQL_USER="$BOLT_MYSQL_USER" \ --env MYSQL_PASSWORD="$BOLT_MYSQL_PASSWORD" \ --env MYSQL_ROOT_PASSWORD="$BOLT_MYSQL_ROOT_PASSWORD" \ - mysql:9.4 + "mysql:${version}" } # Start a MSSQL database container # # ARGUMENTS: # $1: Container name (default: bolt_mssql_db) +# $2: Version tag (default: latest) # docker_start_mssql() { local container_name="${1:-bolt_mssql_db}" + local version="${2:-latest}" - log_info "Starting MSSQL container '$container_name'..." + log_info "Starting MSSQL $version container '$container_name'..." docker run --detach \ --name "$container_name" \ @@ -123,7 +157,7 @@ docker_start_mssql() { --health-retries 10 \ --env ACCEPT_EULA=Y \ --env MSSQL_SA_PASSWORD="$BOLT_MSSQL_SA_PASSWORD" \ - mcr.microsoft.com/mssql/server:2022-latest + "mcr.microsoft.com/mssql/server:${version}" } # Stop and remove a database container @@ -195,7 +229,7 @@ docker_wait_for_healthy_container() { # # ARGUMENTS: # $1: Container name -# $2: Database type (postgresql, mysql, mssql) +# $2: Database suite name (postgresql, mysql, mssql, or versioned like postgresql-15) # $3: Keep database running (true/false) # # RETURN: @@ -204,9 +238,12 @@ docker_wait_for_healthy_container() { # docker_ensure_container_running() { local container_name="$1" - local db_type="$2" + local suite_name="$2" local keepdb="$3" + local db_type version + read -r db_type version <<< "$(docker_parse_suite_name "$suite_name")" + local container_status container_status=$(docker inspect -f '{{.State.Health.Status}}' "$container_name" 2>/dev/null || echo "not_found") @@ -225,13 +262,13 @@ docker_ensure_container_running() { case "$db_type" in "postgresql") - docker_start_postgresql "$container_name" + docker_start_postgresql "$container_name" "$version" ;; "mysql") - docker_start_mysql "$container_name" + docker_start_mysql "$container_name" "$version" ;; "mssql") - docker_start_mssql "$container_name" + docker_start_mssql "$container_name" "$version" ;; *) log_error "Unknown database type: $db_type" 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 diff --git a/scripts/test.sh b/scripts/test.sh index fe14068..b6ddda0 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -19,10 +19,14 @@ usage() { echo "" echo "Arguments:" echo " TEST_SUITE Test suite to run (mssql, sqlite3, postgresql, mysql)" + echo " Supports versioned suites (e.g., postgresql-15, mysql-8.0)" + echo " Version format: <database>-<version> where version is a Docker tag" echo " If not specified, runs all test suites" echo "" echo "Examples:" - echo " $0 mssql # Run only MSSQL tests" + echo " $0 mssql # Run only MSSQL tests with latest version" + echo " $0 postgresql-15 # Run PostgreSQL 15 tests" + echo " $0 mysql-8.0 # Run MySQL 8.0 tests" echo " $0 --keepdb mssql # Run MSSQL tests, keep container running" echo " $0 --keepdb # Run all test suites, keep containers running" echo " $0 # Run all test suites" |