diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-28 14:19:20 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-01 07:34:57 +0300 |
commit | 78e9a9cc83102f2a608a353d7739d2bec2dd47f4 (patch) | |
tree | fa1ce1e483e2131a693359f4539f9e5a7fbbfb4b | |
parent | 13d2aa37056b68c81f5a8098a8015a0771b0211b (diff) |
ssh: Refactor test for transactional SSHReceivePack to be hash-agnostic
Refacor tests for transactional voting in SSHReceivePack to be
hash-agnostic instead of assuming that we use SHA1 as an object hash.
-rw-r--r-- | internal/gitaly/service/ssh/receive_pack_test.go | 97 |
1 files changed, 47 insertions, 50 deletions
diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go index 14a4af3e7..695654a5f 100644 --- a/internal/gitaly/service/ssh/receive_pack_test.go +++ b/internal/gitaly/service/ssh/receive_pack_test.go @@ -402,41 +402,38 @@ func TestReceivePack_hidesObjectPoolReferences(t *testing.T) { func TestReceivePack_transactional(t *testing.T) { t.Parallel() + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - testcfg.BuildGitalyHooks(t, cfg) - txManager := transaction.NewTrackingManager() cfg.SocketPath = runSSHServer(t, cfg, testserver.WithTransactionManager(txManager)) - ctx := testhelper.Context(t) - repoProto, repoPath := gittest.CreateRepository(testhelper.Context(t), t, cfg, gittest.CreateRepositoryConfig{ - Seed: gittest.SeedGitLabTest, - }) - repo := localrepo.NewTestRepo(t, cfg, repoProto) + testcfg.BuildGitalyHooks(t, cfg) client, conn := newSSHClient(t, cfg.SocketPath) defer conn.Close() + ctx, err := txinfo.InjectTransaction(ctx, 1, "node", true) require.NoError(t, err) ctx = metadata.IncomingToOutgoing(ctx) - masterOID := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, - "rev-parse", "refs/heads/master")) - masterParentOID := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/master~")) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg) + repo := localrepo.NewTestRepo(t, cfg, repoProto) + parentCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) + commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"), gittest.WithParents(parentCommitID)) type command struct { ref string - oldOID string - newOID string + oldOID git.ObjectID + newOID git.ObjectID } for _, tc := range []struct { desc string writePackfile bool commands []command - expectedRefs map[string]string + expectedRefs map[string]git.ObjectID expectedVotes int }{ { @@ -444,13 +441,13 @@ func TestReceivePack_transactional(t *testing.T) { writePackfile: true, commands: []command{ { - ref: "refs/heads/master", - oldOID: masterOID, - newOID: masterOID, + ref: "refs/heads/main", + oldOID: commitID, + newOID: commitID, }, }, - expectedRefs: map[string]string{ - "refs/heads/master": masterOID, + expectedRefs: map[string]git.ObjectID{ + "refs/heads/main": commitID, }, expectedVotes: 3, }, @@ -459,13 +456,13 @@ func TestReceivePack_transactional(t *testing.T) { writePackfile: true, commands: []command{ { - ref: "refs/heads/master", - oldOID: masterOID, - newOID: masterParentOID, + ref: "refs/heads/main", + oldOID: commitID, + newOID: parentCommitID, }, }, - expectedRefs: map[string]string{ - "refs/heads/master": masterParentOID, + expectedRefs: map[string]git.ObjectID{ + "refs/heads/main": parentCommitID, }, expectedVotes: 3, }, @@ -475,12 +472,12 @@ func TestReceivePack_transactional(t *testing.T) { commands: []command{ { ref: "refs/heads/other", - oldOID: git.ObjectHashSHA1.ZeroOID.String(), - newOID: masterOID, + oldOID: gittest.DefaultObjectHash.ZeroOID, + newOID: commitID, }, }, - expectedRefs: map[string]string{ - "refs/heads/other": masterOID, + expectedRefs: map[string]git.ObjectID{ + "refs/heads/other": commitID, }, expectedVotes: 3, }, @@ -489,12 +486,12 @@ func TestReceivePack_transactional(t *testing.T) { commands: []command{ { ref: "refs/heads/other", - oldOID: masterOID, - newOID: git.ObjectHashSHA1.ZeroOID.String(), + oldOID: commitID, + newOID: gittest.DefaultObjectHash.ZeroOID, }, }, - expectedRefs: map[string]string{ - "refs/heads/other": git.ObjectHashSHA1.ZeroOID.String(), + expectedRefs: map[string]git.ObjectID{ + "refs/heads/other": gittest.DefaultObjectHash.ZeroOID, }, expectedVotes: 3, }, @@ -504,18 +501,18 @@ func TestReceivePack_transactional(t *testing.T) { commands: []command{ { ref: "refs/heads/a", - oldOID: git.ObjectHashSHA1.ZeroOID.String(), - newOID: masterOID, + oldOID: gittest.DefaultObjectHash.ZeroOID, + newOID: commitID, }, { ref: "refs/heads/b", - oldOID: git.ObjectHashSHA1.ZeroOID.String(), - newOID: masterOID, + oldOID: gittest.DefaultObjectHash.ZeroOID, + newOID: commitID, }, }, - expectedRefs: map[string]string{ - "refs/heads/a": masterOID, - "refs/heads/b": masterOID, + expectedRefs: map[string]git.ObjectID{ + "refs/heads/a": commitID, + "refs/heads/b": commitID, }, expectedVotes: 5, }, @@ -525,12 +522,12 @@ func TestReceivePack_transactional(t *testing.T) { commands: []command{ { ref: "refs/heads/a", - oldOID: git.ObjectHashSHA1.ZeroOID.String(), - newOID: masterParentOID, + oldOID: gittest.DefaultObjectHash.ZeroOID, + newOID: parentCommitID, }, }, - expectedRefs: map[string]string{ - "refs/heads/a": masterOID, + expectedRefs: map[string]git.ObjectID{ + "refs/heads/a": commitID, }, expectedVotes: 1, }, @@ -540,17 +537,17 @@ func TestReceivePack_transactional(t *testing.T) { commands: []command{ { ref: "refs/heads/a", - oldOID: git.ObjectHashSHA1.ZeroOID.String(), - newOID: masterParentOID, + oldOID: gittest.DefaultObjectHash.ZeroOID, + newOID: parentCommitID, }, { ref: "refs/heads/b", - oldOID: masterOID, - newOID: git.ObjectHashSHA1.ZeroOID.String(), + oldOID: commitID, + newOID: gittest.DefaultObjectHash.ZeroOID, }, }, - expectedRefs: map[string]string{ - "refs/heads/a": masterOID, + expectedRefs: map[string]git.ObjectID{ + "refs/heads/a": commitID, }, expectedVotes: 3, }, @@ -594,11 +591,11 @@ func TestReceivePack_transactional(t *testing.T) { for expectedRef, expectedOID := range tc.expectedRefs { actualOID, err := repo.ResolveRevision(ctx, git.Revision(expectedRef)) - if expectedOID == git.ObjectHashSHA1.ZeroOID.String() { + if expectedOID == gittest.DefaultObjectHash.ZeroOID { require.Equal(t, git.ErrReferenceNotFound, err) } else { require.NoError(t, err) - require.Equal(t, expectedOID, actualOID.String()) + require.Equal(t, expectedOID, actualOID) } } require.Equal(t, tc.expectedVotes, len(txManager.Votes())) |