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
52
53
54
55
56
57
58
59
60
|
package git_test
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/command"
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg"
)
func TestWithRefHook(t *testing.T) {
cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx, cancel := testhelper.Context()
defer cancel()
opt := git.WithRefTxHook(ctx, repo, cfg)
subCmd := git.SubCmd{Name: "update-ref", Args: []string{"refs/heads/master", git.ZeroOID.String()}}
for _, tt := range []struct {
name string
fn func() (*command.Command, error)
}{
{
name: "NewCommand",
fn: func() (*command.Command, error) {
return git.NewExecCommandFactory(cfg).New(ctx, repo, subCmd, opt)
},
},
} {
t.Run(tt.name, func(t *testing.T) {
cmd, err := tt.fn()
require.NoError(t, err)
// There is no full setup, so executing the hook will fail.
require.Error(t, cmd.Wait())
var actualEnvVars []string
for _, env := range cmd.Env() {
kv := strings.SplitN(env, "=", 2)
require.Len(t, kv, 2)
key, val := kv[0], kv[1]
if strings.HasPrefix(key, "GL_") || strings.HasPrefix(key, "GITALY_") {
require.NotEmptyf(t, strings.TrimSpace(val),
"env var %s value should not be empty string", key)
actualEnvVars = append(actualEnvVars, key)
}
}
require.EqualValues(t, []string{
"GITALY_HOOKS_PAYLOAD",
"GITALY_BIN_DIR",
"GITALY_LOG_DIR",
}, actualEnvVars)
})
}
}
|