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:
authorSami Hiltunen <shiltunen@gitlab.com>2020-12-16 16:16:38 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2020-12-16 16:19:35 +0300
commit3e0a09f1f940eeda81df8c797a62bc918127e874 (patch)
tree5fee7cb809407ff959716bdaafe9d2937f63e688
parentbca59804605b4afd0bebacbaa0952c5b4ca16141 (diff)
stub out hook manager when hooks are disabled in tests
Gitaly has a `GITALY_TESTING_NO_GIT_HOOKS` environment variable to disable git hooks during tests. Currently, it only skips configuring the interal API client but leaves the hook manager in place. This causes nil pointer dereferencing panics when executing code that would invoke hooks when the environment variable is set. This commit fixes the problem by stubbing out the whole hook manager when the environment variable is set.
-rw-r--r--cmd/gitaly/main.go9
-rw-r--r--internal/gitaly/hook/disabled_manager.go31
2 files changed, 37 insertions, 3 deletions
diff --git a/cmd/gitaly/main.go b/cmd/gitaly/main.go
index 73f1a38fa..eb4316575 100644
--- a/cmd/gitaly/main.go
+++ b/cmd/gitaly/main.go
@@ -127,6 +127,7 @@ func run(b *bootstrap.Bootstrap) error {
var gitlabAPI hook.GitlabAPI
var err error
+ hookManager := hook.Manager(hook.DisabledManager{})
if config.SkipHooks() {
log.Warn("skipping GitLab API client creation since hooks are bypassed via GITALY_TESTING_NO_GIT_HOOKS")
} else {
@@ -134,10 +135,12 @@ func run(b *bootstrap.Bootstrap) error {
if err != nil {
log.Fatalf("could not create GitLab API client: %v", err)
}
- }
- hookManager := hook.NewManager(config.NewLocator(config.Config), gitlabAPI, config.Config)
- prometheus.MustRegister(hookManager)
+ hm := hook.NewManager(config.NewLocator(config.Config), gitlabAPI, config.Config)
+ prometheus.MustRegister(hm)
+
+ hookManager = hm
+ }
conns := client.NewPoolWithOptions(
client.WithDialer(client.HealthCheckDialer(client.DialContext)),
diff --git a/internal/gitaly/hook/disabled_manager.go b/internal/gitaly/hook/disabled_manager.go
new file mode 100644
index 000000000..192739aef
--- /dev/null
+++ b/internal/gitaly/hook/disabled_manager.go
@@ -0,0 +1,31 @@
+package hook
+
+import (
+ "context"
+ "io"
+
+ "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+)
+
+// DisabledManager never executes hooks and simply returns a nil error.
+type DisabledManager struct{}
+
+// PreReceiveHook ignores its parameters and returns a nil error.
+func (DisabledManager) PreReceiveHook(context.Context, *gitalypb.Repository, []string, io.Reader, io.Writer, io.Writer) error {
+ return nil
+}
+
+// PostReceiveHook ignores its parameters and returns a nil error.
+func (DisabledManager) PostReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, io.Writer, io.Writer) error {
+ return nil
+}
+
+// UpdateHook ignores its parameters and returns a nil error.
+func (DisabledManager) UpdateHook(context.Context, *gitalypb.Repository, string, string, string, []string, io.Writer, io.Writer) error {
+ return nil
+}
+
+// ReferenceTransactionHook ignores its parameters and returns a nil error.
+func (DisabledManager) ReferenceTransactionHook(context.Context, ReferenceTransactionState, []string, io.Reader) error {
+ return nil
+}