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
43
44
45
46
47
48
49
50
51
|
package testhelper
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
)
// CaptureHookEnv creates a bogus 'update' Git hook to sniff out what
// environment variables get set for hooks.
func CaptureHookEnv(t testing.TB) (hookPath string, cleanup func()) {
var err error
oldOverride := hooks.Override
hooks.Override, err = filepath.Abs("testdata/scratch/hooks")
require.NoError(t, err)
hookOutputFile, err := filepath.Abs("testdata/scratch/hook.env")
require.NoError(t, err)
require.NoError(t, os.RemoveAll(hookOutputFile))
require.NoError(t, os.MkdirAll(hooks.Override, 0755))
require.NoError(t, ioutil.WriteFile(filepath.Join(hooks.Override, "update"), []byte(`
#!/bin/sh
env | grep -e ^GIT -e ^GL_ > `+hookOutputFile+"\n"), 0755))
return hookOutputFile, func() {
hooks.Override = oldOverride
}
}
// ConfigureGitalyHooksBinary builds gitaly-hooks command for tests
func ConfigureGitalyHooksBinary() {
if config.Config.BinDir == "" {
log.Fatal("config.Config.BinDir must be set")
}
goBuildArgs := []string{
"build",
"-o",
filepath.Join(config.Config.BinDir, "gitaly-hooks"),
"gitlab.com/gitlab-org/gitaly/cmd/gitaly-hooks",
}
MustRunCommand(nil, nil, "go", goBuildArgs...)
}
|