ci_annotation_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain_test
4
5import (
6	"strings"
7	"testing"
8
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/require"
11
12	"bnema.dev/ermite/internal/domain"
13)
14
15func an(level domain.AnnotationLevel, step int32, msg string) domain.CIAnnotation {
16	return domain.CIAnnotation{Level: level, Step: step, Message: msg}
17}
18
19func TestCheckAnnotationsLimits(t *testing.T) {
20	t.Parallel()
21	n, w, f := domain.AnnotationNotice, domain.AnnotationWarning, domain.AnnotationFailure
22	same := func(level domain.AnnotationLevel, step int32, count int) []domain.CIAnnotation {
23		var out []domain.CIAnnotation
24		for range count {
25			out = append(out, an(level, step, "m"))
26		}
27		return out
28	}
29	valid := map[string][]domain.CIAnnotation{
30		"none":                     nil,
31		"ten of a level":           same(n, 1, 10),
32		"ten of each level":        append(append(same(n, 1, 10), same(w, 1, 10)...), same(f, 1, 10)...),
33		"ten per level, two steps": append(same(n, 1, 10), same(n, 2, 10)...),
34		"4096 characters, 8 KiB":   {an(n, 1, strings.Repeat("é", 4096))},
35		"title 4096, file 1024":    {{Level: n, Step: 1, Message: "m", Title: strings.Repeat("é", 4096), File: strings.Repeat("é", 1024)}},
36		"title 600":                {{Level: n, Step: 1, Message: "m", Title: strings.Repeat("t", 600)}},
37		"step 1000":                {an(n, 1000, "m")},
38		"end line equal to start":  {{Level: n, Step: 1, Message: "m", StartLine: 3, EndLine: 3}},
39		"end line without start":   {{Level: n, Step: 1, Message: "m", EndLine: 3}},
40	}
41	for name, anns := range valid {
42		assert.NoError(t, domain.CheckAnnotations(anns), name)
43	}
44	invalid := map[string][]domain.CIAnnotation{
45		"eleven of a level":  same(w, 4, 11),
46		"no level":           {{Step: 1, Message: "m"}},
47		"unknown level":      {{Level: "debug", Step: 1, Message: "m"}},
48		"no message":         {an(n, 1, "")},
49		"message 4097":       {an(n, 1, strings.Repeat("é", 4097))},
50		"title 4097":         {{Level: n, Step: 1, Message: "m", Title: strings.Repeat("t", 4097)}},
51		"file 1025":          {{Level: n, Step: 1, Message: "m", File: strings.Repeat("f", 1025)}},
52		"step 0":             {an(n, 0, "m")},
53		"step 1001":          {an(n, 1001, "m")},
54		"negative line":      {{Level: n, Step: 1, Message: "m", StartLine: -1}},
55		"negative column":    {{Level: n, Step: 1, Message: "m", EndColumn: -1}},
56		"end before start":   {{Level: n, Step: 1, Message: "m", StartLine: 4, EndLine: 3}},
57		"invalid utf-8":      {an(n, 1, "a\xffb")},
58		"one bad among good": append(same(n, 1, 3), an(n, 1, "")),
59	}
60	for name, anns := range invalid {
61		err := domain.CheckAnnotations(anns)
62		require.Error(t, err, name)
63		assert.ErrorIs(t, err, domain.ErrInvalid, name)
64	}
65}
66
67func TestGroupAnnotationsKeepsTheOrderOfAStep(t *testing.T) {
68	t.Parallel()
69	by, steps := domain.GroupAnnotations([]domain.CIAnnotation{
70		an(domain.AnnotationNotice, 10, "ten-a"), an(domain.AnnotationNotice, 2, "two-a"), an(domain.AnnotationFailure, 10, "ten-b"),
71	})
72	assert.Equal(t, []int32{2, 10}, steps)
73	assert.Equal(t, "ten-a", by[10][0].Message)
74	assert.Equal(t, "ten-b", by[10][1].Message)
75}

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 2

Tags 43

↑↓ moveenter openesc close