name: Test Go

on:
  pull_request:
    branches: [ master ]
    paths:
      - 'go/**'
  workflow_dispatch:

jobs:
  test:
    name: Go tests
    defaults:
      run:
        shell: bash
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-10.15, ubuntu-18.04, windows-latest]
    steps:
    - name: Set up Go 1.x
      uses: actions/setup-go@v2
      with:
        go-version: ^1.15
      id: go
    - uses: actions/checkout@v2
    - name: Test All
      working-directory: ./go
      run: |
        files=$(go list ./...)

        SAVEIFS=$IFS
        IFS=$'\n'

        file_arr=($files)

        IFS=$SAVEIFS

        file_list=
        for (( i=0; i<${#file_arr[@]}; i++ ))
        do
          echo "Testing Package: ${file_arr[$i]}"
          if [ "$MATRIX_OS" == 'ubuntu-18.04' ]
          then
            go test -timeout 30m -race "${file_arr[$i]}"
          else
            go test -timeout 30m "${file_arr[$i]}"
          fi
          succeeded=$(echo "$?")
          if [ "$succeeded" -ne 0 ]; then
            echo "Testing failed in package ${file_arr[$i]}"
            exit 1;
          fi
        done
      env:
        MATRIX_OS: ${{ matrix.os }}
  noracetest:
    name: Go tests - no race
    defaults:
      run:
        shell: bash
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-10.15, ubuntu-18.04, windows-latest]
    steps:
    - name: Set up Go 1.x
      uses: actions/setup-go@v2
      with:
        go-version: ^1.15
      id: go
    - uses: actions/checkout@v2
    - name: Test All
      working-directory: ./go
      run: |
        go test -timeout 30m ./libraries/doltcore/sqle/altertests
        go test -timeout 30m ./libraries/doltcore/sqle/integration_test
      env:
        MATRIX_OS: ${{ matrix.os }}
        DOLT_TEST_RUN_NON_RACE_TESTS: "true"
