image: $CI_REGISTRY/knot/knot-resolver/ci/debian-buster:knot-3.0
variables:
  LC_ALL: C.UTF-8

stages:
  - test

.test: &test
  stage: test
  tags:
    - docker
    - linux
    - amd64

.privileged_test: &privileged_test
  stage: test
  tags:
    - privileged

test:augeas:
  <<: *test
  script:
    - augparse pydnstest/deckard.aug

test:flake8:
  <<: *test
  script:
    - python3 -m flake8 --max-line-length=100 . && echo "OK, no flake8 errors detected"

test:mypy:
  <<: *test
  script:
    - ci/mypy-run.sh  && echo "OK, no mypy error detected"

test:pylint:
  <<: *test
  script:
    - ci/pylint-run.sh

test:rplint:
  <<: *test
  script:
    - cp ci/common.sh /tmp
    - cp ci/compare-rplint.sh /tmp
    - /tmp/compare-rplint.sh

test:unittests:
  <<: *privileged_test
  script:
    - python3 -m pytest

# There are no tests in the repo which use this feature but others do
# and do not want to cause them breakage
test:sanity:raw_id:
  <<: *privileged_test
  script:
    - unshare -rn ci/raw_id_check.sh

# changes in Deckard itself must not change result of tests
test:comparative:kresd:
  <<: *privileged_test
  script:
    # test kresd binary
    - git clone --recurse-submodules -j8 --depth=1 https://gitlab.nic.cz/knot/knot-resolver.git /tmp/kresd-local-build
    - pushd /tmp/kresd-local-build
    - git log -1
    - meson build_local --default-library=static --prefix=/tmp/.local
    - ninja -C build_local install
    - popd
    # compare results from latest Deckard with results from merge base
    - cp ci/common.sh /tmp
    - cp ci/compare-tests.sh /tmp
    - cp ci/junit-compare.py /tmp
    - PATH=/tmp/.local/sbin:$PATH /tmp/compare-tests.sh $(pwd)/kresd_run.sh
  artifacts:
    when: always
    expire_in: '1 hour'
    paths:
      - modified_tests
      - base.xml
      - head.xml

# Run all tests on the latest kresd version to ensure that we not push tests
# which do not work on latest kresd. It would lead to breakage in kresd CI.
test:latest:kresd:
  <<: *privileged_test
  script:
    - git clone --recurse-submodules -j8 --depth=1 https://gitlab.nic.cz/knot/knot-resolver.git kresd-local-build
    - pushd kresd-local-build
    - git log -1
    - meson build_local --default-library=static --prefix="$PWD/../.local"
    - ninja -C build_local install
    - popd
    - TMPDIR=$(pwd) PATH=$(pwd)/.local/sbin:$PATH ./kresd_run.sh -n $(nproc)
  artifacts:
    when: on_failure
    expire_in: 1 week
    paths:
      - tmpdeckard*

# sanity check that Unbound under Deckard still works
# I've selected the only tests which are working
# on kresd and Unbound 1.5.8 as well as 1.6.0
test:sanity:unbound:
  <<: *privileged_test
  script:
    - TMPDIR=$(pwd) ./unbound_run.sh --scenarios=sets/resolver/iter_hint_lame.rpl
    - TMPDIR=$(pwd) ./unbound_run.sh --scenarios=sets/resolver/iter_lame_root.rpl
    # these do not work with Unbound 1.5.8 which is in CI container
      #- TESTS=sets/resolver/nsec_wildcard_answer_response.rpl ./unbound_run.sh
      #- TESTS=sets/resolver/world_cz_lidovky_www.rpl ./unbound_run.sh
  artifacts:
    when: on_failure
    expire_in: 1 week
    paths:
      - tmpdeckard*

# sanity check that PowerDNS recursor under Deckard still works
# I've selected couple tests which are working
# on kresd and PowerDNS recursor 4.0.0~alpha2 as well as 4.0.4
test:sanity:pdnsrecursor:
  <<: *privileged_test
  script:
    - TMPDIR=$(pwd) ./pdns_run.sh --scenarios=sets/resolver/iter_recurse.rpl
    - TMPDIR=$(pwd) ./pdns_run.sh --scenarios=sets/resolver/iter_tcbit.rpl
  artifacts:
    when: on_failure
    expire_in: 1 week
    paths:
      - tmpdeckard*
