recovery_test.go RawHistoryFolder

1package domain
2
3import (
4	"crypto/rand"
5	"testing"
6
7	"github.com/stretchr/testify/require"
8)
9
10func TestNewIncarnationID(t *testing.T) {
11	id, err := NewIncarnationID(rand.Reader)
12	require.NoError(t, err)
13	require.NotEqual(t, IncarnationID{}, id)
14	require.Len(t, id.String(), 32)
15}
16
17func TestIncarnationIDText(t *testing.T) {
18	id := IncarnationID{0: 0xab, 15: 0xcd}
19	text, err := id.MarshalText()
20	require.NoError(t, err)
21	require.Equal(t, "ab0000000000000000000000000000cd", string(text))
22	var decoded IncarnationID
23	require.NoError(t, decoded.UnmarshalText(text))
24	require.Equal(t, id, decoded)
25	require.Error(t, decoded.UnmarshalText([]byte("AB0000000000000000000000000000CD")))
26
27	_, err = (IncarnationID{}).MarshalText()
28	require.Error(t, err)
29	require.Error(t, decoded.UnmarshalText([]byte("00000000000000000000000000000000")))
30	require.Equal(t, id, decoded, "rejected zero text must not mutate the receiver")
31}
32
33func TestCatalogueRecordValidate(t *testing.T) {
34	validRef := &CheckpointRef{Generation: 7, ManifestDigest: [32]byte{1}}
35	tests := []struct {
36		name      string
37		record    CatalogueRecord
38		wantValid bool
39	}{
40		{name: "fresh valid", record: CatalogueRecord{Name: "work", IncarnationID: IncarnationID{1}}, wantValid: true},
41		{name: "healthy with committed checkpoint valid", record: CatalogueRecord{Name: "work", IncarnationID: IncarnationID{1}, Committed: &CheckpointRef{Generation: 7, ManifestDigest: [32]byte{1}}}, wantValid: true},
42		{name: "invalid session name", record: CatalogueRecord{Name: "bad/name", IncarnationID: IncarnationID{1}}},
43		{name: "zero incarnation", record: CatalogueRecord{Name: "work"}},
44		{name: "broken with committed checkpoint valid", record: CatalogueRecord{Name: "work", IncarnationID: IncarnationID{1}, Committed: validRef, DegradedReason: "missing manifest"}, wantValid: true},
45		{name: "broken without committed checkpoint", record: CatalogueRecord{Name: "work", IncarnationID: IncarnationID{1}, DegradedReason: "missing manifest"}},
46		{name: "zero checkpoint generation", record: CatalogueRecord{Name: "work", IncarnationID: IncarnationID{1}, Committed: &CheckpointRef{ManifestDigest: [32]byte{1}}}},
47		{name: "zero checkpoint digest", record: CatalogueRecord{Name: "work", IncarnationID: IncarnationID{1}, Committed: &CheckpointRef{Generation: 7}}},
48	}
49	for _, tt := range tests {
50		t.Run(tt.name, func(t *testing.T) {
51			err := tt.record.Validate()
52			if tt.wantValid {
53				require.NoError(t, err)
54			} else {
55				require.Error(t, err)
56			}
57		})
58	}
59}
60
61func TestCatalogueRecordEqualUsesCheckpointValuesAndOrderedTabs(t *testing.T) {
62	committed := CheckpointRef{Generation: 2, ManifestDigest: [32]byte{2}}
63	left := CatalogueRecord{Name: "work", IncarnationID: IncarnationID{1}, TabNames: []string{"shell", "logs"}, Committed: &committed}
64	right := left
65	right.TabNames = append([]string(nil), left.TabNames...)
66	committedCopy := committed
67	right.Committed = &committedCopy
68	require.True(t, left.Equal(right))
69
70	right.TabNames[0], right.TabNames[1] = right.TabNames[1], right.TabNames[0]
71	require.False(t, left.Equal(right))
72	require.True(t, (*CheckpointRef)(nil).Equal(nil))
73	require.False(t, left.Committed.Equal(nil))
74}

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 12

Tags 11

↑↓ moveenter openesc close