diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2021-05-21 16:25:10 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2021-05-21 16:25:10 +0300 |
commit | 98b62a8e6b2b87ad6fbfb70f706274ee91e953d8 (patch) | |
tree | 0164f01a731a2e3980cf70798985d6b3b28428a2 | |
parent | 6c2ad0b46a89f6faecf428f598160fd42fa64442 (diff) | |
parent | 5844b2d0ddb98c135b7c58531979f268b1b4c4d7 (diff) |
Merge branch 'pks-tests-with-rebase' into 'master'
Fix running Gitaly tests during interactive rebases
See merge request gitlab-org/gitaly!3524
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | internal/gitaly/config/testhelper_test.go | 19 | ||||
-rw-r--r-- | internal/testhelper/configure.go | 20 |
3 files changed, 47 insertions, 1 deletions
@@ -4,6 +4,12 @@ # directory. -include config.mak +# Unexport environment variables which have an effect on Git itself. +# We need to keep GIT_PREFIX because it's used to determine where our +# self-built Git should be installed into. It's probably not going to +# matter much though. +unexport $(filter-out GIT_PREFIX,$(shell git rev-parse --local-env-vars)) + # Call `make V=1` in order to print commands verbosely. ifeq ($(V),1) Q = @@ -53,7 +59,7 @@ GOLANGCI_LINT_CONFIG ?= ${SOURCE_DIR}/.golangci.yml BUNDLE_DEPLOYMENT ?= $(shell test -f ${SOURCE_DIR}/../.gdk-install-root && echo false || echo true) GITALY_PACKAGE := gitlab.com/gitlab-org/gitaly BUILD_TIME := $(shell date +"%Y%m%d.%H%M%S") -GITALY_VERSION := $(shell git describe --match v* 2>/dev/null | sed 's/^v//' || cat ${SOURCE_DIR}/VERSION 2>/dev/null || echo unknown) +GITALY_VERSION := $(shell ${GIT} describe --match v* 2>/dev/null | sed 's/^v//' || cat ${SOURCE_DIR}/VERSION 2>/dev/null || echo unknown) GO_LDFLAGS := -ldflags '-X ${GITALY_PACKAGE}/internal/version.version=${GITALY_VERSION} -X ${GITALY_PACKAGE}/internal/version.buildtime=${BUILD_TIME}' GO_BUILD_TAGS := tracer_static,tracer_static_jaeger,continuous_profiler_stackdriver,static,system_libgit2 @@ -159,6 +165,7 @@ find_go_sources = $(shell find ${SOURCE_DIR} -type d \( -name ruby -o -nam # TEST_OPTIONS: any additional options # TEST_PACKAGES: packages which shall be tested run_go_tests = PATH='${SOURCE_DIR}/internal/testhelper/testdata/home/bin:${PATH}' \ + GIT_DIR=/dev/null \ go test -tags '${GO_BUILD_TAGS}' ${TEST_OPTIONS} ${TEST_PACKAGES} unexport GOROOT diff --git a/internal/gitaly/config/testhelper_test.go b/internal/gitaly/config/testhelper_test.go new file mode 100644 index 000000000..04e13330d --- /dev/null +++ b/internal/gitaly/config/testhelper_test.go @@ -0,0 +1,19 @@ +package config_test + +import ( + "os" + "testing" + + "gitlab.com/gitlab-org/gitaly/internal/testhelper" +) + +func TestMain(m *testing.M) { + os.Exit(testMain(m)) +} + +func testMain(m *testing.M) int { + defer testhelper.MustHaveNoChildProcess() + cleanup := testhelper.Configure() + defer cleanup() + return m.Run() +} diff --git a/internal/testhelper/configure.go b/internal/testhelper/configure.go index 7b011a76c..01a6a0851 100644 --- a/internal/testhelper/configure.go +++ b/internal/testhelper/configure.go @@ -55,6 +55,26 @@ func Configure() func() { // ConfigureGit configures git for test purpose func ConfigureGit() error { + // We cannot use gittest here given that we ain't got no config yet. We thus need to + // manually resolve the git executable, which is either stored in below envvar if + // executed via our Makefile, or else just git as resolved via PATH. + gitPath := "git" + if path, ok := os.LookupEnv("GITALY_TESTING_GIT_BINARY"); ok { + gitPath = path + } + + // Unset environment variables which have an effect on Git itself. + cmd := exec.Command(gitPath, "rev-parse", "--local-env-vars") + envvars, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("error computing local envvars: %w", err) + } + for _, envvar := range strings.Split(string(envvars), "\n") { + if err := os.Unsetenv(envvar); err != nil { + return fmt.Errorf("error unsetting envvar: %w", err) + } + } + _, currentFile, _, ok := runtime.Caller(0) if !ok { return fmt.Errorf("could not get caller info") |