Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
wuriyanto48 committed Aug 30, 2023
1 parent 263d091 commit c922f9a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 22 deletions.
66 changes: 44 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,51 @@ on:
branches: [ master ]

jobs:
build:

docker-build:
runs-on: ubuntu-20.04
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: wuriyanto/postgres-pgcrypsi:latest
test:
name: Test
runs-on: ubuntu-20.04

strategy:
fail-fast: false
services:
postgres:
image: wuriyanto/postgres-pgcrypsi:latest
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set permission to install_ubuntu_deps
run: chmod +x ./scripts/install_ubuntu_deps
- name: Install Ubuntu dependecies
run: bash ./scripts/install_ubuntu_deps
- name: Check Builder
run: |
cmake --version
gcc --version
openssl version -a
- name: Build Extension
run: |
ls /usr/include/postgresql/
cc -fPIC -c pgcrypsi.c -I /usr/include/postgresql/12/server/
cc -shared -o pgcrypsi.so pgcrypsi.o
- name: Check libdir
run: |
pg_config --pkglibdir
- name: Check out
uses: actions/checkout@v2

- name: Install Postgre Client
run: |
apt-get update
apt-get install --yes --no-install-recommends postgresql-client
- name: Test
run: |
psql -h localhost -U superdevuser -d superdevdb -a -f ./scripts/test.sql
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM postgres:12

# docker is only used for integration testing, so ignoring security is acceptable

ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD 12345678

RUN apt-get update && apt-get install -y build-essential \
&& apt-get install -y gcc-multilib \
&& apt-get install -y libpq-dev \
&& apt-get install -y postgresql-server-dev-12

COPY . .

RUN cc -fPIC -c pgcrypsi.c -I /usr/include/postgresql/12/server/
RUN cc -shared -o pgcrypsi.so pgcrypsi.o
RUN cp pgcrypsi.so /usr/lib/postgresql/12/lib/
RUN make USE_PGXS=1 install

COPY ./scripts/init.sql /docker-entrypoint-initdb.d/
COPY ./scripts/load_ext.sh /docker-entrypoint-initdb.d/
5 changes: 5 additions & 0 deletions scripts/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE USER superdevuser;
CREATE DATABASE superdevdb;
GRANT ALL PRIVILEGES ON DATABASE superdevdb TO superdevuser;
ALTER USER postgres with PASSWORD '12345678';
ALTER USER superdevuser with PASSWORD '12345678';
7 changes: 7 additions & 0 deletions scripts/load_ext.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

psql -v ON_ERROR_STOP=1 --username postgres --dbname superdevdb <<-EOSQL
CREATE EXTENSION IF NOT EXISTS "pgcrypsi";
select extname FROM pg_extension;
EOSQL
File renamed without changes.

0 comments on commit c922f9a

Please sign in to comment.