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-03-28 09:17:26 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-03-28 09:34:09 +0300
commit0983a83714199f0fb59eba04459aaab44a89de57 (patch)
tree61f80466c40114544d95321f80703718c21ff161
parent57761a33a63a8cda40a137d487db1b4d3dd4acf8 (diff)
ssh: Refactor tests to not create worktree
Our SSH tests need to set up a repository with some new objects so that it can verify that these objects end up on the remote side after the push. To create those objects, we currently use a worktree and then execute git-commit(1). This usage pattern is outdated though: we have a `gittest.WriteCommit()` helper which does not require a worktree. Refactor tests to use this new helper so that we can get rid of using a worktree.
-rw-r--r--internal/gitaly/service/ssh/receive_pack_test.go53
1 files changed, 15 insertions, 38 deletions
diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go
index cda2fa4aa..266b99844 100644
--- a/internal/gitaly/service/ssh/receive_pack_test.go
+++ b/internal/gitaly/service/ssh/receive_pack_test.go
@@ -571,18 +571,23 @@ type SSHCloneDetails struct {
// setupSSHClone sets up a test clone
func setupSSHClone(t *testing.T, cfg config.Cfg, remoteRepo *gitalypb.Repository, remoteRepoPath string) (SSHCloneDetails, func()) {
- // Make a non-bare clone of the test repo to act as a local one
- _, localRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
- WithWorktree: true,
- })
-
- // We need git thinking we're pushing over SSH...
- oldHead, newHead, success := makeCommit(t, cfg, localRepoPath)
- require.True(t, success)
+ _, localRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+
+ oldHead := text.ChompBytes(gittest.Exec(t, cfg, "-C", localRepoPath, "rev-parse", "HEAD"))
+ newHead := gittest.WriteCommit(t, cfg, localRepoPath,
+ gittest.WithMessage(fmt.Sprintf("Testing ReceivePack RPC around %d", time.Now().Unix())),
+ gittest.WithTreeEntries(gittest.TreeEntry{
+ Path: "foo.txt",
+ Mode: "100644",
+ Content: "foo bar",
+ }),
+ gittest.WithBranch("master"),
+ gittest.WithParents(git.ObjectID(oldHead)),
+ )
return SSHCloneDetails{
- OldHead: oldHead,
- NewHead: newHead,
+ OldHead: []byte(oldHead),
+ NewHead: []byte(newHead.String()),
LocalRepoPath: localRepoPath,
RemoteRepoPath: remoteRepoPath,
TempRepo: remoteRepo.GetRelativePath(),
@@ -644,34 +649,6 @@ func testCloneAndPush(t *testing.T, cfg config.Cfg, serverSocketPath string, rem
return sshPush(t, cfg, cloneDetails, serverSocketPath, params)
}
-// makeCommit creates a new commit and returns oldHead, newHead, success
-func makeCommit(t *testing.T, cfg config.Cfg, localRepoPath string) ([]byte, []byte, bool) {
- commitMsg := fmt.Sprintf("Testing ReceivePack RPC around %d", time.Now().Unix())
- committerName := "Scrooge McDuck"
- committerEmail := "scrooge@mcduck.com"
- newFilePath := localRepoPath + "/foo.txt"
-
- // Create a tiny file and add it to the index
- require.NoError(t, os.WriteFile(newFilePath, []byte("foo bar"), 0o644))
- gittest.Exec(t, cfg, "-C", localRepoPath, "add", ".")
-
- // The latest commit ID on the remote repo
- oldHead := bytes.TrimSpace(gittest.Exec(t, cfg, "-C", localRepoPath, "rev-parse", "master"))
-
- gittest.Exec(t, cfg, "-C", localRepoPath,
- "-c", fmt.Sprintf("user.name=%s", committerName),
- "-c", fmt.Sprintf("user.email=%s", committerEmail),
- "commit", "-m", commitMsg)
- if t.Failed() {
- return nil, nil, false
- }
-
- // The commit ID we want to push to the remote repo
- newHead := bytes.TrimSpace(gittest.Exec(t, cfg, "-C", localRepoPath, "rev-parse", "master"))
-
- return oldHead, newHead, true
-}
-
func drainPostReceivePackResponse(stream gitalypb.SSHService_SSHReceivePackClient) error {
var err error
for err == nil {