From 1d56891061271a836aeda9ed384c5f6a5376bfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Wed, 17 Mar 2021 11:39:30 +0100 Subject: [PATCH] fix: generate a jUnit file per test suite (#907) * fix: generate a jUnit file per test suite * chore: move reports setup goal to a common Makefile --- .ci/scripts/build-test.sh | 7 ++----- cli/Makefile | 6 ++++-- commons.mk | 4 ++++ e2e/Makefile | 16 +++++++++++++--- 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 commons.mk diff --git a/.ci/scripts/build-test.sh b/.ci/scripts/build-test.sh index 8e66dc27a5..fe2d03157b 100755 --- a/.ci/scripts/build-test.sh +++ b/.ci/scripts/build-test.sh @@ -14,8 +14,5 @@ mkdir -p $(pwd)/outputs go get -v -u gotest.tools/gotestsum -# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output -GOTESTSUM_JUNITFILE="$(pwd)/outputs/TEST-unit-cli.xml" make -C cli install test - -# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output -GOTESTSUM_JUNITFILE="$(pwd)/outputs/TEST-unit-e2e.xml" make -C e2e unit-test +make -C cli install test +make -C e2e unit-test diff --git a/cli/Makefile b/cli/Makefile index 3a6459d56c..dfdb5eab0f 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -1,6 +1,8 @@ # Get current directory of a Makefile: https://stackoverflow.com/a/23324703 ROOT_DIR:=$(CURDIR) +include ../commons.mk + TEST_TIMEOUT?=5m GO_IMAGE?='golang' @@ -41,5 +43,5 @@ sync-integrations: OP_LOG_LEVEL=${LOG_LEVEL} go run main.go sync integrations --delete .PHONY: test -test: - gotestsum --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... +test: test-report-setup + gotestsum --junitfile "$(PWD)/outputs/TEST-unit-cli.xml" --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... diff --git a/commons.mk b/commons.mk new file mode 100644 index 0000000000..80667e0a93 --- /dev/null +++ b/commons.mk @@ -0,0 +1,4 @@ +# Prepare junit build context +.PHONY: test-report-setup +test-report-setup: + mkdir -p $(PWD)/outputs diff --git a/e2e/Makefile b/e2e/Makefile index 8c8ef53bb3..8b1762cc01 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -1,3 +1,5 @@ +include ../commons.mk + SUITE?=metricbeat TAGS?= DEVELOPER_MODE?=false @@ -101,9 +103,17 @@ notice: -depsOut "" .PHONY: unit-test -unit-test: - gotestsum --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... - cd _suites && gotestsum --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... +unit-test: test-report-setup unit-test-e2e unit-test-suite-fleet unit-test-suite-helm unit-test-suite-metricbeat + +# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output +.PHONY: unit-test-e2e +unit-test-e2e: + gotestsum --junitfile "$(PWD)/outputs/TEST-unit-e2e.xml" --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... + +# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output +.PHONY: unit-test-suite-% +unit-test-suite-%: + cd _suites/$* && gotestsum --junitfile "$(PWD)/outputs/TEST-unit-e2e-$*.xml" --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... ## Test examples