name: HaProxy Tests

on:
  workflow_call:

jobs:
  haproxy_check:
    strategy:
      fail-fast: false
      matrix:
        # List of refs to test
        ref: [ master ]
    name: ${{ matrix.ref }}
    runs-on: ubuntu-latest
    steps:
      - name: Build wolfSSL
        uses: wolfSSL/actions-build-autotools-project@v1
        with:
          path: wolfssl
          configure: --enable-quic --enable-haproxy
          install: true

      - name: Checkout VTest
        uses: actions/checkout@v3
        with:
          repository: vtest/VTest
          path: VTest

      - name: Build VTest
        working-directory: VTest
        # Special flags due to: https://github.com/vtest/VTest/issues/12
        run: make FLAGS='-O2 -s -Wall'

      - name: Checkout HaProxy
        uses: actions/checkout@v3
        with:
          repository: haproxy/haproxy
          path: haproxy
          ref: ${{ matrix.ref }}

      - name: Build HaProxy
        working-directory: haproxy
        run: >-
          make -j TARGET=linux-glibc DEBUG='-DDEBUG_MEMORY_POOLS -DDEBUG_STRICT'
          USE_OPENSSL_WOLFSSL=1 USE_QUIC=1 SSL_INC=$GITHUB_WORKSPACE/build-dir/include/
          SSL_LIB=$GITHUB_WORKSPACE/build-dir/lib/ ADDLIB=-Wl,-rpath=$GITHUB_WORKSPACE/build-dir/lib

      - name: Test HaProxy
        working-directory: haproxy
        run: make reg-tests reg-tests/ssl VTEST_PROGRAM=$GITHUB_WORKSPACE/VTest/vtest
 
