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
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-12-10 16:41:56 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-12-11 11:48:12 +0300
commitf58b02f2ecc9329174f28a1bd58cd256ec61ab42 (patch)
treeb22d8400eeca91bd3d920cfc5e0caac395e78d6f
parentd902bf04434196af8a4a4b00b3420e9a2868e7fb (diff)
hooks: Discern expected and actual environment for custom hook tests
Right now, our custom hook tests expect the same environment for the invoked custom hooks as the environment that we provide. This is going to change though as we move more variables into the hooks payload. As such, the input environment is only going to contain the payload, while the custom hooks environment will stay the same. Let's prepare for this change by converting tests to discern between actual and expected environment to make it easier to change.
-rw-r--r--internal/gitaly/hook/postreceive_test.go18
-rw-r--r--internal/gitaly/hook/prereceive_test.go18
-rw-r--r--internal/gitaly/hook/update_test.go22
3 files changed, 41 insertions, 17 deletions
diff --git a/internal/gitaly/hook/postreceive_test.go b/internal/gitaly/hook/postreceive_test.go
index 8cdd98735..428b81835 100644
--- a/internal/gitaly/hook/postreceive_test.go
+++ b/internal/gitaly/hook/postreceive_test.go
@@ -122,11 +122,19 @@ func TestPostReceive_customHook(t *testing.T) {
expectedStderr string
}{
{
- desc: "hook receives environment variables",
- env: append(standardEnv, payload),
- stdin: "changes\n",
- hook: "#!/bin/sh\nenv | grep -e '^GL_' -e '^GITALY_' | sort\n",
- expectedStdout: strings.Join(append([]string{payload}, standardEnv...), "\n") + "\n",
+ desc: "hook receives environment variables",
+ env: append(standardEnv, payload),
+ stdin: "changes\n",
+ hook: "#!/bin/sh\nenv | grep -e '^GL_' -e '^GITALY_' | sort\n",
+ expectedStdout: strings.Join([]string{
+ payload,
+ "GL_ID=1234",
+ fmt.Sprintf("GL_PROJECT_PATH=%s", repo.GetGlProjectPath()),
+ "GL_PROTOCOL=web",
+ fmt.Sprintf("GL_REPO=%s", repo),
+ fmt.Sprintf("GL_REPOSITORY=%s", repo.GetGlRepository()),
+ "GL_USERNAME=user",
+ }, "\n") + "\n",
},
{
desc: "push options are passed through",
diff --git a/internal/gitaly/hook/prereceive_test.go b/internal/gitaly/hook/prereceive_test.go
index 7690a220d..31b50e734 100644
--- a/internal/gitaly/hook/prereceive_test.go
+++ b/internal/gitaly/hook/prereceive_test.go
@@ -70,11 +70,19 @@ func TestPrereceive_customHooks(t *testing.T) {
expectedStderr string
}{
{
- desc: "hook receives environment variables",
- env: append(standardEnv, payload),
- hook: "#!/bin/sh\nenv | grep -e '^GL_' -e '^GITALY_' | sort\n",
- stdin: "change\n",
- expectedStdout: strings.Join(append([]string{payload}, standardEnv...), "\n") + "\n",
+ desc: "hook receives environment variables",
+ env: append(standardEnv, payload),
+ hook: "#!/bin/sh\nenv | grep -e '^GL_' -e '^GITALY_' | sort\n",
+ stdin: "change\n",
+ expectedStdout: strings.Join([]string{
+ payload,
+ "GL_ID=1234",
+ fmt.Sprintf("GL_PROJECT_PATH=%s", repo.GetGlProjectPath()),
+ "GL_PROTOCOL=web",
+ fmt.Sprintf("GL_REPO=%s", repo),
+ fmt.Sprintf("GL_REPOSITORY=%s", repo.GetGlRepository()),
+ "GL_USERNAME=user",
+ }, "\n") + "\n",
},
{
desc: "hook can write to stderr and stdout",
diff --git a/internal/gitaly/hook/update_test.go b/internal/gitaly/hook/update_test.go
index 046d66500..eb79597e1 100644
--- a/internal/gitaly/hook/update_test.go
+++ b/internal/gitaly/hook/update_test.go
@@ -72,13 +72,21 @@ func TestUpdate_customHooks(t *testing.T) {
expectedStderr string
}{
{
- desc: "hook receives environment variables",
- env: append(standardEnv, payload),
- reference: "refs/heads/master",
- oldHash: hash1,
- newHash: hash2,
- hook: "#!/bin/sh\nenv | grep -e '^GL_' -e '^GITALY_' | sort\n",
- expectedStdout: strings.Join(append([]string{payload}, standardEnv...), "\n") + "\n",
+ desc: "hook receives environment variables",
+ env: append(standardEnv, payload),
+ reference: "refs/heads/master",
+ oldHash: hash1,
+ newHash: hash2,
+ hook: "#!/bin/sh\nenv | grep -e '^GL_' -e '^GITALY_' | sort\n",
+ expectedStdout: strings.Join([]string{
+ payload,
+ "GL_ID=1234",
+ fmt.Sprintf("GL_PROJECT_PATH=%s", repo.GetGlProjectPath()),
+ "GL_PROTOCOL=web",
+ fmt.Sprintf("GL_REPO=%s", repo),
+ fmt.Sprintf("GL_REPOSITORY=%s", repo.GetGlRepository()),
+ "GL_USERNAME=user",
+ }, "\n") + "\n",
},
{
desc: "hook receives arguments",