.unit-test:
    # Postgres DB service
    services:
      - name: ssa-containers.aoc.nrao.edu/ops/ci/db:workspaces
        alias: db
    image: ${REGISTRY_URL}/${PROJECT_NAME}/${SERVICE_NAME}:${CI_COMMIT_SHORT_SHA}
    script:
        - |
            ([ $(whoami) = "root" ] && su vlapipe -c "cd /code && ./bin/run-tests.sh -b") || (cd /code && ./bin/run-tests.sh -b)
        - mv /code/.coverage ${CI_PROJECT_DIR}/.coverage.${SERVICE_NAME}.${CI_COMMIT_SHORT_SHA}
    artifacts:
        paths:
            - .coverage.${SERVICE_NAME}.${CI_COMMIT_SHORT_SHA}
    rules:
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
        - if: '$CI_COMMIT_TAG =~ /^end-of-sprint-[0-9]+/ || $CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+/'
          variables:
            IMAGE_TAG: $CI_COMMIT_TAG
        - if: '$CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+$/'
          variables:
            IMAGE_TAG: $CI_COMMIT_TAG
    dependencies: []
