Commit ae1e9bda authored by Jacob Vosmaer (GitLab)'s avatar Jacob Vosmaer (GitLab) Committed by Nick Thomas

Decorate local info refs and remove GitalyAddress

parent 7ab2ede6
...@@ -56,15 +56,10 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) { ...@@ -56,15 +56,10 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
gitalyAddress := "unix://" + socketPath gitalyAddress := "unix://" + socketPath
apiResponseOld := gitOkBody(t)
apiResponseOld.GitalyServer = gitaly.Server{}
apiResponseOld.GitalyAddress = gitalyAddress
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
apiResponse.GitalyServer.Address = gitalyAddress apiResponse.GitalyServer.Address = gitalyAddress
for _, a := range []*api.Response{apiResponseOld, apiResponse} { ts := testAuthServer(nil, 200, apiResponse)
ts := testAuthServer(nil, 200, a)
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
...@@ -75,7 +70,6 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) { ...@@ -75,7 +70,6 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
expectedContent := string(testhelper.GitalyInfoRefsResponseMock) expectedContent := string(testhelper.GitalyInfoRefsResponseMock)
assert.Equal(t, expectedContent, body, "GET %q: response body", resource) assert.Equal(t, expectedContent, body, "GET %q: response body", resource)
}
} }
func TestGetInfoRefsProxiedToGitalyInterruptedStream(t *testing.T) { func TestGetInfoRefsProxiedToGitalyInterruptedStream(t *testing.T) {
...@@ -265,7 +259,6 @@ func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { ...@@ -265,7 +259,6 @@ func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
defer gitalyServer.Stop() defer gitalyServer.Stop()
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
apiResponse.GitalyAddress = ""
apiResponse.GitalyServer.Address = "" apiResponse.GitalyServer.Address = ""
ts := testAuthServer(nil, 200, apiResponse) ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close() defer ts.Close()
...@@ -286,7 +279,6 @@ func TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { ...@@ -286,7 +279,6 @@ func TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
defer gitalyServer.Stop() defer gitalyServer.Stop()
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
apiResponse.GitalyAddress = ""
apiResponse.GitalyServer.Address = "" apiResponse.GitalyServer.Address = ""
ts := testAuthServer(nil, 200, apiResponse) ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close() defer ts.Close()
...@@ -308,7 +300,6 @@ func TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { ...@@ -308,7 +300,6 @@ func TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
defer gitalyServer.Stop() defer gitalyServer.Stop()
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
apiResponse.GitalyAddress = ""
apiResponse.GitalyServer.Address = "" apiResponse.GitalyServer.Address = ""
ts := testAuthServer(nil, 200, apiResponse) ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close() defer ts.Close()
......
...@@ -105,8 +105,6 @@ type Response struct { ...@@ -105,8 +105,6 @@ type Response struct {
Entry string `json:"entry"` Entry string `json:"entry"`
// Used to communicate terminal session details // Used to communicate terminal session details
Terminal *TerminalSettings Terminal *TerminalSettings
// DEPRECATED. GitalyAddress is a unix:// or tcp:// address to reach a Gitaly service on
GitalyAddress string
// GitalyServer specifies an address and authentication token for a gitaly server we should connect to. // GitalyServer specifies an address and authentication token for a gitaly server we should connect to.
GitalyServer gitaly.Server GitalyServer gitaly.Server
// Repository object for making gRPC requests to Gitaly. This will // Repository object for making gRPC requests to Gitaly. This will
...@@ -231,11 +229,6 @@ func (api *API) PreAuthorize(suffix string, r *http.Request) (httpResponse *http ...@@ -231,11 +229,6 @@ func (api *API) PreAuthorize(suffix string, r *http.Request) (httpResponse *http
return httpResponse, nil, fmt.Errorf("preAuthorizeHandler: decode authorization response: %v", err) return httpResponse, nil, fmt.Errorf("preAuthorizeHandler: decode authorization response: %v", err)
} }
if authResponse.GitalyServer.Address == "" {
authResponse.GitalyServer.Address = authResponse.GitalyAddress
}
authResponse.GitalyAddress = ""
return httpResponse, authResponse, nil return httpResponse, authResponse, nil
} }
......
...@@ -11,6 +11,11 @@ import ( ...@@ -11,6 +11,11 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper" "gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
) )
var (
// Testing is only set during workhorse testing.
Testing = false
)
func GetInfoRefsHandler(a *api.API) http.Handler { func GetInfoRefsHandler(a *api.API) http.Handler {
return repoPreAuthorizeHandler(a, handleGetInfoRefs) return repoPreAuthorizeHandler(a, handleGetInfoRefs)
} }
...@@ -31,8 +36,8 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response) ...@@ -31,8 +36,8 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
w.Header().Set("Cache-Control", "no-cache") w.Header().Set("Cache-Control", "no-cache")
var err error var err error
if a.GitalyServer.Address == "" { if a.GitalyServer.Address == "" && Testing {
err = handleGetInfoRefsLocally(w, a, rpc) err = handleGetInfoRefsLocalTesting(w, a, rpc)
} else { } else {
err = handleGetInfoRefsWithGitaly(r.Context(), w, a, rpc) err = handleGetInfoRefsWithGitaly(r.Context(), w, a, rpc)
} }
...@@ -42,7 +47,10 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response) ...@@ -42,7 +47,10 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
} }
} }
func handleGetInfoRefsLocally(w http.ResponseWriter, a *api.Response, rpc string) error { // This code is not used in production. It is left over from before
// Gitaly. We left it here to allow local workhorse tests to keep working
// until we are done migrating Git HTTP to Gitaly.
func handleGetInfoRefsLocalTesting(w http.ResponseWriter, a *api.Response, rpc string) error {
if err := pktLine(w, fmt.Sprintf("# service=%s\n", rpc)); err != nil { if err := pktLine(w, fmt.Sprintf("# service=%s\n", rpc)); err != nil {
return fmt.Errorf("pktLine: %v", err) return fmt.Errorf("pktLine: %v", err)
} }
......
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api" "gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/config" "gitlab.com/gitlab-org/gitlab-workhorse/internal/config"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/git"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly" "gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper" "gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper" "gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
...@@ -41,6 +42,8 @@ var checkoutDir = path.Join(scratchDir, "test") ...@@ -41,6 +42,8 @@ var checkoutDir = path.Join(scratchDir, "test")
var cacheDir = path.Join(scratchDir, "cache") var cacheDir = path.Join(scratchDir, "cache")
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
git.Testing = true
source := "https://gitlab.com/gitlab-org/gitlab-test.git" source := "https://gitlab.com/gitlab-org/gitlab-test.git"
clonePath := path.Join(testRepoRoot, testRepo) clonePath := path.Join(testRepoRoot, testRepo)
if _, err := os.Stat(clonePath); err != nil { if _, err := os.Stat(clonePath); err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment