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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-12-09 14:33:03 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-12-14 09:54:12 +0300
commit08d5b7b268e36da27a7843a1c7d7021ef9a96487 (patch)
treecc0a2dbcaf62b6848659299915d5220d21fb8668 /cmd
parent8907e9a9637182efa7576024008882e790c77c89 (diff)
tests: Convert to use testhelper contexts
We're about to disallow use of "normal" contexts created via the `context` package given that they do not perform sanity checks for feature flags. Instead, contexts should be created via the testhelper package. Convert tests to use the testhelper context.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gitaly-hooks/hooks_test.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go
index 856730900..399e6e538 100644
--- a/cmd/gitaly-hooks/hooks_test.go
+++ b/cmd/gitaly-hooks/hooks_test.go
@@ -122,6 +122,9 @@ func TestHooksPrePostReceive(t *testing.T) {
}
func testHooksPrePostReceive(t *testing.T, cfg config.Cfg, repo *gitalypb.Repository, repoPath string) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
secretToken := "secret token"
glID := "key-1234"
glUsername := "iamgitlab"
@@ -184,7 +187,7 @@ func testHooksPrePostReceive(t *testing.T, cfg config.Cfg, repo *gitalypb.Reposi
cmd.Stdin = stdin
cmd.Env = envForHooks(
t,
- context.Background(),
+ ctx,
cfg,
repo,
glHookValues{
@@ -242,6 +245,9 @@ func testHooksPrePostReceive(t *testing.T, cfg config.Cfg, repo *gitalypb.Reposi
}
func TestHooksUpdate(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
glID := "key-1234"
glUsername := "iamgitlab"
glProtocol := "ssh"
@@ -261,21 +267,21 @@ func TestHooksUpdate(t *testing.T) {
runHookServiceServer(t, cfg)
- testHooksUpdate(t, cfg, glHookValues{
+ testHooksUpdate(t, ctx, cfg, glHookValues{
GLID: glID,
GLUsername: glUsername,
GLProtocol: glProtocol,
})
}
-func testHooksUpdate(t *testing.T, cfg config.Cfg, glValues glHookValues) {
+func testHooksUpdate(t *testing.T, ctx context.Context, cfg config.Cfg, glValues glHookValues) {
repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
refval, oldval, newval := "refval", strings.Repeat("a", 40), strings.Repeat("b", 40)
updateHookPath, err := filepath.Abs("../../ruby/git-hooks/update")
require.NoError(t, err)
cmd := exec.Command(updateHookPath, refval, oldval, newval)
- cmd.Env = envForHooks(t, context.Background(), cfg, repo, glValues, proxyValues{})
+ cmd.Env = envForHooks(t, ctx, cfg, repo, glValues, proxyValues{})
cmd.Dir = repoPath
tempDir := testhelper.TempDir(t)
@@ -395,6 +401,9 @@ func TestHooksPostReceiveFailed(t *testing.T) {
for _, tc := range testcases {
t.Run(tc.desc, func(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
hooksPayload, err := git.NewHooksPayload(
cfg,
repo,
@@ -409,11 +418,11 @@ func TestHooksPostReceiveFailed(t *testing.T) {
Protocol: glProtocol,
},
git.PostReceiveHook,
- rawFeatureFlags(context.Background()),
+ rawFeatureFlags(ctx),
).Env()
require.NoError(t, err)
- env := envForHooks(t, context.Background(), cfg, repo, glHookValues{}, proxyValues{})
+ env := envForHooks(t, ctx, cfg, repo, glHookValues{}, proxyValues{})
env = append(env, hooksPayload)
cmd := exec.Command(postReceiveHookPath)
@@ -466,13 +475,16 @@ func TestHooksNotAllowed(t *testing.T) {
var stderr, stdout bytes.Buffer
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
preReceiveHookPath, err := filepath.Abs("../../ruby/git-hooks/pre-receive")
require.NoError(t, err)
cmd := exec.Command(preReceiveHookPath)
cmd.Stderr = &stderr
cmd.Stdout = &stdout
cmd.Stdin = strings.NewReader(changes)
- cmd.Env = envForHooks(t, context.Background(), cfg, repo,
+ cmd.Env = envForHooks(t, ctx, cfg, repo,
glHookValues{
GLID: glID,
GLUsername: glUsername,
@@ -660,6 +672,9 @@ func TestGitalyHooksPackObjects(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
hook.Reset()
tempDir := testhelper.TempDir(t)
@@ -668,7 +683,7 @@ func TestGitalyHooksPackObjects(t *testing.T) {
args = append(args, repoPath, tempDir)
gittest.ExecOpts(t, cfg, gittest.ExecConfig{
- Env: (envForHooks(t, context.Background(), cfg, repo, glHookValues{}, proxyValues{})),
+ Env: (envForHooks(t, ctx, cfg, repo, glHookValues{}, proxyValues{})),
}, args...)
})
}