From 3f55e3481e2dcc28fbe01d774a80b8b877ac5c89 Mon Sep 17 00:00:00 2001 From: Artem Nikitin Date: Fri, 13 Sep 2019 13:53:59 +0200 Subject: [PATCH] Generate xUnit compatible test results for unit and integration tests (#1724) * Add xUnit compatible output for unit and integration tests * Add example of output to test on Jenkins * Create integration-tests.xml * Update make target for CI * Add xUnit compatible test reports to PR job * Revert "Create integration-tests.xml" This reverts commit 313d8a66ea6843970b6a4fe95e741461e9c36afc. * Revert "Add example of output to test on Jenkins" This reverts commit bdd7664972ca320b817e17c07a489167d408bccd. --- Makefile | 11 ++++++++++- build/ci/Dockerfile | 7 +++++++ build/ci/pr/Jenkinsfile | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9fe94d58379..bea247e1308 100644 --- a/Makefile +++ b/Makefile @@ -101,10 +101,19 @@ clean: unit: clean go test ./pkg/... ./cmd/... -coverprofile cover.out +unit_xml: clean + go test --json ./pkg/... ./cmd/... -coverprofile cover.out > unit-tests.json + gotestsum --junitfile unit-tests.xml --raw-command cat unit-tests.json + integration: GO_TAGS += integration integration: clean generate go test -tags='$(GO_TAGS)' ./pkg/... ./cmd/... -coverprofile cover.out +integration_xml: GO_TAGS += integration +integration_xml: clean generate + go test -tags='$(GO_TAGS)' --json ./pkg/... ./cmd/... -coverprofile cover.out > integration-tests.json + gotestsum --junitfile integration-tests.xml --raw-command cat integration-tests.json + check-fmt: ifneq ($(shell goimports -l pkg cmd),) $(error Invalid go formatting. Please run `make fmt`) @@ -338,7 +347,7 @@ e2e-local: ## -- Continuous integration -- ## ########################################## -ci: dep-vendor-only check-fmt lint generate check-local-changes unit integration e2e-compile docker-build +ci: dep-vendor-only check-fmt lint generate check-local-changes unit_xml integration_xml e2e-compile docker-build # Run e2e tests in a dedicated cluster. ci-e2e: dep-vendor-only run-deployer install-crds apply-psp e2e diff --git a/build/ci/Dockerfile b/build/ci/Dockerfile index e77ce167a66..90fdf3a686e 100644 --- a/build/ci/Dockerfile +++ b/build/ci/Dockerfile @@ -6,6 +6,7 @@ ENV GCLOUD_VERSION=232.0.0 ENV KUBECTL_VERSION=1.13.6 ENV DOCKER_VERSION=18.03.1-ce ENV GOLANGCILINT_VERSION=1.17.1 +ENV GOTESTSUM_VERSION=0.3.5 # Download required golang tools RUN go get github.com/golang/dep/cmd/dep golang.org/x/tools/cmd/goimports @@ -50,6 +51,12 @@ RUN apt-get update && apt-get --no-install-recommends -y install \ # Download Azure CLI RUN curl -sSL https://aka.ms/InstallAzureCLIDeb | bash +# Install gotestsum to generate xUnit compatible XML for tests +RUN curl -fsSLO https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz && \ + tar xzf gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz && \ + mv gotestsum /usr/local/bin/gotestsum && chmod +x /usr/local/bin/gotestsum && \ + rm gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz + # Add Go dependencies to Docker image WORKDIR /go/src/github.com/elastic/cloud-on-k8s COPY Gopkg.lock . diff --git a/build/ci/pr/Jenkinsfile b/build/ci/pr/Jenkinsfile index e7136d69025..ff10d756697 100644 --- a/build/ci/pr/Jenkinsfile +++ b/build/ci/pr/Jenkinsfile @@ -41,6 +41,8 @@ pipeline { steps { createConfig() sh 'make -C build/ci TARGET=ci ci' + junit "unit-tests.xml" + junit "integration-tests.xml" } } stage("Run smoke E2E tests") {