diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2018-10-04 17:53:54 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2018-10-04 17:59:46 +0300 |
commit | 00d31b470ec727584201d66c30de0c6312930072 (patch) | |
tree | dc30dcb2e36a168aa45b0800e8ef2666f1f773c1 | |
parent | e0bc50d6878608962086bf702907ed3d65ea1bac (diff) |
Extract key from git env in a nicer wayprotocol-v2-env-line
-rw-r--r-- | internal/service/smarthttp/inforefs_test.go | 6 | ||||
-rw-r--r-- | internal/service/smarthttp/receive_pack_test.go | 6 | ||||
-rw-r--r-- | internal/service/smarthttp/upload_pack_test.go | 7 | ||||
-rw-r--r-- | internal/service/ssh/receive_pack_test.go | 6 | ||||
-rw-r--r-- | internal/service/ssh/upload_pack_test.go | 6 | ||||
-rw-r--r-- | internal/testhelper/testhelper.go | 14 |
6 files changed, 17 insertions, 28 deletions
diff --git a/internal/service/smarthttp/inforefs_test.go b/internal/service/smarthttp/inforefs_test.go index 7cbb73928..0892ef60c 100644 --- a/internal/service/smarthttp/inforefs_test.go +++ b/internal/service/smarthttp/inforefs_test.go @@ -85,11 +85,7 @@ func TestSuccessfulInfoRefsUploadPackWithGitProtocol(t *testing.T) { } require.NoError(t, err) - envData := testhelper.GetGitEnvData() - - if !strings.Contains(envData, "GIT_PROTOCOL=version=2") { - t.Errorf("Expected response to set GIT_PROTOCOL, found %q", envData) - } + require.Equal(t, "GIT_PROTOCOL=version=2", testhelper.GetGitEnv("GIT_PROTOCOL")) } func makeInfoRefsUploadPackRequest(t *testing.T, serverSocketPath string, rpcRequest *pb.InfoRefsRequest) ([]byte, error) { diff --git a/internal/service/smarthttp/receive_pack_test.go b/internal/service/smarthttp/receive_pack_test.go index e21628d3d..f10687304 100644 --- a/internal/service/smarthttp/receive_pack_test.go +++ b/internal/service/smarthttp/receive_pack_test.go @@ -101,11 +101,7 @@ func TestSuccessfulReceivePackRequestWithGitProtocol(t *testing.T) { firstRequest := &pb.PostReceivePackRequest{Repository: repo, GlId: "user-123", GlRepository: "project-123", GitProtocol: "version=2"} doPush(t, stream, firstRequest, push.body) - envData := testhelper.GetGitEnvData() - - if !strings.Contains(envData, "GIT_PROTOCOL=version=2") { - t.Errorf("Expected response to set GIT_PROTOCOL, found %q", envData) - } + require.Equal(t, "GIT_PROTOCOL=version=2", testhelper.GetGitEnv("GIT_PROTOCOL")) // The fact that this command succeeds means that we got the commit correctly, no further checks should be needed. testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "show", push.newHead) diff --git a/internal/service/smarthttp/upload_pack_test.go b/internal/service/smarthttp/upload_pack_test.go index 7f64ba669..c9aeefbd6 100644 --- a/internal/service/smarthttp/upload_pack_test.go +++ b/internal/service/smarthttp/upload_pack_test.go @@ -7,7 +7,6 @@ import ( "io" "os" "path" - "strings" "testing" "time" @@ -191,11 +190,7 @@ func TestUploadPackRequestWithGitProtocol(t *testing.T) { _, err = makePostUploadPackRequest(t, serverSocketPath, rpcRequest, requestBody) require.NoError(t, err) - envData := testhelper.GetGitEnvData() - - if !strings.Contains(envData, "GIT_PROTOCOL=version=2") { - t.Errorf("Expected response to set GIT_PROTOCOL, found %q", envData) - } + require.Equal(t, "GIT_PROTOCOL=version=2", testhelper.GetGitEnv("GIT_PROTOCOL")) } // This test is here because git-upload-pack returns a non-zero exit code diff --git a/internal/service/ssh/receive_pack_test.go b/internal/service/ssh/receive_pack_test.go index f38aad6d9..d21e97594 100644 --- a/internal/service/ssh/receive_pack_test.go +++ b/internal/service/ssh/receive_pack_test.go @@ -117,11 +117,7 @@ func TestReceivePackPushSuccessWithGitProtocol(t *testing.T) { t.Errorf("local and remote head not equal. push failed: %q != %q", lHead, rHead) } - envData := testhelper.GetGitEnvData() - - if !strings.Contains(envData, "GIT_PROTOCOL=version=2") { - t.Errorf("Expected response to set GIT_PROTOCOL, found %q", envData) - } + require.Equal(t, "GIT_PROTOCOL=version=2", testhelper.GetGitEnv("GIT_PROTOCOL")) } func TestReceivePackPushFailure(t *testing.T) { diff --git a/internal/service/ssh/upload_pack_test.go b/internal/service/ssh/upload_pack_test.go index 9d48644fe..25c569fb6 100644 --- a/internal/service/ssh/upload_pack_test.go +++ b/internal/service/ssh/upload_pack_test.go @@ -131,11 +131,7 @@ func TestUploadPackCloneSuccessWithGitProtocol(t *testing.T) { require.NoError(t, err, "clone failed") require.Equal(t, lHead, rHead, "local and remote head not equal") - envData := testhelper.GetGitEnvData() - - if !strings.Contains(envData, "GIT_PROTOCOL=version=2") { - t.Errorf("Expected response to set GIT_PROTOCOL, found %q", envData) - } + require.Equal(t, "GIT_PROTOCOL=version=2", testhelper.GetGitEnv("GIT_PROTOCOL")) }) } } diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index 5195af7e5..2a7b0eb40 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -257,8 +257,18 @@ func ConfigureRuby() { } } -// GetGitEnvData reads and returns the content of testGitEnv -func GetGitEnvData() string { +// GetGitEnv fetches a key from a captured git environment +func GetGitEnv(key string) string { + for _, line := range strings.Split(getGitEnvData(), "\n") { + if strings.HasPrefix(line, key+"=") { + return line + } + } + + return "" +} + +func getGitEnvData() string { gitEnvBytes, err := ioutil.ReadFile(testGitEnv) if err != nil { |