name: Tests
permissions:
  contents: read
on: [push, pull_request]

jobs:
  unit:
    strategy:
      fail-fast: false
      matrix:
        os: [ "ubuntu", "windows", "macos" ]
        go: [ "1.24.x", "1.25.x" ]
    runs-on: ${{ fromJSON(vars[format('UNIT_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }}
    name: Unit tests (${{ matrix.os}}, Go ${{ matrix.go }})
    env:
      GOEXPERIMENT: ${{ matrix.go == '1.24.x' && 'synctest' || '' }}
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v6
        with:
          go-version: ${{ matrix.go }}
      - run: go version
      - name: Install go-junit-report
        run: go install github.com/jstemmer/go-junit-report/v2@v2.1.0
      - name: Run tests
        env:
          TIMESCALE_FACTOR: 10
        run: go test -v -cover -coverprofile coverage.txt ./... 2>&1 | go-junit-report -set-exit-code -iocopy -out report.xml
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v5
        env:
          OS: ${{ matrix.os }}
          GO: ${{ matrix.go }}
        with:
          files: coverage.txt
          env_vars: OS,GO
          token: ${{ secrets.CODECOV_TOKEN }}
      - name: Upload test report to Codecov
        if: ${{ !cancelled() }}
        uses: codecov/codecov-action@v5
        env:
          OS: ${{ matrix.os }}
          GO: ${{ matrix.go }}
        with:
          report_type: test_results
          name: Unit tests
          files: report.xml
          env_vars: OS,GO
          token: ${{ secrets.CODECOV_TOKEN }}
