diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-10-18 10:49:25 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-10-18 11:18:36 +0300 |
commit | fb39ff0f407dc89cc56d6f847b0b046c9b03a230 (patch) | |
tree | 1019f5e07e7d1248e6e573bd4ad979d8eaa0e309 | |
parent | 17f07d1750ebf7f8ff4223f32d6a3d91befaabfa (diff) |
housekeeping: Simplify test set up for `CleanStaleData()`
Simplify the test setup for one of our `CleanStaleData()` tests to only
test for a single file entry. While this requires us to split up one of
the testcases, it makes the test logic easier to amend.
-rw-r--r-- | internal/git/housekeeping/clean_stale_data_test.go | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/internal/git/housekeeping/clean_stale_data_test.go b/internal/git/housekeeping/clean_stale_data_test.go index d8b3f1d24..0baf1533b 100644 --- a/internal/git/housekeeping/clean_stale_data_test.go +++ b/internal/git/housekeeping/clean_stale_data_test.go @@ -570,45 +570,41 @@ func TestRepositoryManager_CleanStaleData_withSpecificFile(t *testing.T) { require.NoError(t, mgr.CleanStaleData(ctx, repo)) for _, subcase := range []struct { desc string - entries []entry + entry entry expectedFiles []string }{ { - desc: fmt.Sprintf("fresh %s is kept", tc.file), - entries: []entry{ - f(tc.file, 0o700, 10*time.Minute, Keep), - }, + desc: fmt.Sprintf("fresh %s is kept", tc.file), + entry: f(tc.file, 0o700, 10*time.Minute, Keep), }, { desc: fmt.Sprintf("stale %s in subdir is kept", tc.file), - entries: []entry{ - d("subdir", 0o700, 240*time.Hour, Keep, - f(tc.file, 0o700, 24*time.Hour, Keep), - ), - }, + entry: d("subdir", 0o700, 240*time.Hour, Keep, + f(tc.file, 0o700, 24*time.Hour, Keep), + ), }, { - desc: fmt.Sprintf("stale %s is deleted", tc.file), - entries: []entry{ - f(tc.file, 0o700, 61*time.Minute, Delete), - }, + desc: fmt.Sprintf("stale %s is deleted", tc.file), + entry: f(tc.file, 0o700, 61*time.Minute, Delete), expectedFiles: []string{ filepath.Join(repoPath, tc.file), }, }, { - desc: fmt.Sprintf("variations of %s are kept", tc.file), - entries: []entry{ - f(tc.file[:len(tc.file)-1], 0o700, 61*time.Minute, Keep), - f("~"+tc.file, 0o700, 61*time.Minute, Keep), - f(tc.file+"~", 0o700, 61*time.Minute, Keep), - }, + desc: fmt.Sprintf("%q is kept", tc.file[:len(tc.file)-1]), + entry: f(tc.file[:len(tc.file)-1], 0o700, 61*time.Minute, Keep), + }, + { + desc: fmt.Sprintf("%q is kept", "~"+tc.file), + entry: f("~"+tc.file, 0o700, 61*time.Minute, Keep), + }, + { + desc: fmt.Sprintf("%q is kept", tc.file+"~"), + entry: f(tc.file+"~", 0o700, 61*time.Minute, Keep), }, } { t.Run(subcase.desc, func(t *testing.T) { - for _, e := range subcase.entries { - e.create(t, repoPath) - } + subcase.entry.create(t, repoPath) staleFiles, err := tc.finder(ctx, repoPath) require.NoError(t, err) @@ -616,9 +612,7 @@ func TestRepositoryManager_CleanStaleData_withSpecificFile(t *testing.T) { require.NoError(t, mgr.CleanStaleData(ctx, repo)) - for _, e := range subcase.entries { - e.validate(t, repoPath) - } + subcase.entry.validate(t, repoPath) }) } |