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-10-18 10:24:04 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-10-18 11:13:56 +0300
commit17f07d1750ebf7f8ff4223f32d6a3d91befaabfa (patch)
tree7249dd868cb59e9287cada78842dd058547999bd
parent7d88809fa9bac82129b76e472f80e917eb0e3806 (diff)
housekeeping: Refactor test helpers that create file tree entries
The tests for `CleanStaleData()` use a set of helper functions to create file tree entries. These functions return an interface type though instead of the concrete implementation, making them hard to use in tests that do indeed need the concrete type. Refactor the helper functions to return concrete types. This can make them harder to use though given that the `d()` function accepts an array of the interface, and callers would now potentially have to convert the concrete-type array to the interface-type array. This is alleviated by accepting a vararg parameter instead of an array.
-rw-r--r--internal/git/housekeeping/clean_stale_data_test.go156
1 files changed, 78 insertions, 78 deletions
diff --git a/internal/git/housekeeping/clean_stale_data_test.go b/internal/git/housekeeping/clean_stale_data_test.go
index 5a8e5f218..d8b3f1d24 100644
--- a/internal/git/housekeeping/clean_stale_data_test.go
+++ b/internal/git/housekeeping/clean_stale_data_test.go
@@ -126,11 +126,11 @@ func (d *dirEntry) validate(t *testing.T, parent string) {
}
}
-func f(name string, mode os.FileMode, age time.Duration, finalState entryFinalState) entry {
+func f(name string, mode os.FileMode, age time.Duration, finalState entryFinalState) *fileEntry {
return &fileEntry{name, mode, age, finalState}
}
-func d(name string, mode os.FileMode, age time.Duration, finalState entryFinalState, entries []entry) entry {
+func d(name string, mode os.FileMode, age time.Duration, finalState entryFinalState, entries ...entry) *dirEntry {
return &dirEntry{fileEntry{name, mode, age, finalState}, entries}
}
@@ -185,38 +185,38 @@ func TestRepositoryManager_CleanStaleData(t *testing.T) {
{
name: "clean",
entries: []entry{
- d("objects", 0o700, 240*time.Hour, Keep, []entry{
+ d("objects", 0o700, 240*time.Hour, Keep,
f("a", 0o700, 24*time.Hour, Keep),
f("b", 0o700, 24*time.Hour, Keep),
f("c", 0o700, 24*time.Hour, Keep),
- }),
+ ),
},
},
{
name: "emptyperms",
entries: []entry{
- d("objects", 0o700, 240*time.Hour, Keep, []entry{
+ d("objects", 0o700, 240*time.Hour, Keep,
f("b", 0o700, 24*time.Hour, Keep),
f("tmp_a", 0o000, 2*time.Hour, Keep),
- }),
+ ),
},
},
{
name: "emptytempdir",
entries: []entry{
- d("objects", 0o700, 240*time.Hour, Keep, []entry{
- d("tmp_d", 0o000, 240*time.Hour, Keep, []entry{}),
+ d("objects", 0o700, 240*time.Hour, Keep,
+ d("tmp_d", 0o000, 240*time.Hour, Keep),
f("b", 0o700, 24*time.Hour, Keep),
- }),
+ ),
},
},
{
name: "oldtempfile",
entries: []entry{
- d("objects", 0o700, 240*time.Hour, Keep, []entry{
+ d("objects", 0o700, 240*time.Hour, Keep,
f("tmp_a", 0o770, 240*time.Hour, Delete),
f("b", 0o700, 24*time.Hour, Keep),
- }),
+ ),
},
expectedMetrics: cleanStaleDataMetrics{
objects: 1,
@@ -225,11 +225,11 @@ func TestRepositoryManager_CleanStaleData(t *testing.T) {
{
name: "subdir temp file",
entries: []entry{
- d("objects", 0o700, 240*time.Hour, Keep, []entry{
- d("a", 0o770, 240*time.Hour, Keep, []entry{
+ d("objects", 0o700, 240*time.Hour, Keep,
+ d("a", 0o770, 240*time.Hour, Keep,
f("tmp_b", 0o700, 240*time.Hour, Delete),
- }),
- }),
+ ),
+ ),
},
expectedMetrics: cleanStaleDataMetrics{
objects: 1,
@@ -238,23 +238,23 @@ func TestRepositoryManager_CleanStaleData(t *testing.T) {
{
name: "inaccessible tmp directory",
entries: []entry{
- d("objects", 0o700, 240*time.Hour, Keep, []entry{
- d("tmp_a", 0o000, 240*time.Hour, Keep, []entry{
+ d("objects", 0o700, 240*time.Hour, Keep,
+ d("tmp_a", 0o000, 240*time.Hour, Keep,
f("tmp_b", 0o700, 240*time.Hour, Delete),
- }),
- }),
+ ),
+ ),
},
},
{
name: "deeply nested inaccessible tmp directory",
entries: []entry{
- d("objects", 0o700, 240*time.Hour, Keep, []entry{
- d("tmp_a", 0o700, 240*time.Hour, Keep, []entry{
- d("tmp_a", 0o700, 24*time.Hour, Keep, []entry{
+ d("objects", 0o700, 240*time.Hour, Keep,
+ d("tmp_a", 0o700, 240*time.Hour, Keep,
+ d("tmp_a", 0o700, 24*time.Hour, Keep,
f("tmp_b", 0o000, 240*time.Hour, Delete),
- }),
- }),
- }),
+ ),
+ ),
+ ),
},
expectedMetrics: cleanStaleDataMetrics{
objects: 1,
@@ -264,9 +264,9 @@ func TestRepositoryManager_CleanStaleData(t *testing.T) {
name: "files outside of object database",
entries: []entry{
f("tmp_a", 0o770, 240*time.Hour, Keep),
- d("info", 0o700, 240*time.Hour, Keep, []entry{
+ d("info", 0o700, 240*time.Hour, Keep,
f("tmp_a", 0o770, 240*time.Hour, Keep),
- }),
+ ),
},
},
}
@@ -413,31 +413,31 @@ func TestRepositoryManager_CleanStaleData_emptyRefDirs(t *testing.T) {
{
name: "unrelated empty directories",
entries: []entry{
- d("objects", 0o700, 240*time.Hour, Keep, []entry{
- d("empty", 0o700, 240*time.Hour, Keep, []entry{}),
- }),
+ d("objects", 0o700, 240*time.Hour, Keep,
+ d("empty", 0o700, 240*time.Hour, Keep),
+ ),
},
},
{
name: "empty ref dir gets retained",
entries: []entry{
- d("refs", 0o700, 240*time.Hour, Keep, []entry{}),
+ d("refs", 0o700, 240*time.Hour, Keep),
},
},
{
name: "empty nested non-stale ref dir gets kept",
entries: []entry{
- d("refs", 0o700, 240*time.Hour, Keep, []entry{
- d("nested", 0o700, 23*time.Hour, Keep, []entry{}),
- }),
+ d("refs", 0o700, 240*time.Hour, Keep,
+ d("nested", 0o700, 23*time.Hour, Keep),
+ ),
},
},
{
name: "empty nested stale ref dir gets pruned",
entries: []entry{
- d("refs", 0o700, 240*time.Hour, Keep, []entry{
- d("nested", 0o700, 240*time.Hour, Delete, []entry{}),
- }),
+ d("refs", 0o700, 240*time.Hour, Keep,
+ d("nested", 0o700, 240*time.Hour, Delete),
+ ),
},
expectedMetrics: cleanStaleDataMetrics{
refsEmptyDir: 1,
@@ -446,11 +446,11 @@ func TestRepositoryManager_CleanStaleData_emptyRefDirs(t *testing.T) {
{
name: "hierarchy of nested stale ref dirs gets pruned",
entries: []entry{
- d("refs", 0o700, 240*time.Hour, Keep, []entry{
- d("first", 0o700, 240*time.Hour, Delete, []entry{
- d("second", 0o700, 240*time.Hour, Delete, []entry{}),
- }),
- }),
+ d("refs", 0o700, 240*time.Hour, Keep,
+ d("first", 0o700, 240*time.Hour, Delete,
+ d("second", 0o700, 240*time.Hour, Delete),
+ ),
+ ),
},
expectedMetrics: cleanStaleDataMetrics{
refsEmptyDir: 2,
@@ -459,13 +459,13 @@ func TestRepositoryManager_CleanStaleData_emptyRefDirs(t *testing.T) {
{
name: "hierarchy with intermediate non-stale ref dir gets kept",
entries: []entry{
- d("refs", 0o700, 240*time.Hour, Keep, []entry{
- d("first", 0o700, 240*time.Hour, Keep, []entry{
- d("second", 0o700, 1*time.Hour, Keep, []entry{
- d("third", 0o700, 24*time.Hour, Delete, []entry{}),
- }),
- }),
- }),
+ d("refs", 0o700, 240*time.Hour, Keep,
+ d("first", 0o700, 240*time.Hour, Keep,
+ d("second", 0o700, 1*time.Hour, Keep,
+ d("third", 0o700, 24*time.Hour, Delete),
+ ),
+ ),
+ ),
},
expectedMetrics: cleanStaleDataMetrics{
refsEmptyDir: 1,
@@ -474,16 +474,16 @@ func TestRepositoryManager_CleanStaleData_emptyRefDirs(t *testing.T) {
{
name: "stale hierrachy with refs gets partially retained",
entries: []entry{
- d("refs", 0o700, 240*time.Hour, Keep, []entry{
- d("first", 0o700, 240*time.Hour, Keep, []entry{
- d("second", 0o700, 240*time.Hour, Delete, []entry{
- d("third", 0o700, 24*time.Hour, Delete, []entry{}),
- }),
- d("other", 0o700, 240*time.Hour, Keep, []entry{
+ d("refs", 0o700, 240*time.Hour, Keep,
+ d("first", 0o700, 240*time.Hour, Keep,
+ d("second", 0o700, 240*time.Hour, Delete,
+ d("third", 0o700, 24*time.Hour, Delete),
+ ),
+ d("other", 0o700, 240*time.Hour, Keep,
f("ref", 0o700, 1*time.Hour, Keep),
- }),
- }),
- }),
+ ),
+ ),
+ ),
},
expectedMetrics: cleanStaleDataMetrics{
refsEmptyDir: 2,
@@ -582,9 +582,9 @@ func TestRepositoryManager_CleanStaleData_withSpecificFile(t *testing.T) {
{
desc: fmt.Sprintf("stale %s in subdir is kept", tc.file),
entries: []entry{
- d("subdir", 0o700, 240*time.Hour, Keep, []entry{
+ d("subdir", 0o700, 240*time.Hour, Keep,
f(tc.file, 0o700, 24*time.Hour, Keep),
- }),
+ ),
},
},
{
@@ -634,20 +634,20 @@ func TestRepositoryManager_CleanStaleData_serverInfo(t *testing.T) {
repo := localrepo.NewTestRepo(t, cfg, repoProto)
entries := []entry{
- d("info", 0o755, 0, Keep, []entry{
+ d("info", 0o755, 0, Keep,
f("ref", 0, 0o644, Keep),
f("refs", 0, 0o644, Delete),
f("refsx", 0, 0o644, Keep),
f("refs_123456", 0, 0o644, Delete),
- }),
- d("objects", 0o755, 0, Keep, []entry{
- d("info", 0o755, 0, Keep, []entry{
+ ),
+ d("objects", 0o755, 0, Keep,
+ d("info", 0o755, 0, Keep,
f("pack", 0, 0o644, Keep),
f("packs", 0, 0o644, Delete),
f("packsx", 0, 0o644, Keep),
f("packs_123456", 0, 0o644, Delete),
- }),
- }),
+ ),
+ ),
}
for _, entry := range entries {
@@ -688,19 +688,19 @@ func TestRepositoryManager_CleanStaleData_referenceLocks(t *testing.T) {
{
desc: "fresh lock is kept",
entries: []entry{
- d("refs", 0o755, 0*time.Hour, Keep, []entry{
+ d("refs", 0o755, 0*time.Hour, Keep,
f("main", 0o755, 10*time.Minute, Keep),
f("main.lock", 0o755, 10*time.Minute, Keep),
- }),
+ ),
},
},
{
desc: "stale lock is deleted",
entries: []entry{
- d("refs", 0o755, 0*time.Hour, Keep, []entry{
+ d("refs", 0o755, 0*time.Hour, Keep,
f("main", 0o755, 1*time.Hour, Keep),
f("main.lock", 0o755, 1*time.Hour, Delete),
- }),
+ ),
},
expectedReferenceLocks: []string{
"refs/main.lock",
@@ -712,20 +712,20 @@ func TestRepositoryManager_CleanStaleData_referenceLocks(t *testing.T) {
{
desc: "nested reference locks are deleted",
entries: []entry{
- d("refs", 0o755, 0*time.Hour, Keep, []entry{
- d("tags", 0o755, 0*time.Hour, Keep, []entry{
+ d("refs", 0o755, 0*time.Hour, Keep,
+ d("tags", 0o755, 0*time.Hour, Keep,
f("main", 0o755, 1*time.Hour, Keep),
f("main.lock", 0o755, 1*time.Hour, Delete),
- }),
- d("heads", 0o755, 0*time.Hour, Keep, []entry{
+ ),
+ d("heads", 0o755, 0*time.Hour, Keep,
f("main", 0o755, 1*time.Hour, Keep),
f("main.lock", 0o755, 1*time.Hour, Delete),
- }),
- d("foobar", 0o755, 0*time.Hour, Keep, []entry{
+ ),
+ d("foobar", 0o755, 0*time.Hour, Keep,
f("main", 0o755, 1*time.Hour, Keep),
f("main.lock", 0o755, 1*time.Hour, Delete),
- }),
- }),
+ ),
+ ),
},
expectedReferenceLocks: []string{
"refs/tags/main.lock",