From c922f9ad9af2cb375b083b1f8cdb3c9f31e3ac2d Mon Sep 17 00:00:00 2001 From: wuriyanto Date: Wed, 30 Aug 2023 23:56:17 +0700 Subject: [PATCH] add integration test --- .github/workflows/ci.yml | 66 ++++++++++++++++++++++++------------ Dockerfile | 21 ++++++++++++ scripts/init.sql | 5 +++ scripts/load_ext.sh | 7 ++++ test.sql => scripts/test.sql | 0 5 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 Dockerfile create mode 100644 scripts/init.sql create mode 100755 scripts/load_ext.sh rename test.sql => scripts/test.sql (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9d729c..f6d809b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 \ No newline at end of file + - 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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f77f10b --- /dev/null +++ b/Dockerfile @@ -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/ \ No newline at end of file diff --git a/scripts/init.sql b/scripts/init.sql new file mode 100644 index 0000000..134c1c7 --- /dev/null +++ b/scripts/init.sql @@ -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'; \ No newline at end of file diff --git a/scripts/load_ext.sh b/scripts/load_ext.sh new file mode 100755 index 0000000..76c4ef3 --- /dev/null +++ b/scripts/load_ext.sh @@ -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 \ No newline at end of file diff --git a/test.sql b/scripts/test.sql similarity index 100% rename from test.sql rename to scripts/test.sql