diff options
| author | 2026-02-21 15:54:26 +0800 | |
|---|---|---|
| committer | 2026-02-21 15:54:26 +0800 | |
| commit | 6a7fc936c4a969aa05b3941feedafe59f4bd2ffd (patch) | |
| tree | 9518dd365d76f784117a1e5df512fb902e71f7db /refstore/packed/packed_test.go | |
| parent | repository: Add loose object writing (diff) | |
| signature | No signature | |
*: Add more tests
Diffstat (limited to 'refstore/packed/packed_test.go')
| -rw-r--r-- | refstore/packed/packed_test.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/refstore/packed/packed_test.go b/refstore/packed/packed_test.go index efec6ca7..77d15640 100644 --- a/refstore/packed/packed_test.go +++ b/refstore/packed/packed_test.go @@ -133,6 +133,67 @@ func TestPackedListAndShorten(t *testing.T) { }) } +func TestPackedListPatternMatrix(t *testing.T) { + t.Parallel() + testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) + _, _, commitID := testRepo.MakeCommit(t, "packed refs pattern matrix") + testRepo.UpdateRef(t, "refs/heads/main", commitID) + testRepo.UpdateRef(t, "refs/heads/feature/one", commitID) + testRepo.UpdateRef(t, "refs/notes/review", commitID) + testRepo.UpdateRef(t, "refs/tags/v1", commitID) + testRepo.PackRefs(t, "--all", "--prune") + + store := openPackedRefStoreFromRepo(t, testRepo.Dir(), algo) + + tests := []struct { + pattern string + want []string + }{ + { + pattern: "refs/heads/*", + want: []string{"refs/heads/main"}, + }, + { + pattern: "refs/heads/*/*", + want: []string{"refs/heads/feature/one"}, + }, + { + pattern: "refs/*/feature/one", + want: []string{"refs/heads/feature/one"}, + }, + { + pattern: "refs/heads/feat?re/one", + want: []string{"refs/heads/feature/one"}, + }, + { + pattern: "refs/tags/v[0-9]", + want: []string{"refs/tags/v1"}, + }, + { + pattern: "refs/*/*", + want: []string{"refs/heads/main", "refs/notes/review", "refs/tags/v1"}, + }, + } + + for _, tt := range tests { + t.Run(tt.pattern, func(t *testing.T) { + got, err := store.List(tt.pattern) + if err != nil { + t.Fatalf("List(%q): %v", tt.pattern, err) + } + gotNames := refNames(got) + slices.Sort(gotNames) + wantNames := append([]string(nil), tt.want...) + slices.Sort(wantNames) + if !slices.Equal(gotNames, wantNames) { + t.Fatalf("List(%q) names = %v, want %v", tt.pattern, gotNames, wantNames) + } + }) + } + }) +} + func TestPackedParseErrors(t *testing.T) { t.Parallel() testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper @@ -175,6 +236,14 @@ func TestPackedNewValidation(t *testing.T) { } } +func refNames(refs []ref.Ref) []string { + names := make([]string, 0, len(refs)) + for _, entry := range refs { + names = append(names, entry.Name()) + } + return names +} + func stringsOfLen(ch string, n int) string { return string(bytes.Repeat([]byte(ch), n)) } |
