Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/my-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ jobs:
install:
runs-on: ubuntu-latest

# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_DB: "cicd_database"
POSTGRES_USER: "cicd_user"
POSTGRES_PASSWORD: "cicd_password"
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -33,3 +51,14 @@ jobs:
- name: Test test
if: ${{ inputs.exe_test == 'false' }}
run: npm test

- name: Connect to PostgreSQL
# Runs a script that creates a PostgreSQL table, populates
# the table with data, and then retrieves the data.
run: node client.js
# Environment variables used by the `client.js` script to create a new PostgreSQL table.
env:
# The hostname used to communicate with the PostgreSQL service container
POSTGRES_HOST: postgres
# The default PostgreSQL port
POSTGRES_PORT: 5432
20 changes: 20 additions & 0 deletions test/database.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Client } from "pg";

describe("Database", () => {
test("connection", async () => {
const database = new Client({
host: "127.0.0.1",
port: 5432,
database: "cicd_database",
user: "cicd_user",
password: "cicd_password",
});

const connected = await database
.connect()
.then(() => true)
.catch(() => false)
.finally(async () => await database.end());
expect(connected).toBe(true);
});
});
Loading