Skip to content

Instantly share code, notes, and snippets.

@dengjonathan
Created September 12, 2025 21:36
Show Gist options
  • Save dengjonathan/94337035fe3ad7cff73d69a16a3f6917 to your computer and use it in GitHub Desktop.
Save dengjonathan/94337035fe3ad7cff73d69a16a3f6917 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to run Go integration tests with proper environment variables
# Usage: ./scripts/run_integration_test.sh <package_path> [test_suite] [test_method]
# Examples:
# ./scripts/run_integration_test.sh ./web-service/model
# ./scripts/run_integration_test.sh ./web-service/model TestTestReportIntegrationTestSuite
# ./scripts/run_integration_test.sh ./web-service/model TestTestReportIntegrationTestSuite TestSelectTestReport
set -e
# Set required environment variables for integration tests
export PG_HOST=localhost
export PG_PORT=5433
export PG_USER=read_write_user
export PG_PASSWORD=temp_password
export PG_DB=azimuth
# Parse arguments
PACKAGE_PATH="$1"
TEST_SUITE="$2"
TEST_METHOD="$3"
if [ -z "$PACKAGE_PATH" ]; then
echo "Usage: $0 <package_path> [test_suite] [test_method]"
echo "Examples:"
echo " $0 ./web-service/model"
echo " $0 ./web-service/model TestTestReportIntegrationTestSuite"
echo " $0 ./web-service/model TestTestReportIntegrationTestSuite TestSelectTestReport"
exit 1
fi
# Build the test command
TEST_CMD="go test -timeout 30s -tags integration,unit"
if [ -n "$TEST_SUITE" ]; then
TEST_CMD="$TEST_CMD -run ^${TEST_SUITE}$"
if [ -n "$TEST_METHOD" ]; then
TEST_CMD="$TEST_CMD -testify.m ^${TEST_METHOD}$"
fi
fi
TEST_CMD="$TEST_CMD $PACKAGE_PATH -v"
echo "Running: $TEST_CMD"
echo "Environment variables:"
echo " PG_HOST=$PG_HOST"
echo " PG_PORT=$PG_PORT"
echo " PG_USER=$PG_USER"
echo " PG_DB=$PG_DB"
echo ""
# Change to the package directory if it's a relative path starting with ./
if [[ "$PACKAGE_PATH" == ./* ]]; then
PACKAGE_DIR="${PACKAGE_PATH#./}"
echo "Changing to directory: $PACKAGE_DIR"
cd "$PACKAGE_DIR"
TEST_CMD="${TEST_CMD/$PACKAGE_PATH/.}"
fi
# Execute the test
eval $TEST_CMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment