name: Go Test

on:
    workflow_call:
      inputs:
        working-directory:
          required: true
          type: string

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Go 1.24.x'
        uses: actions/setup-go@v5
        with:
          cache-dependency-path: |
             ${{ inputs.working-directory }}/go.sum
          go-version: '1.24.1'

      - name: Display Go version
        run: go version

      - name: Install dependencies
        run: |
          cd ${{ inputs.working-directory }}
          go get ./...
          
      - name: Run tests
        run: |
          cd ${{ inputs.working-directory }}
          go test ./... -json > ../../TestResults.json
          
      - name: Upload Go test results
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: Go-Test-results
          path: TestResults.json