v0.35.1 2aca1df

ciartifacts_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package ciartifacts_test
4
5import (
6	"errors"
7	"io"
8	"os"
9	"path/filepath"
10	"testing"
11
12	"github.com/stretchr/testify/assert"
13	"github.com/stretchr/testify/require"
14
15	"bnema.dev/ermite/internal/adapters/ciartifacts"
16	"bnema.dev/ermite/internal/domain"
17	"bnema.dev/ermite/internal/ports"
18)
19
20var ref = ports.CIArtifactRef{RunID: 7, ID: 42}
21
22func entries(t *testing.T, dir string) []string {
23	t.Helper()
24	es, err := os.ReadDir(dir)
25	if errors.Is(err, os.ErrNotExist) {
26		return nil
27	}
28	require.NoError(t, err)
29	var out []string
30	for _, e := range es {
31		out = append(out, e.Name())
32	}
33	return out
34}
35
36func TestLegacyReadAndRemoval(t *testing.T) {
37	ctx := t.Context()
38	root := t.TempDir()
39	s := ciartifacts.New(root)
40	run := filepath.Join(root, "00000000000000000007")
41	require.NoError(t, os.MkdirAll(run, 0o700))
42	require.NoError(t, os.WriteFile(filepath.Join(run, "00000000000000000042"), []byte("hello world"), 0o600))
43	r, err := s.Open(ctx, ref, 6)
44	require.NoError(t, err)
45	data, err := io.ReadAll(r)
46	require.NoError(t, err)
47	require.NoError(t, r.Close())
48	assert.Equal(t, "world", string(data))
49	ids, err := s.ArtifactIDs(ctx, 7)
50	require.NoError(t, err)
51	assert.Equal(t, []int64{42}, ids)
52	require.NoError(t, s.Remove(ctx, ref))
53	require.NoError(t, s.Remove(ctx, ref))
54	_, err = s.Open(ctx, ref, 0)
55	assert.ErrorIs(t, err, domain.ErrNotFound)
56	require.NoError(t, s.RemoveRuns(ctx, []int64{7}))
57	assert.Empty(t, entries(t, root))
58	for _, bad := range []ports.CIArtifactRef{{RunID: 0, ID: 1}, {RunID: 1, ID: -1}} {
59		_, err := s.Open(ctx, bad, 0)
60		assert.ErrorIs(t, err, domain.ErrNotFound)
61	}
62}
63
64func TestOrphanListingSeesEveryKindOfFile(t *testing.T) {
65	ctx := t.Context()
66	root := t.TempDir()
67	s := ciartifacts.New(root)
68	run := filepath.Join(root, "00000000000000000009")
69	require.NoError(t, os.MkdirAll(filepath.Join(run, "00000000000000000003.blocks"), 0o700))
70	require.NoError(t, os.WriteFile(filepath.Join(run, "00000000000000000001"), nil, 0o600))
71	require.NoError(t, os.WriteFile(filepath.Join(run, ".tmp-00000000000000000002-123"), nil, 0o600))
72	require.NoError(t, os.WriteFile(filepath.Join(run, "junk"), nil, 0o600))
73	require.NoError(t, os.MkdirAll(filepath.Join(root, "not-a-run"), 0o700))
74
75	ids, err := s.ArtifactIDs(ctx, 9)
76	require.NoError(t, err)
77	assert.Equal(t, []int64{1, 2, 3}, ids)
78	runs, err := s.RunIDs(ctx)
79	require.NoError(t, err)
80	assert.Equal(t, []int64{9}, runs)
81
82	// Remove takes the assembly in progress too.
83	require.NoError(t, s.Remove(ctx, ports.CIArtifactRef{RunID: 9, ID: 2}))
84	ids, _ = s.ArtifactIDs(ctx, 9)
85	assert.Equal(t, []int64{1, 3}, ids)
86}

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 4

Tags 45

↑↓ moveenter openesc close