Skip to content

Merge pull request #47 from smalex-z/app-status #100

Merge pull request #47 from smalex-z/app-status

Merge pull request #47 from smalex-z/app-status #100

Workflow file for this run

name: Go Unit Tests
# User-management tests need Postgres.
# Repository secret TEST_POSTGRES_PASSWORD
on:
push:
branches: [ main ]
pull_request:
branches: [ main, feat/golang-unit-tests ]
permissions:
contents: read
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: altsuite
POSTGRES_PASSWORD: ${{ secrets.TEST_POSTGRES_PASSWORD }}
POSTGRES_DB: altsuite
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U altsuite -d altsuite"
--health-interval 5s
--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.24'
- name: Run unit tests and generate coverage
env:
DATABASE_URL: postgres://altsuite:${{ secrets.TEST_POSTGRES_PASSWORD }}@localhost:5432/altsuite?sslmode=disable
run: |
cd api
go test -v -race -coverprofile=coverage.out -coverpkg=./... ./... | tee test_output.txt
go tool cover -func=coverage.out > coverage.txt
go tool cover -html=coverage.out -o coverage.html
- name: Parse test results and comment
if: always()
run: |
TESTS_PASSED=$(grep -c -- '--- PASS:' api/test_output.txt || echo 0)
TESTS_TOTAL=$(grep -c -- '=== RUN' api/test_output.txt || echo 0)
COVERAGE=$(grep '^total:' api/coverage.txt | awk '{print $3}')
echo "Unit tests run: $TESTS_TOTAL" > test_summary.txt
echo "Unit tests passed: $TESTS_PASSED" >> test_summary.txt
echo "Test coverage: ${COVERAGE:-0.0%}" >> test_summary.txt
- name: Upload coverage report (PR only)
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
api/coverage.txt
api/coverage.html
- name: Comment test summary (PR only)
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
path: test_summary.txt