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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-17 12:29:49 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-17 14:51:21 +0300
commita392d42cfff4143a2bf5b2e7bf2f74448e6ea23b (patch)
tree7fda15cfb8f55c4836b6fb452c448bc305594904
parent751fd3b6e28682a50efd937541d12b6f723967ea (diff)
ssh: Avoid using worktrees in tests
We're currently creating a worktree in some of smarthttp's tests in order to be able to write commits. Convert `newTestPush()` to instead use `gittest.WriteCommit()`, which doesn't require a worktree.
-rw-r--r--internal/gitaly/service/smarthttp/receive_pack_test.go41
1 files changed, 7 insertions, 34 deletions
diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go
index ea5175466..88508dc95 100644
--- a/internal/gitaly/service/smarthttp/receive_pack_test.go
+++ b/internal/gitaly/service/smarthttp/receive_pack_test.go
@@ -10,7 +10,6 @@ import (
"path/filepath"
"strings"
"testing"
- "time"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/backchannel"
@@ -294,21 +293,20 @@ type pushData struct {
}
func newTestPush(t *testing.T, cfg config.Cfg, fileContents []byte) *pushData {
- _, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
- })
+ _, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- oldHead, newHead := createCommit(t, cfg, repoPath, fileContents)
+ oldCommitID := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "HEAD"))
+ newCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(git.ObjectID(oldCommitID)))
// ReceivePack request is a packet line followed by a packet flush, then the pack file of the objects we want to push.
// This is explained a bit in https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols#_uploading_data
// We form the packet line the same way git executable does: https://github.com/git/git/blob/d1a13d3fcb252631361a961cb5e2bf10ed467cba/send-pack.c#L524-L527
requestBuffer := &bytes.Buffer{}
- pkt := fmt.Sprintf("%s %s refs/heads/master\x00 %s", oldHead, newHead, uploadPackCapabilities)
+ pkt := fmt.Sprintf("%s %s refs/heads/master\x00 %s", oldCommitID, newCommitID, uploadPackCapabilities)
fmt.Fprintf(requestBuffer, "%04x%s", len(pkt)+4, pkt)
- pkt = fmt.Sprintf("%s %s refs/heads/branch", git.ZeroOID, newHead)
+ pkt = fmt.Sprintf("%s %s refs/heads/branch", git.ZeroOID, newCommitID)
fmt.Fprintf(requestBuffer, "%04x%s", len(pkt)+4, pkt)
fmt.Fprintf(requestBuffer, "%s", pktFlushStr)
@@ -317,7 +315,7 @@ func newTestPush(t *testing.T, cfg config.Cfg, fileContents []byte) *pushData {
// which expects a list of revisions passed through standard input. The list format means
// pack the objects needed if I have oldHead but not newHead (think of it from the perspective of the remote repo).
// For more info, check the man pages of both `git-pack-objects` and `git-rev-list --objects`.
- stdin := strings.NewReader(fmt.Sprintf("^%s\n%s\n", oldHead, newHead))
+ stdin := strings.NewReader(fmt.Sprintf("^%s\n%s\n", oldCommitID, newCommitID))
// The options passed are the same ones used when doing an actual push.
pack := gittest.ExecOpts(t, cfg, gittest.ExecConfig{Stdin: stdin},
@@ -325,32 +323,7 @@ func newTestPush(t *testing.T, cfg config.Cfg, fileContents []byte) *pushData {
)
requestBuffer.Write(pack)
- return &pushData{newHead: newHead, body: requestBuffer}
-}
-
-// createCommit creates a commit on HEAD with a file containing the
-// specified contents.
-func createCommit(t *testing.T, cfg config.Cfg, repoPath string, fileContents []byte) (oldHead string, newHead string) {
- commitMsg := fmt.Sprintf("Testing ReceivePack RPC around %d", time.Now().Unix())
- committerName := "Scrooge McDuck"
- committerEmail := "scrooge@mcduck.com"
-
- // The latest commit ID on the remote repo
- oldHead = text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "master"))
-
- changedFile := "README.md"
- require.NoError(t, os.WriteFile(filepath.Join(repoPath, changedFile), fileContents, 0o644))
-
- gittest.Exec(t, cfg, "-C", repoPath, "add", changedFile)
- gittest.Exec(t, cfg, "-C", repoPath,
- "-c", fmt.Sprintf("user.name=%s", committerName),
- "-c", fmt.Sprintf("user.email=%s", committerEmail),
- "commit", "-m", commitMsg)
-
- // The commit ID we want to push to the remote repo
- newHead = text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "master"))
-
- return oldHead, newHead
+ return &pushData{newHead: newCommitID.String(), body: requestBuffer}
}
func TestFailedReceivePackRequestDueToValidationError(t *testing.T) {