resume_credentials_test.go RawHistoryFolder

1package daemon
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/require"
7)
8
9func TestResumeCredentialsLifecycle(t *testing.T) {
10	sessA, sessB := &session{}, &session{}
11	owner, other := &attachedClient{resumeToken: 7}, &attachedClient{resumeToken: 7}
12	tests := []struct {
13		name        string
14		run         func(c *resumeCredentials)
15		wantParked  bool
16		wantParking bool
17		wantSession *session
18	}{
19		{name: "parking marker is visible", run: func(c *resumeCredentials) { c.markParking(sessA, owner) }, wantParking: true, wantSession: sessA},
20		{name: "publishing park clears the owner's marker", run: func(c *resumeCredentials) {
21			c.markParking(sessA, owner)
22			c.publishParked(7, &parkedAttachment{sess: sessA, ac: owner})
23		}, wantParked: true, wantSession: sessA},
24		{name: "another attachment cannot clear the marker", run: func(c *resumeCredentials) {
25			c.markParking(sessA, owner)
26			c.clearParking(7, other)
27		}, wantParking: true, wantSession: sessA},
28		{name: "purging another session keeps the marker", run: func(c *resumeCredentials) {
29			c.markParking(sessA, owner)
30			c.purgeParking(sessB)
31		}, wantParking: true, wantSession: sessA},
32		{name: "purging all markers", run: func(c *resumeCredentials) {
33			c.markParking(sessA, owner)
34			c.purgeParking(nil)
35		}},
36		{name: "stale take is refused", run: func(c *resumeCredentials) {
37			current := &parkedAttachment{sess: sessB, ac: owner}
38			c.publishParked(7, current)
39			require.False(t, c.takeParked(7, &parkedAttachment{sess: sessA, ac: owner}))
40		}, wantParked: true, wantSession: sessB},
41		{name: "current take removes", run: func(c *resumeCredentials) {
42			current := &parkedAttachment{sess: sessA, ac: owner}
43			c.publishParked(7, current)
44			require.True(t, c.takeParked(7, current))
45		}},
46	}
47	for _, tt := range tests {
48		t.Run(tt.name, func(t *testing.T) {
49			credentials := newResumeCredentials()
50			tt.run(&credentials)
51			require.Equal(t, tt.wantParked, credentials.parkedFor(7) != nil)
52			require.Equal(t, tt.wantParking, credentials.parkingFor(7) != nil)
53			require.Same(t, tt.wantSession, credentials.sessionFor(7))
54			require.Equal(t, tt.wantSession == sessA, credentials.retainsSession(sessA))
55			require.Equal(t, tt.wantSession == sessB, credentials.retainsSession(sessB))
56		})
57	}
58}
59
60func TestResumeCredentialsIssueAvoidsHeldTokens(t *testing.T) {
61	credentials := newResumeCredentials()
62	for range 64 {
63		token := credentials.issue()
64		require.NotZero(t, token)
65		require.Nil(t, credentials.parkedFor(token))
66		credentials.publishParked(token, &parkedAttachment{ac: &attachedClient{}})
67	}
68	require.Len(t, credentials.parkedForSession(nil), 64)
69}

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