From 1724a2847f39effcf3317b501fda0c7310f9be7a Mon Sep 17 00:00:00 2001 From: Pavlo Strokov Date: Sat, 13 Feb 2021 01:22:51 +0200 Subject: Gitaly-ruby server should not depend on the global state Configuration of the gitaly-ruby server depends on the global config.Config variable. As we are on the road to removing it this change break this dependency by introducing a constructor function that accepts required configuration. That change requires refactoring of the gitaly-ruby test instance setup - now it should be created only after configuration is properly set. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699 --- internal/testhelper/testserver.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'internal/testhelper/testserver.go') diff --git a/internal/testhelper/testserver.go b/internal/testhelper/testserver.go index 119e387f4..57bd3e15c 100644 --- a/internal/testhelper/testserver.go +++ b/internal/testhelper/testserver.go @@ -825,6 +825,8 @@ type GitlabTestServerOptions struct { // NewGitlabTestServer returns a mock gitlab server that responds to the hook api endpoints func NewGitlabTestServer(t testing.TB, options GitlabTestServerOptions) (url string, cleanup func()) { + t.Helper() + mux := http.NewServeMux() prefix := strings.TrimRight(options.RelativeURLRoot, "/") + "/api/v4/internal" mux.Handle(prefix+"/allowed", http.HandlerFunc(handleAllowed(t, options))) @@ -911,6 +913,8 @@ func WriteTemporaryGitalyConfigFile(t testing.TB, tempDir, gitlabURL, user, pass // WriteShellSecretFile writes a .gitlab_shell_secret file in the specified directory func WriteShellSecretFile(t testing.TB, dir, secretToken string) { + t.Helper() + require.NoError(t, os.MkdirAll(dir, os.ModeDir)) require.NoError(t, ioutil.WriteFile(filepath.Join(dir, ".gitlab_shell_secret"), []byte(secretToken), 0644)) } @@ -945,10 +949,10 @@ func NewHealthServerWithListener(t testing.TB, listener net.Listener) (*grpc.Ser // SetupAndStartGitlabServer creates a new GitlabTestServer, starts it and sets // up the gitlab-shell secret. -func SetupAndStartGitlabServer(t testing.TB, c *GitlabTestServerOptions) (string, func()) { +func SetupAndStartGitlabServer(t testing.TB, shellDir string, c *GitlabTestServerOptions) (string, func()) { url, cleanup := NewGitlabTestServer(t, *c) - WriteShellSecretFile(t, config.Config.GitlabShell.Dir, c.SecretToken) + WriteShellSecretFile(t, shellDir, c.SecretToken) return url, cleanup } -- cgit v1.2.3