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,26 +56,20 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
gitalyAddress := "unix://" + socketPath
apiResponseOld := gitOkBody(t)
apiResponseOld.GitalyServer = gitaly.Server{}
apiResponseOld.GitalyAddress = gitalyAddress
apiResponse := gitOkBody(t)
apiResponse.GitalyServer.Address = gitalyAddress
for _, a := range []*api.Response{apiResponseOld, apiResponse} {
ts := testAuthServer(nil, 200, a)
defer ts.Close()
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
ws := startWorkhorseServer(ts.URL)
defer ws.Close()
ws := startWorkhorseServer(ts.URL)
defer ws.Close()
resource := "/gitlab-org/gitlab-test.git/info/refs?service=git-upload-pack"
_, body := httpGet(t, ws.URL+resource)
resource := "/gitlab-org/gitlab-test.git/info/refs?service=git-upload-pack"
_, body := httpGet(t, ws.URL+resource)
expectedContent := string(testhelper.GitalyInfoRefsResponseMock)
assert.Equal(t, expectedContent, body, "GET %q: response body", resource)
}
expectedContent := string(testhelper.GitalyInfoRefsResponseMock)
assert.Equal(t, expectedContent, body, "GET %q: response body", resource)
}
func TestGetInfoRefsProxiedToGitalyInterruptedStream(t *testing.T) {
......@@ -265,7 +259,6 @@ func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
defer gitalyServer.Stop()
apiResponse := gitOkBody(t)
apiResponse.GitalyAddress = ""
apiResponse.GitalyServer.Address = ""
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
......@@ -286,7 +279,6 @@ func TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
defer gitalyServer.Stop()
apiResponse := gitOkBody(t)
apiResponse.GitalyAddress = ""
apiResponse.GitalyServer.Address = ""
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
......@@ -308,7 +300,6 @@ func TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
defer gitalyServer.Stop()
apiResponse := gitOkBody(t)
apiResponse.GitalyAddress = ""
apiResponse.GitalyServer.Address = ""
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
......
......@@ -105,8 +105,6 @@ type Response struct {
Entry string `json:"entry"`
// Used to communicate terminal session details
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 gitaly.Server
// 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
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
}
......
......@@ -11,6 +11,11 @@ import (
"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 {
return repoPreAuthorizeHandler(a, handleGetInfoRefs)
}
......@@ -31,8 +36,8 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
w.Header().Set("Cache-Control", "no-cache")
var err error
if a.GitalyServer.Address == "" {
err = handleGetInfoRefsLocally(w, a, rpc)
if a.GitalyServer.Address == "" && Testing {
err = handleGetInfoRefsLocalTesting(w, a, rpc)
} else {
err = handleGetInfoRefsWithGitaly(r.Context(), w, a, rpc)
}
......@@ -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 {
return fmt.Errorf("pktLine: %v", err)
}
......
......@@ -20,6 +20,7 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"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/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
......@@ -41,6 +42,8 @@ var checkoutDir = path.Join(scratchDir, "test")
var cacheDir = path.Join(scratchDir, "cache")
func TestMain(m *testing.M) {
git.Testing = true
source := "https://gitlab.com/gitlab-org/gitlab-test.git"
clonePath := path.Join(testRepoRoot, testRepo)
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