Dont use gotestsum in hack/test/unit
authorArnaud Rebillout <arnaud.rebillout@collabora.com>
Sat, 28 Sep 2019 02:30:56 +0000 (02:30 +0000)
committerDmitry Smirnov <onlyjob@debian.org>
Tue, 12 Nov 2019 01:18:22 +0000 (01:18 +0000)
gotestsum is not yet in Debian, let's just stick to 'go test' for now.

As soon as gotestsum is packaged for Debian (see #940225), we can drop
this patch, and add gotestsum as a build dependency.

This is a partial revert of the docker/cli commits:
3bd3996f72ca281cec288dd6e7f4fdaa0e1eeb00
277f61415ec99d5fbae75c15013f2fdfb0017af4

Origin: vendor, Debian
Forwarded: not-needed, Debian-specific
Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
Gbp-Pq: Name debian-dont-use-gotestsum-in-cli.patch

cli/Makefile
cli/scripts/test/unit [new file with mode: 0644]
cli/scripts/test/unit-with-coverage [new file with mode: 0644]

index 6f9abf9179a0c0752ef286928554ab544da3edd7..aaf5317fe60eb8239f911ab631973d7e5896eaf4 100644 (file)
@@ -11,15 +11,15 @@ clean: ## remove build artifacts
        rm -rf ./build/* cli/winresources/rsrc_* ./man/man[1-9] docs/yaml/gen
 
 .PHONY: test-unit
-test-unit: ## run unit tests, to change the output format use: GOTESTSUM_FORMAT=(dots|short|standard-quiet|short-verbose|standard-verbose) make test-unit 
-       gotestsum $(TESTFLAGS) -- $${TESTDIRS:-$(shell go list ./... | grep -vE '/vendor/|/e2e/')}
+test-unit: ## run unit test
+       ./scripts/test/unit $(shell go list ./... | grep -vE '/vendor/|/e2e/')
 
 .PHONY: test
 test: test-unit ## run tests
 
 .PHONY: test-coverage
 test-coverage: ## run test coverage
-       gotestsum -- -coverprofile=coverage.txt $(shell go list ./... | grep -vE '/vendor/|/e2e/')
+       ./scripts/test/unit-with-coverage $(shell go list ./... | grep -vE '/vendor/|/e2e/')
 
 .PHONY: fmt
 fmt:
diff --git a/cli/scripts/test/unit b/cli/scripts/test/unit
new file mode 100644 (file)
index 0000000..7eb82d0
--- /dev/null
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+set -eu -o pipefail
+
+go test -v "$@"
diff --git a/cli/scripts/test/unit-with-coverage b/cli/scripts/test/unit-with-coverage
new file mode 100644 (file)
index 0000000..db2efe7
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+set -eu -o pipefail
+
+# install test dependencies once before running tests for each package. This
+# reduces the runtime from 200s down to 23s
+go test -i "$@"
+
+echo "mode: atomic" > coverage.txt
+for pkg in "$@"; do
+    ./scripts/test/unit \
+        -cover \
+        -coverprofile=profile.out \
+        -covermode=atomic \
+        "${pkg}"
+
+    if test -f profile.out; then
+        grep -v "^mode:" < profile.out >> coverage.txt || true
+        rm profile.out
+    fi
+done