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-07-21 08:21:27 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-21 10:00:43 +0300
commit9ef8ff076f124483eb194c748bc34b665b6bfb9f (patch)
tree264ddd9cae5c306c1d78e8c0f5917d8e52d143d5
parentc3bada82044d572f246d74e8b5109403a05e5a93 (diff)
gittest: Disallow use of seeded repositories with SHA256
It's not currently possible to use our test repositories in combination with SHA256 given that they're all using SHA1. This makes it easy to accidentally test with SHA1 even though one thought to be testing with SHA256. Detect the use of seeded repositories and fail the test when done with SHA256 is the default hash.
-rw-r--r--internal/git/gittest/objects.go5
-rw-r--r--internal/git/gittest/repo.go8
2 files changed, 13 insertions, 0 deletions
diff --git a/internal/git/gittest/objects.go b/internal/git/gittest/objects.go
index aafca61b2..62ef4733b 100644
--- a/internal/git/gittest/objects.go
+++ b/internal/git/gittest/objects.go
@@ -15,6 +15,11 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
)
+// ObjectHashIsSHA256 returns if the current default object hash is SHA256.
+func ObjectHashIsSHA256() bool {
+ return DefaultObjectHash == git.ObjectHashSHA256
+}
+
// RequireObjectExists asserts that the given repository does contain an object with the specified
// object ID.
func RequireObjectExists(t testing.TB, cfg config.Cfg, repoPath string, objectID git.ObjectID) {
diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go
index 1b4b08bb3..201f459b1 100644
--- a/internal/git/gittest/repo.go
+++ b/internal/git/gittest/repo.go
@@ -144,6 +144,10 @@ func CreateRepository(ctx context.Context, t testing.TB, cfg config.Cfg, configs
}
if opts.Seed != "" {
+ if ObjectHashIsSHA256() {
+ require.FailNow(t, "seeded repository creation not supported with SHA256")
+ }
+
_, err := client.CreateRepositoryFromURL(ctx, &gitalypb.CreateRepositoryFromURLRequest{
Repository: repository,
Url: testRepositoryPath(t, opts.Seed),
@@ -290,6 +294,10 @@ type CloneRepoOpts struct {
// CloneRepo clones a new copy of test repository under a subdirectory in the storage root. You can
// either pass no or exactly one CloneRepoOpts.
func CloneRepo(t testing.TB, cfg config.Cfg, storage config.Storage, opts ...CloneRepoOpts) (*gitalypb.Repository, string) {
+ if ObjectHashIsSHA256() {
+ require.FailNow(t, "seeded repository creation not supported with SHA256")
+ }
+
require.Less(t, len(opts), 2, "you must either pass no or exactly one option")
opt := CloneRepoOpts{}