From 2d90769cfecd39e9a43e806f8a6edb49427ecf3f Mon Sep 17 00:00:00 2001 From: Lukas Braun <lukas.braun@fau.de> Date: Tue, 7 Mar 2017 01:20:45 +0100 Subject: [PATCH] Script testing with PostgreSQL --- Makefile | 7 +++++-- test_pg.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 test_pg.sh diff --git a/Makefile b/Makefile index e1f9761..4628f48 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,13 @@ CFLAGS += -std=c11 -D_POSIX_C_SOURCE=201112 -Wall -Wconversion -fPIC goatherd: goatherd.go go build goatherd.go -goatherd_test: goatherd.go goatherd_test.go +test_sqlite: goatherd.go goatherd_test.go go test -test: goatherd_test +test_pg: goatherd.go goatherd_test.go test_pg.sh + sh test_pg.sh + +test: test_sqlite test_pg pam_goatherd.so: pam_goatherd.o $(LINK.c) -lpam -lgnutls -Wl,-soname,$@ -shared $< -o $@ diff --git a/test_pg.sh b/test_pg.sh new file mode 100644 index 0000000..dab00d9 --- /dev/null +++ b/test_pg.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -eu + +export PGHOST="$PWD/postgres_test" +if [ $# -ge 1 ]; then + PGHOST="$(realpath -- "$1")" + shift +fi +export PGDATA="$PGHOST/data" + +cleanup() { + pg_ctl stop || true + echo -n "removing directories... " + rm -rf $PGHOST + echo "[x]" +} +trap 'cleanup' EXIT INT + +mkdir -p "$PGHOST" +initdb +echo "unix_socket_directories = '$PGHOST'" >"$PGDATA/postgresql.conf" + +pg_ctl -l "$PGHOST/log" -o '-h ""' start + +export PGHOST="$PGHOST" +createdb goatherd_test + +DB_DRIVER=postgres DB_URL="host=$PGHOST dbname=goatherd_test" go test "$@" -- GitLab