version: 2.1

jobs:
  test-ubuntu-arm64:
    machine:
      image: ubuntu-2004:current
    resource_class: arm.medium
    steps:
      - checkout
      - run:
          name: Build
          command: |
            export CARGO_NET_GIT_FETCH_WITH_CLI=true
            uname -a
            lsb_release -a
            curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
            source $HOME/.cargo/env
            rustc --version
            cargo --version
            sudo apt update -qq
            sudo apt install -y -qq libxml2-utils libcurl4-openssl-dev
            cargo build --release --verbose --locked --color always
            target/release/hurl --version
            curl --version
      - run:
          name: Tests units and integration tests
          command: |
            python3 -m pip install --upgrade pip --quiet
            bin/test/test_prerequisites.sh
            echo "================= Tests units ================="
            cargo test --features strict --verbose --color always
            mitmdump --version
            pip3 install lxml bs4
            echo "================= Integration tests ================="
            export PATH="$PWD/target/debug:$PATH"
            cd integration
            python3 ./integration.py
            ./test_curl_commands.sh $(find ./tests_ok -maxdepth 1 -type f -name '*.curl' ! -name '*windows*')
            python3 ./test_html_output.py tests_ok/*.html
            xmllint --noout tests_ok/*.html
            ./test_curl_commands.sh $(find ./tests_failed -maxdepth 1 -type f -name '*.curl' ! -name '*windows*')
            python3 ./test_html_output.py tests_failed/*.html
            xmllint --noout tests_failed/*.html
      - store_artifacts:
          path: integration/mitmdump.log

      - store_artifacts:
          path: integration/server.log

      - store_artifacts:
          path: integration/server-ssl.log

workflows:
  tests-arm64:
    jobs:
      - test-ubuntu-arm64
