v2.31.0-dev8 ec8c5b9

blob_cleanup_test.go RawHistoryFolder

1package filesystem
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7	"time"
8
9	"github.com/bnema/zerowrap"
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/require"
12)
13
14func TestBlobStorage_CleanupStaleUploads_RemovesOldFiles(t *testing.T) {
15	tmpDir := t.TempDir()
16	bs, err := NewBlobStorage(tmpDir, zerowrap.Default())
17	require.NoError(t, err)
18
19	uploadsDir := filepath.Join(tmpDir, "uploads")
20	stalePath := filepath.Join(uploadsDir, "stale-uuid-1234")
21	require.NoError(t, os.WriteFile(stalePath, make([]byte, 1024), 0600))
22	staleTime := time.Now().Add(-48 * time.Hour)
23	require.NoError(t, os.Chtimes(stalePath, staleTime, staleTime))
24
25	removed, bytes, err := bs.CleanupStaleUploads(24 * time.Hour)
26	require.NoError(t, err)
27	assert.Equal(t, 1, removed)
28	assert.Equal(t, int64(1024), bytes)
29	assert.NoFileExists(t, stalePath)
30}
31
32func TestBlobStorage_CleanupStaleUploads_PreservesRecentFiles(t *testing.T) {
33	tmpDir := t.TempDir()
34	bs, err := NewBlobStorage(tmpDir, zerowrap.Default())
35	require.NoError(t, err)
36
37	uploadsDir := filepath.Join(tmpDir, "uploads")
38	recentPath := filepath.Join(uploadsDir, "recent-uuid-5678")
39	require.NoError(t, os.WriteFile(recentPath, make([]byte, 512), 0600))
40
41	removed, bytes, err := bs.CleanupStaleUploads(24 * time.Hour)
42	require.NoError(t, err)
43	assert.Equal(t, 0, removed)
44	assert.Equal(t, int64(0), bytes)
45	assert.FileExists(t, recentPath)
46}
47
48func TestBlobStorage_CleanupStaleUploads_EmptyUploadsDir(t *testing.T) {
49	tmpDir := t.TempDir()
50	bs, err := NewBlobStorage(tmpDir, zerowrap.Default())
51	require.NoError(t, err)
52
53	removed, bytes, err := bs.CleanupStaleUploads(24 * time.Hour)
54	require.NoError(t, err)
55	assert.Equal(t, 0, removed)
56	assert.Equal(t, int64(0), bytes)
57}
58
59func TestBlobStorage_CleanupStaleUploads_MixedAges(t *testing.T) {
60	tmpDir := t.TempDir()
61	bs, err := NewBlobStorage(tmpDir, zerowrap.Default())
62	require.NoError(t, err)
63
64	uploadsDir := filepath.Join(tmpDir, "uploads")
65
66	stalePath := filepath.Join(uploadsDir, "stale-uuid")
67	require.NoError(t, os.WriteFile(stalePath, make([]byte, 2048), 0600))
68	staleTime := time.Now().Add(-72 * time.Hour)
69	require.NoError(t, os.Chtimes(stalePath, staleTime, staleTime))
70
71	recentPath := filepath.Join(uploadsDir, "recent-uuid")
72	require.NoError(t, os.WriteFile(recentPath, make([]byte, 512), 0600))
73
74	removed, bytes, err := bs.CleanupStaleUploads(24 * time.Hour)
75	require.NoError(t, err)
76	assert.Equal(t, 1, removed)
77	assert.Equal(t, int64(2048), bytes)
78	assert.NoFileExists(t, stalePath)
79	assert.FileExists(t, recentPath)
80}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close