Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git_protocol.go « testhelper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d506fcc6e722899c0609113deeb7ab2521526ee7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package testhelper

import (
	"fmt"
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/assert"
	"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
)

// EnableGitProtocolV2Support replaces the git binary in config with a
// wrapper that allows the protocol to be tested. It returns a function that
// restores the given settings as well as an array of environment variables
// which need to be set when invoking Git with this setup.
func EnableGitProtocolV2Support(t *testing.T) func() {
	envPath := filepath.Join(testDirectory, "git-env")

	script := fmt.Sprintf(`#!/bin/sh
env | grep ^GIT_PROTOCOL= >>"%s"
exec "%s" "$@"
`, envPath, config.Config.Git.BinPath)

	dir, cleanupDir := TempDir(t)

	path := filepath.Join(dir, "git")
	cleanupExe, err := WriteExecutable(path, []byte(script))
	if !assert.NoError(t, err) {
		cleanupDir()
		t.FailNow()
	}

	oldGitBinPath := config.Config.Git.BinPath
	config.Config.Git.BinPath = path
	return func() {
		os.Remove(envPath)
		config.Config.Git.BinPath = oldGitBinPath
		cleanupExe()
		cleanupDir()
	}
}