image:
        name: harbor.skao.int/production/ska-tango-images-tango-dsconfig:1.5.5

stages:
  - build
  - test

build_job:
  stage: build
  tags:
    - docker
  before_script:
    - sudo apt update && sudo apt -y --no-install-recommends install build-essential cmake pkg-config libboost-thread-dev
  script:
    - mkdir build && cd build
    - cmake -DBUILD_TESTS=ON ..
    - make
  artifacts:
    paths:
      - build/alarm-handler-srv
      - build/bin/testdevice-srv
    expire_in: 1 week

test_load_job:
  stage: test
  tags:
    - docker
  before_script:
    - sudo apt update && sudo apt -y --no-install-recommends install libboost-thread-dev
  script:
    - sleep 10
    - /usr/local/bin/DataBaseds 2 -ORBendPoint giop:tcp::10000 &
    - sleep 10
    - exit_code=2
    - json2tango -w -a -u ./test/ah_config.json || exit_code=$?
    - if [ ${exit_code} -ne 2 ]; then echo "Tango DB configuration failed!" ; else echo "Tango DB configuration succedeed!"; fi
    - ./build/alarm-handler-srv 01 &
    - ./build/bin/testdevice-srv 01 &
    - sleep 5
    - python ./test/load-alarm-conf.py --device=alarm/handler/01 --load="tag=test0;formula=(alarm/test/01/condition == 1);on_delay=0;off_delay=0;priority=high;shlvd_time=0;group=gr_test;message=Test alarm;url=;on_command=;off_command=;enabled=1"
    - sleep 1
    - python ./test/check-alarm-conf.py --device=alarm/handler/01 --alarm="tag=test0;formula=(alarm/test/01/condition == 1);on_delay=0;off_delay=0;priority=high;shlvd_time=0;group=gr_test;message=Test alarm;url=;on_command=;off_command=;enabled=1"
  needs: ["build_job"]
  services:
    - name: harbor.skao.int/production/ska-tango-images-tango-db:10.4.16
      alias: tangodb


