diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-01 20:24:40 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-01 20:24:40 -0500 |
| commit | e4ef4ee27ecfbe43aca6df42ae6fa212b3d68c6f (patch) | |
| tree | 6b33cd05a9a69c13e8ed7f9e8d8043ae6b1783e1 | |
| parent | Add migration tests (diff) | |
| download | cli-e4ef4ee27ecfbe43aca6df42ae6fa212b3d68c6f.zip | |
Add test db
| -rw-r--r-- | .env.test | 5 | ||||
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | bolt.toml | 9 | ||||
| -rw-r--r-- | docker-compose.yml | 18 | ||||
| -rwxr-xr-x | task | 70 |
5 files changed, 104 insertions, 1 deletions
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 @@ -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 @@ -0,0 +1,70 @@ +#!/bin/sh +set -e + +print_help() { + echo "Usage: ./task <command>" + 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 <command>'" +} + +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 <command>" + 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 "$@" |