name: Unit Tests

permissions:
  contents: read
  actions: read

on:
  push:
    branches: main
  pull_request:
    branches: main

jobs:
  go-tests:
    name: Run Unit Tests
    strategy:
      matrix:
        go-version: ["1.23", "1.24"]
        platform: [ubuntu-latest]
      fail-fast: false

    runs-on: ${{ matrix.platform }}
    timeout-minutes: 10

    steps:
      - name: Check Repository
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Setup Go ${{ matrix.go-version }}
        uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
        with:
          go-version: ${{ matrix.go-version }}
        id: go

      - name: Restore Go Cache
        uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
        with:
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-${{ matrix.go-version }}-

      - name: Run Tests
        env:
          TEST_COUNT: 1
          TEST_RACE_HISTORY_SIZE: 5
          TEST_TIMEOUT: 5m
          TEST_OPTS: ""
        run: make go-test

      - name: Debug on Failure
        if: ${{ failure() }}
        uses: mxschmitt/action-tmate@7b6a61a73bbb9793cb80ad69b8dd8ac19261834c # v3.22
