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>2023-08-21 16:23:20 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-08-21 17:03:35 +0300
commitcab64a05e22215cf8dc879f9fbb125207ad38e51 (patch)
tree18cf10d301da5f1ed28f7536f24af8bd7a1ea1ff /internal
parent3c79c64beacaacc75b55861c4d317732ae367fc1 (diff)
repository: Use `voting.Vote` to compute votes in tests
We're currently hardcoding `sha1` as voting hash in a test for `ReplicateRepository()`. Convert this test to instead use our own `voting` package.
Diffstat (limited to 'internal')
-rw-r--r--internal/gitaly/service/repository/replicate_test.go42
1 files changed, 22 insertions, 20 deletions
diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go
index 2762fd3ef..7b678ec9d 100644
--- a/internal/gitaly/service/repository/replicate_test.go
+++ b/internal/gitaly/service/repository/replicate_test.go
@@ -3,8 +3,6 @@ package repository
import (
"bytes"
"context"
- "crypto/sha1"
- "encoding/hex"
"fmt"
"io"
"io/fs"
@@ -35,6 +33,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v16/internal/transaction/txinfo"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/transaction/voting"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
@@ -702,10 +701,13 @@ func testReplicateRepositoryTransactional(t *testing.T, ctx context.Context) {
targetRepo := proto.Clone(sourceRepo).(*gitalypb.Repository)
targetRepo.StorageName = cfg.Storages[1].Name
- var votes []string
+ var votes []voting.Vote
txServer := testTransactionServer{
vote: func(request *gitalypb.VoteTransactionRequest) (*gitalypb.VoteTransactionResponse, error) {
- votes = append(votes, hex.EncodeToString(request.ReferenceUpdatesHash))
+ vote, err := voting.VoteFromHash(request.ReferenceUpdatesHash)
+ require.NoError(t, err)
+ votes = append(votes, vote)
+
return &gitalypb.VoteTransactionResponse{
State: gitalypb.VoteTransactionResponse_COMMIT,
}, nil
@@ -737,23 +739,23 @@ func testReplicateRepositoryTransactional(t *testing.T, ctx context.Context) {
require.NoError(t, err)
// There is no gitattributes file, so we vote on the empty contents of that file.
- gitattributesVote := sha1.Sum([]byte{})
+ gitattributesVote := voting.VoteFromData([]byte{})
// There is a gitconfig though, so the vote should reflect its contents.
- gitconfigVote := sha1.Sum(testhelper.MustReadFile(t, filepath.Join(sourceRepoPath, "config")))
+ gitconfigVote := voting.VoteFromData(testhelper.MustReadFile(t, filepath.Join(sourceRepoPath, "config")))
- noHooksVote := "fd69c38637bf443296edc19e2b2c649d0502f7c0"
+ noHooksVote := voting.Vote("fd69c38637bf443296edc19e2b2c649d0502f7c0")
- expectedVotes := []string{
+ expectedVotes := []voting.Vote{
// We cannot easily derive these first two votes: they are based on the complete
// hashed contents of the unpacked repository. We thus just only assert that they
// are always the first two entries and that they are the same by simply taking the
// first vote twice here.
votes[0],
votes[0],
- hex.EncodeToString(gitconfigVote[:]),
- hex.EncodeToString(gitconfigVote[:]),
- hex.EncodeToString(gitattributesVote[:]),
- hex.EncodeToString(gitattributesVote[:]),
+ gitconfigVote,
+ gitconfigVote,
+ gitattributesVote,
+ gitattributesVote,
noHooksVote,
noHooksVote,
}
@@ -762,7 +764,7 @@ func testReplicateRepositoryTransactional(t *testing.T, ctx context.Context) {
// We're about to change refs/heads/master, and thus the mirror-fetch will update it. The
// vote should reflect that.
- replicationVote := sha1.Sum([]byte(fmt.Sprintf("%[1]s %[2]s refs/heads/master\n", commitID2, commitID1)))
+ replicationVote := voting.VoteFromData([]byte(fmt.Sprintf("%[1]s %[2]s refs/heads/master\n", commitID2, commitID1)))
// We're now changing a reference in the source repository such that we can observe changes
// in the target repo.
@@ -777,13 +779,13 @@ func testReplicateRepositoryTransactional(t *testing.T, ctx context.Context) {
})
require.NoError(t, err)
- expectedVotes = []string{
- hex.EncodeToString(gitconfigVote[:]),
- hex.EncodeToString(gitconfigVote[:]),
- hex.EncodeToString(gitattributesVote[:]),
- hex.EncodeToString(gitattributesVote[:]),
- hex.EncodeToString(replicationVote[:]),
- hex.EncodeToString(replicationVote[:]),
+ expectedVotes = []voting.Vote{
+ gitconfigVote,
+ gitconfigVote,
+ gitattributesVote,
+ gitattributesVote,
+ replicationVote,
+ replicationVote,
noHooksVote,
noHooksVote,
}