Skip to content

Testing Workflow

The test.yml workflow runs Go tests with comprehensive options.

Usage

jobs:
  test:
    uses: go-gamma/actions/.github/workflows/test.yml@v1
    with:
      go-version: '1.24'
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

What It Does

  1. Checkout - Clones your repository
  2. Setup Go - Installs Go with caching
  3. Download deps - Runs go mod download
  4. go vet - Static analysis
  5. go test - Runs tests with options
  6. Coverage - Uploads to Codecov

Test Command

The workflow runs:

go test -v -shuffle=on -race -coverprofile=coverage.out -covermode=atomic ./...

Inputs

Input Type Default Description
go-version string '1.24' Go version
go-version-file string '' Path to go.mod
working-directory string '.' Code directory
race-detection boolean true Enable -race
test-flags string '-v -shuffle=on' Additional flags
upload-coverage boolean true Upload to Codecov

Outputs

Output Description
coverage-percentage Test coverage as percentage

Examples

With Custom Flags

jobs:
  test:
    uses: go-gamma/actions/.github/workflows/test.yml@v1
    with:
      go-version: '1.24'
      test-flags: '-v -shuffle=on -count=1 -timeout=30m'

Without Race Detection

jobs:
  test:
    uses: go-gamma/actions/.github/workflows/test.yml@v1
    with:
      go-version: '1.24'
      race-detection: false  # Faster, less thorough

Using Coverage Output

jobs:
  test:
    uses: go-gamma/actions/.github/workflows/test.yml@v1
    with:
      go-version: '1.24'
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  check-coverage:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo "Coverage: ${{ needs.test.outputs.coverage-percentage }}%"

Race Detection

The -race flag enables Go's race detector, which finds data races:

// This race would be caught:
var counter int
go func() { counter++ }()
counter++

Performance Impact

Race detection adds ~2-10x overhead. For large test suites, consider disabling on non-main branches.