Skip to content

Commit a8be6c3

Browse files
Feature/enable db tests (#6)
meta: enabled database tests
1 parent 674f2ea commit a8be6c3

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

.github/workflows/cicd.yml

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
- run: npm ci
2121
- run: npm test
2222
- run: npm run lint
23-
ci-db:
24-
name: Continuous Integration Database
23+
ci-db-linting:
24+
name: Continuous Integration Database - Linting
2525
runs-on: ubuntu-latest
2626
strategy:
2727
matrix:
@@ -49,10 +49,64 @@ jobs:
4949
- name: Analysing the SQL code
5050
run: |
5151
bash db/linting/lint.sh
52+
ci-db-testing:
53+
name: Continuous Integration Database - Testing
54+
runs-on: ubuntu-latest
55+
services:
56+
postgres:
57+
image: acprdev/postgres-ci:15.2
58+
env:
59+
DATABASE: test_postgres
60+
HOST: localhost
61+
PORT: 5432
62+
USER: postgres
63+
PASSWORD: postgres
64+
POSTGRES_PASSWORD: postgres
65+
POSTGRES_USER: postgres
66+
options: >-
67+
--health-cmd pg_isready
68+
--health-interval 10s
69+
--health-timeout 5s
70+
--health-retries 5
71+
ports:
72+
- 5432:5432
73+
74+
steps:
75+
- uses: actions/checkout@v3
76+
- name: Setup Perl
77+
id: perl
78+
uses: shogo82148/actions-setup-perl@v1
79+
with:
80+
perl-version: '5.34'
81+
install-modules-with: cpm
82+
- name: Cache CPAN Modules
83+
uses: actions/cache@v3
84+
with:
85+
path: local
86+
key: perl-${{ steps.perl.outputs.perl-hash }}
87+
- name: Install pg_prove
88+
run: |
89+
cpm install TAP::Parser::SourceHandler::pgTAP
90+
env:
91+
SHELL: /bin/bash
92+
- name: Initialize database and run tests
93+
run: |
94+
bash db/cli/init_db.sh
95+
bash db/cli/apply_all_migrations.sh
96+
bash db/cli/run_tests.sh
97+
env:
98+
DATABASE: test_postgres
99+
HOST: localhost
100+
PORT: 5432
101+
USER: postgres
102+
PASSWORD: postgres
103+
POSTGRES_PASSWORD: postgres
104+
POSTGRES_USER: postgres
105+
PGPASSWORD: postgres
52106
cd:
53107
name: Continuous Deployment
54108
runs-on: ubuntu-latest
55-
needs: [ci-node,ci-db]
109+
needs: [ci-node,ci-db-linting,ci-db-testing]
56110
if: startsWith(github.ref, 'refs/tags/v')
57111
steps:
58112
- name: Checkout the repository

db/cli/apply_all_migrations.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
echo 'Applying migrations'
2+
for f in source/migrations/*.sql;
3+
do
4+
if test -f "$f"; then
5+
psql -U $USER -h $HOST -p $PORT -d $DATABASE -v "ON_ERROR_STOP=1" -f "$f"
6+
echo 'Applied migration -' $f
7+
fi
8+
done

db/cli/init_db.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
createdb --username=$USER -h $HOST -p $PORT $DATABASE

db/cli/run_tests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set -e
2+
3+
psql --quiet -U $USER -h $HOST -p $PORT -d $DATABASE -c 'CREATE EXTENSION IF NOT EXISTS pgtap;'
4+
5+
pg_prove -U $USER -h $HOST -p $PORT -d $DATABASE db/tests/performance/*.test.sql

0 commit comments

Comments
 (0)