name: Tests

on:
  push:
  pull_request:

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        rust: [nightly, stable, 1.45.0]
    steps:
      - uses: actions/checkout@v2

      - name: Start RabbitMQ
        uses: getong/rabbitmq-action@v1.2
        with:
          rabbitmq user: 'guest'
          rabbitmq password: 'guest'
          rabbitmq vhost: '/'

      - name: Set RabbitMQ URL in environment
        run: echo "TEST_AMQP_URL=amqp://guest:guest@127.0.0.1:5672//" >> $GITHUB_ENV

      - name: Install latest ${{ matrix.rust }}
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
          profile: minimal
          override: true

      - name: Run cargo check
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --all --bins --examples --tests --all-features

      - name: Run cargo check (without dev-dependencies to catch missing feature flags)
        if: startsWith(matrix.rust, 'nightly')
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: -Z features=dev_dep

      - name: Run cargo test
        uses: actions-rs/cargo@v1
        with:
          command: test
