---
# Makefile based unit test

- job-template:
    id: 'make-unit-test'
    name: 'verify_{project}_unit-test{name-extension}'

    description: |
      Created by {id} job-template from ci-management/jjb/make-unit.yaml<br/>
      Runs make with the following unit tests targets - '{unit-test-targets}'

    triggers:
      - cord-infra-gerrit-trigger-patchset:
          gerrit-server-name: '{gerrit-server-name}'
          project-regexp: '^{project}$'
          branch-regexp: '{branch-regexp}'
          dependency-jobs: '{dependency-jobs}'
          file-include-regexp: '{all-files-regexp}'

    properties:
      - cord-infra-properties:
          build-days-to-keep: '{build-days-to-keep}'
          artifact-num-to-keep: '{artifact-num-to-keep}'

    wrappers:
      - lf-infra-wrappers:
          build-timeout: '{build-timeout}'
          jenkins-ssh-credential: '{jenkins-ssh-credential}'

    scm:
      - cord-infra-gerrit-scm:
          git-url: '$GIT_URL/$GERRIT_PROJECT'
          refspec: '$GERRIT_REFSPEC'
          branch: '$GERRIT_BRANCH'
          submodule-recursive: 'false'
          choosing-strategy: gerrit
          jenkins-ssh-credential: '{jenkins-ssh-credential}'
          basedir: '{project}'

    node: '{build-node}'
    project-type: freestyle
    concurrent: true

    builders:
      - inject:
          properties-content: |
            DEST_GOPATH={dest-gopath}
            UNIT_TEST_TARGETS={unit-test-targets}
            UNIT_TEST_KEEP_GOING={unit-test-keep-going}
            GOPROXY=https://proxy.golang.org
            TEST_PROJECT={project}
      - shell: !include-raw-escape: shell/make-unit.sh

    publishers:
      - junit:
          results: "**/*results.xml,**/*report.xml"
          allow-empty-results: '{junit-allow-empty-results}'
# NOTE: circa 2020-04-11, the Jenkins xUnit plugin version 3.x.x changed the
# config XML to not be JJB compatible, replacing the previous XML <types> tag
# with a <tools> tag.
#
# Temporarily switch to using raw XML to configure xUnit.
#
# The following xunit and XML should be equivalent, except that the variable
# `xunit-skip-if-no-test-files` is assumed to always be true.
#
#     - xunit:
#         types:
#           - gtest:
#               pattern: "**/*xunit.xml"
#               deleteoutput: false
#               skip-if-no-test-files: '{xunit-skip-if-no-test-files}'
#
      - raw:
          xml: |
            <xunit plugin="xunit">
              <tools>
                <GoogleTestType>
                  <pattern>**/*xunit.xml</pattern>
                  <failIfNotNew>true</failIfNotNew>
                  <deleteOutputFiles>false</deleteOutputFiles>
                  <skipNoTestFiles>True</skipNoTestFiles>
                  <stopProcessingIfError>true</stopProcessingIfError>
                </GoogleTestType>
              </tools>
              <thresholds/>
              <thresholdMode>1</thresholdMode>
              <extraConfiguration>
                <testTimeMargin>3000</testTimeMargin>
              </extraConfiguration>
            </xunit>
      - cobertura:
          report-file: "**/*coverage.xml"
          targets:
            - files:
                healthy: 80
                unhealthy: 0
                failing: 0
            - method:
                healthy: 50
                unhealthy: 0
                failing: 0

# [EOF]
