diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-05-11 12:38:45 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-05-12 10:37:45 +0300 |
commit | 25e307ccf61880f80eea51828c8a1e886f2d7533 (patch) | |
tree | 496e61a237d2b04d911ee9f48ce944362ccfddc5 /internal | |
parent | 3e8fa7c272824fdfceb5a4de5292592c148433e9 (diff) |
git/stats: Introduce test helper to write files with mtime
We're about to add more testcases that care about file mtimes. Let's
thus wrap this functionality into a simple test helper.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/git/stats/repository_info_test.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/internal/git/stats/repository_info_test.go b/internal/git/stats/repository_info_test.go index dbfb1360f..9235581c3 100644 --- a/internal/git/stats/repository_info_test.go +++ b/internal/git/stats/repository_info_test.go @@ -357,10 +357,8 @@ func TestRepositoryInfoForRepository(t *testing.T) { desc: "last full repack timestamp", setup: func(t *testing.T, repoPath string) { timestampPath := filepath.Join(repoPath, fullRepackTimestampFilename) - require.NoError(t, os.WriteFile(timestampPath, nil, perm.PrivateFile)) - date := time.Date(2005, 4, 7, 15, 13, 13, 0, time.Local) - require.NoError(t, os.Chtimes(timestampPath, date, date)) + writeFileWithMtime(t, timestampPath, nil, date) }, expectedInfo: RepositoryInfo{ Packfiles: PackfilesInfo{ @@ -576,8 +574,7 @@ func TestCountLooseObjects(t *testing.T) { beforeCutoffDate := cutoffDate.Add(-1 * time.Minute) for _, objectPath := range objectPaths { - require.NoError(t, os.WriteFile(objectPath, []byte("1"), perm.SharedFile)) - require.NoError(t, os.Chtimes(objectPath, afterCutoffDate, afterCutoffDate)) + writeFileWithMtime(t, objectPath, []byte("1"), afterCutoffDate) } // Objects are recent, so with the cutoff-date they shouldn't be counted. @@ -1486,3 +1483,9 @@ func hashDependentSize(sha1, sha256 uint64) uint64 { } return sha256 } + +func writeFileWithMtime(tb testing.TB, path string, content []byte, date time.Time) { + tb.Helper() + require.NoError(tb, os.WriteFile(path, content, perm.PrivateFile)) + require.NoError(tb, os.Chtimes(path, date, date)) +} |