tests: use go modules from ./vendor for running tests

Running tests without `-mod=vendor` causes the tests to download the
dependencies if these are not available in the standard go-module
directories (parent directories of the project). All dependencies are
already included in the ./vendor directory, so passing `-mod=vendor`
prevents downloading the dependencies and speeds up testing a lot.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-03-24 09:26:57 +01:00 committed by mergify[bot]
parent 79b0b8cfa6
commit a262063819

View File

@ -1,12 +1,12 @@
#!/bin/bash
GOPACKAGES="$(go list ./... | grep -v vendor | grep -v e2e)"
GOPACKAGES="$(go list -mod=vendor ./... | grep -v -e vendor -e e2e)"
COVERFILE="${GO_COVER_DIR}/profile.cov"
# no special options, exec to go test w/ all pkgs
if [[ ${TEST_EXITFIRST} != "yes" && -z ${TEST_COVERAGE} ]]; then
# shellcheck disable=SC2086
exec go test ${GOPACKAGES}
exec go test -mod=vendor -v ${GOPACKAGES}
fi
# our options are set so we need to handle each go package one
@ -20,7 +20,7 @@ failed=0
for gopackage in ${GOPACKAGES}; do
echo "--- testing: ${gopackage} ---"
# shellcheck disable=SC2086
go test ${GOTESTOPTS} "${gopackage}" || ((failed += 1))
go test -mod=vendor -v ${GOTESTOPTS} "${gopackage}" || ((failed += 1))
if [[ -f cover.out ]]; then
# Append to coverfile
grep -v "^mode: count" cover.out >>"${COVERFILE}"