diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 21ddb34..4f3b911 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,6 +15,7 @@ jobs: # Ensure rustfmt is installed and setup problem matcher - uses: actions-rust-lang/setup-rust-toolchain@v1 with: + toolchain: 1.40.0 components: rustfmt - name: Rustfmt Check uses: actions-rust-lang/rustfmt@v1 @@ -25,12 +26,15 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 - - run: ./tests/run.sh + with: + toolchain: 1.40.0 + - run: cargo build + - run: ./tests/run.sh --keep-database --diff env: - PGQL_DB_HOST: 127.0.0.1 + PGQL_DB_HOST: localhost PGQL_DB_USER: postgres PGQL_DB_PASSWORD: postgres - PGQL_DB_NAME: travis_ci_test + PGQL_DB_NAME: postgres services: postgres: image: postgres:12 @@ -43,6 +47,8 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 5432:5432 clippy: name: cargo clippy @@ -50,4 +56,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: 1.40.0 + components: clippy - run: cargo clippy diff --git a/tests/run.sh b/tests/run.sh index c9e27b8..9c674fb 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -11,6 +11,7 @@ filter="" no_confirmation="" quiet="" keep_database="" +create_schema=1 total=0; failures=(); @@ -194,6 +195,7 @@ read_args() { echo " -p, --patch Patch expected output files to match actual output when different" echo " -n, --no-confirmation Don’t ask for confirmation before updated expected output files" echo " -k, --keep-database Don’t reset the database at start" + echo " --no-schema Don’t create the schema at start" echo " -f, --filter FILTER Only execute test matching FILTER" exit 0 ;; @@ -217,6 +219,10 @@ read_args() { keep_database=1 shift ;; + --no-schema) + create_schema="" + shift + ;; -q|--quiet) quiet=1 shift @@ -238,10 +244,18 @@ read_args() { } reset_database () { + export PGPASSWORD="$PGQL_DB_PASSWORD" + psql="psql -h $PGQL_DB_HOST -U $PGQL_DB_USER -w -v ON_ERROR_STOP=1 -q" + if [ -z "$keep_database" ]; then - psql="PGPASSWORD=\"$PGQL_DB_PASSWORD\" psql -h \"$PGQL_DB_HOST\" -U \"$PGQL_DB_USER\" -w -v ON_ERROR_STOP=1 -q" - echo "drop database if exists $PGQL_DB_NAME; create database $PGQL_DB_NAME" | eval "$psql" - cat ./schema.sql | envsubst | eval "$psql" -d "$PGQL_DB_NAME" + echo Creating Database + echo "drop database if exists $PGQL_DB_NAME; create database $PGQL_DB_NAME" | $psql + fi + + if [ ! -z "$create_schema" ]; then + echo Creating DB schema + cat ./schema.sql | envsubst + cat ./schema.sql | envsubst | $psql -d "$PGQL_DB_NAME" fi }