From e4ef4ee27ecfbe43aca6df42ae6fa212b3d68c6f Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Mon, 1 Jan 2024 20:24:40 -0500 Subject: Add test db --- .env.test | 5 ++++ .gitignore | 3 ++- bolt.toml | 9 +++++++ docker-compose.yml | 18 ++++++++++++++ task | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 .env.test create mode 100644 bolt.toml create mode 100644 docker-compose.yml create mode 100755 task diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..d298ca7 --- /dev/null +++ b/.env.test @@ -0,0 +1,5 @@ +DB_NAME=test_db +DB_HOST=test_db +DB_PORT=5839 +DB_USERNAME=test_user +DB_PASSWORD=testpassword diff --git a/.gitignore b/.gitignore index 65e4738..a0090b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/bolt.toml +# macOS +.DS_Store diff --git a/bolt.toml b/bolt.toml new file mode 100644 index 0000000..0a40fa9 --- /dev/null +++ b/bolt.toml @@ -0,0 +1,9 @@ +migrations_dir = "migrations" + +[connection] +host = "localhost" +port = 5839 +user = "test_user" +password = "testpassword" +dbname = "test_db" +driver = "postgres" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3479b02 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.8' + +services: + postgres_db: + image: postgres:16.1-alpine3.19 + container_name: postgres_db + ports: + - "${DB_PORT:?err}:5432" + environment: + - POSTGRES_DB=${DB_NAME:?err} + - POSTGRES_USER=${DB_USERNAME:?err} + - POSTGRES_PASSWORD=${DB_PASSWORD:?err} + volumes: + - postgres_db_volume:/var/lib/postgresql/data + +volumes: + postgres_db_volume: + name: postgres-db-volume diff --git a/task b/task new file mode 100755 index 0000000..18105b9 --- /dev/null +++ b/task @@ -0,0 +1,70 @@ +#!/bin/sh +set -e + +print_help() { + echo "Usage: ./task " + echo "" + echo "Commands:" + echo " help Print this help message or help information for a specific command" + echo " test Run the go test suite for the repo" + echo "" + echo "For more information on a specific command, use './task help '" +} + +run_tests() { + docker compose --env-file .env.test up -d + + if [ "$1" = "-cov" ]; then + go test -cover ./... + else + go test ./... + fi + + docker compose --env-file .env.test down --volumes +} + +print_help_command() { + case "$1" in + help) + echo "Usage: ./task help " + echo "" + echo "Commands:" + echo " help Print this help message" + echo " test Run the go test suite for the repo" + ;; + test) + echo "Usage: ./task test [-cov]" + echo "" + echo "Options:" + echo " -cov Generate a coverage report" + ;; + *) + echo "Invalid command. Use 'help' to see available commands." + ;; + esac +} + +main() { + if [ $# -eq 0 ]; then + print_help + exit 1 + fi + + case "$1" in + help) + if [ $# -eq 1 ]; then + print_help + else + print_help_command "$2" + fi + ;; + test) + run_tests "$2" + ;; + *) + echo "Invalid command. Use 'help' to see available commands." + ;; + esac +} + +main "$@" -- cgit v1.2.3