diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-29 13:46:12 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-01 12:54:47 +0300 |
commit | 666c37f78c7bec0b0bff6b5c01456b077d77e45e (patch) | |
tree | 919e83d6593fbe7e04bd95e31633baff2cc540bb | |
parent | c0466ef7dbb071356c4614650bdd18a028534a09 (diff) |
localrepo: Enable testing most parts with SHA256pks-git-localrepo-sha256
Enable testing of most parts of our localrepo tests with SHA256 as
object hash. There are two notable exclusions:
- The remote extra tests depend on the `CreateRepository()` RPC that
doesn't yet support creating SHA256 repositories.
- The `ReadCommit()` function depends on the `catfile` package,
which doesn't yet support parsing SHA256 commits.
We thus skip testing those two parts of the package.
-rw-r--r-- | internal/git/localrepo/config_test.go | 31 | ||||
-rw-r--r-- | internal/git/localrepo/objects_test.go | 6 | ||||
-rw-r--r-- | internal/git/localrepo/paths_test.go | 2 | ||||
-rw-r--r-- | internal/git/localrepo/refs_test.go | 2 | ||||
-rw-r--r-- | internal/git/localrepo/remote_test.go | 2 | ||||
-rw-r--r-- | internal/git/localrepo/repo_test.go | 21 | ||||
-rw-r--r-- | internal/git/localrepo/testhelper_test.go | 2 |
7 files changed, 32 insertions, 34 deletions
diff --git a/internal/git/localrepo/config_test.go b/internal/git/localrepo/config_test.go index a29d8f4eb..3f17c22c5 100644 --- a/internal/git/localrepo/config_test.go +++ b/internal/git/localrepo/config_test.go @@ -1,5 +1,3 @@ -//go:build !gitaly_test_sha256 - package localrepo import ( @@ -97,10 +95,15 @@ func TestRepo_SetConfig(t *testing.T) { require.Equal(t, tc.expectedErr, repo.SetConfig(ctx, tc.key, tc.value, &transaction.MockManager{})) standardEntries := []string{ - "core.repositoryformatversion=0", "core.filemode=true", "core.bare=true", } + if gittest.ObjectHashIsSHA256() { + standardEntries = append(standardEntries, "core.repositoryformatversion=1") + standardEntries = append(standardEntries, "extensions.objectformat=sha256") + } else { + standardEntries = append(standardEntries, "core.repositoryformatversion=0") + } if runtime.GOOS == "darwin" { standardEntries = append(standardEntries, @@ -110,7 +113,7 @@ func TestRepo_SetConfig(t *testing.T) { } output := gittest.Exec(t, cfg, "-C", repoPath, "config", "--list", "--local") - require.Equal(t, + require.ElementsMatch(t, append(standardEntries, tc.expectedEntries...), strings.Split(text.ChompBytes(output), "\n"), ) @@ -147,15 +150,11 @@ func TestRepo_UnsetMatchingConfig(t *testing.T) { "core.filemode", "core.bare", } - if runtime.GOOS == "darwin" { - standardKeys = []string{ - "core.repositoryformatversion", - "core.filemode", - "core.bare", - "core.ignorecase", - "core.precomposeunicode", - } + standardKeys = append(standardKeys, "core.ignorecase", "core.precomposeunicode") + } + if gittest.ObjectHashIsSHA256() { + standardKeys = append(standardKeys, "extensions.objectformat") } for _, tc := range []struct { @@ -179,7 +178,7 @@ func TestRepo_UnsetMatchingConfig(t *testing.T) { "foo.qux": "value2", }, regex: "foo.bar", - expectedKeys: append(standardKeys, "foo.qux"), + expectedKeys: append([]string{"foo.qux"}, standardKeys...), }, { desc: "multiple matches", @@ -197,7 +196,7 @@ func TestRepo_UnsetMatchingConfig(t *testing.T) { "foo.qux": "value2", }, regex: "matchme", - expectedKeys: append(standardKeys, "foo.qux"), + expectedKeys: append([]string{"foo.qux"}, standardKeys...), }, { desc: "anchored", @@ -206,7 +205,7 @@ func TestRepo_UnsetMatchingConfig(t *testing.T) { "matchme.foo": "value2", }, regex: "^matchme", - expectedKeys: append(standardKeys, "foo.matchme"), + expectedKeys: append([]string{"foo.matchme"}, standardKeys...), }, { desc: "no matches", @@ -246,7 +245,7 @@ func TestRepo_UnsetMatchingConfig(t *testing.T) { require.Equal(t, tc.expectedErr, repo.UnsetMatchingConfig(ctx, tc.regex, &transaction.MockManager{})) output := gittest.Exec(t, cfg, "-C", repoPath, "config", "--list", "--name-only", "--local") - require.Equal(t, tc.expectedKeys, strings.Split(text.ChompBytes(output), "\n")) + require.ElementsMatch(t, tc.expectedKeys, strings.Split(text.ChompBytes(output), "\n")) }) } diff --git a/internal/git/localrepo/objects_test.go b/internal/git/localrepo/objects_test.go index c43e24eb3..a4cd9b95c 100644 --- a/internal/git/localrepo/objects_test.go +++ b/internal/git/localrepo/objects_test.go @@ -1,5 +1,3 @@ -//go:build !gitaly_test_sha256 - package localrepo import ( @@ -263,6 +261,10 @@ func TestRepo_ReadObject(t *testing.T) { } func TestRepo_ReadCommit(t *testing.T) { + if gittest.ObjectHashIsSHA256() { + t.Skip("this test is hash-agnostic, but depends on the `git/catfile` package that has not yet been converted") + } + ctx := testhelper.Context(t) cfg, repo, repoPath := setupRepo(t) diff --git a/internal/git/localrepo/paths_test.go b/internal/git/localrepo/paths_test.go index 980b82a95..e785bd01f 100644 --- a/internal/git/localrepo/paths_test.go +++ b/internal/git/localrepo/paths_test.go @@ -1,5 +1,3 @@ -//go:build !gitaly_test_sha256 - package localrepo_test import ( diff --git a/internal/git/localrepo/refs_test.go b/internal/git/localrepo/refs_test.go index 64d5f0219..d5e7f2d28 100644 --- a/internal/git/localrepo/refs_test.go +++ b/internal/git/localrepo/refs_test.go @@ -1,5 +1,3 @@ -//go:build !gitaly_test_sha256 - package localrepo import ( diff --git a/internal/git/localrepo/remote_test.go b/internal/git/localrepo/remote_test.go index 5e22e158d..fe65206d6 100644 --- a/internal/git/localrepo/remote_test.go +++ b/internal/git/localrepo/remote_test.go @@ -1,5 +1,3 @@ -//go:build !gitaly_test_sha256 - package localrepo import ( diff --git a/internal/git/localrepo/repo_test.go b/internal/git/localrepo/repo_test.go index 430a4b0f6..0b773a03a 100644 --- a/internal/git/localrepo/repo_test.go +++ b/internal/git/localrepo/repo_test.go @@ -1,5 +1,3 @@ -//go:build !gitaly_test_sha256 - package localrepo import ( @@ -53,6 +51,13 @@ func TestSize(t *testing.T) { `, commandArgFile, execEnv.BinaryPath) }) + hashDependentSize := func(sha1Size, sha256Size int64) int64 { + if gittest.ObjectHashIsSHA256() { + return sha256Size + } + return sha1Size + } + testCases := []struct { desc string setup func(t *testing.T) *gitalypb.Repository @@ -83,7 +88,7 @@ func TestSize(t *testing.T) { return repoProto }, - expectedSize: 203, + expectedSize: hashDependentSize(203, 230), expectedUseBitmap: true, }, { @@ -124,7 +129,7 @@ func TestSize(t *testing.T) { return repoProto }, - expectedSize: 439, + expectedSize: hashDependentSize(439, 510), expectedUseBitmap: true, }, { @@ -151,7 +156,7 @@ func TestSize(t *testing.T) { return repoProto }, - expectedSize: 398, + expectedSize: hashDependentSize(398, 465), expectedUseBitmap: true, }, { @@ -178,7 +183,7 @@ func TestSize(t *testing.T) { opts: []RepoSizeOption{ WithExcludeRefs("refs/heads/exclude-me"), }, - expectedSize: 217, + expectedSize: hashDependentSize(217, 245), expectedUseBitmap: true, }, { @@ -226,7 +231,7 @@ func TestSize(t *testing.T) { }, // While both repositories have the same contents, we should still return // the actual repository's size because we don't exclude the alternate. - expectedSize: 207, + expectedSize: hashDependentSize(207, 234), // Even though we have an alternate, we should still use bitmap indices // given that we don't use `--not --alternate-refs`. expectedUseBitmap: true, @@ -300,7 +305,7 @@ func TestSize(t *testing.T) { opts: []RepoSizeOption{ WithoutAlternates(), }, - expectedSize: 224, + expectedSize: hashDependentSize(224, 268), expectedUseBitmap: false, }, } diff --git a/internal/git/localrepo/testhelper_test.go b/internal/git/localrepo/testhelper_test.go index a331cbf82..28fc6a851 100644 --- a/internal/git/localrepo/testhelper_test.go +++ b/internal/git/localrepo/testhelper_test.go @@ -1,5 +1,3 @@ -//go:build !gitaly_test_sha256 - package localrepo import ( |