on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master
name: Upstream Test

jobs:
  unit:
    strategy:
      fail-fast: false
      matrix:
        os:
          - 'ubuntu'
        go:
          # - '1.15.x'
          - '1.16.x'
        upstream:
          # - 'libp2p/go-libp2p-pubsub' flaky
          # - 'ipfs/go-bitswap' flaky
          # - 'libp2p/go-libp2p-kad-dht'
          - 'libp2p/go-libp2p-daemon'
    runs-on: ${{ matrix.os }}-latest
    name: ${{ matrix.upstream }} unit tests (${{ matrix.os }}, Go ${{ matrix.go }})
    steps:
      - uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go }}
      - name: Go information
        run: |
          go version
          go env
      - uses: actions/checkout@v4
        with:
          path: 'libp2p'
      - uses: actions/checkout@v4
        with:
          repository: ${{ matrix.upstream }}
          path: upstream
      - name: Patch in new go-libp2p
        working-directory: upstream
        run: |
          go mod edit -replace "github.com/libp2p/go-libp2p=../libp2p"
          go mod tidy
      - name: Run tests
        working-directory: upstream
        run: go test -v ./...
      - name: Run tests (32 bit)
        working-directory: upstream
        if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
        env:
          GOARCH: 386
        run: go test -v ./...
      - name: Run tests with race detector
        working-directory: upstream
        if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
        run: go test -v -race ./...
