diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..3da9530 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,59 @@ +name: Test Suite + +on: + pull_request: + branches: [ main ] + push: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:17 + env: + POSTGRES_DB: echobase_test + POSTGRES_USER: user + POSTGRES_PASSWORD: pass + ports: + - 5433:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.25' + cache: true + + - name: Install sql-migrate + run: go install github.com/rubenv/sql-migrate/sql-migrate@latest + + - name: Wait for PostgreSQL + run: | + until pg_isready -h localhost -p 5433 -U user; do + echo "Waiting for PostgreSQL..." + sleep 2 + done + + - name: Run database migrations + run: sql-migrate up -env=test + env: + DATABASE_URL: postgresql://user:pass@localhost:5433/echobase_test?sslmode=disable + + - name: Download dependencies + run: go mod download + + - name: Run tests + run: go test -v -race ./... + env: + EB_DSN: postgresql://user:pass@localhost:5433/echobase_test?sslmode=disable diff --git a/Dockerfile b/Dockerfile index ddae9b9..bee92d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1 AS builder +FROM golang:1.25 AS builder WORKDIR /go/src/app COPY go.mod go.sum ./