detached ece7682

navigation_inventory_test.go RawHistoryFolder

1package protocol
2
3import (
4	"strings"
5	"testing"
6
7	"github.com/bnema/vev/internal/domain"
8)
9
10func TestValidateNavigationInventoryRequest(t *testing.T) {
11	registration, err := domain.NewRemoteRegistration("user@arch", [16]byte{1})
12	if err != nil {
13		t.Fatalf("NewRemoteRegistration: %v", err)
14	}
15	tests := []struct {
16		name    string
17		request NavigationInventoryRequest
18		wantErr bool
19	}{
20		{name: "snapshot ok", request: NavigationInventoryRequest{Version: Version, RequestID: 1, Operation: NavigationInventorySnapshot}},
21		{name: "zero request", request: NavigationInventoryRequest{Operation: NavigationInventorySnapshot}, wantErr: true},
22		{name: "bad operation", request: NavigationInventoryRequest{Version: Version, RequestID: 1, Operation: 9}, wantErr: true},
23		{name: "snapshot with keys", request: NavigationInventoryRequest{Version: Version, RequestID: 1, Operation: NavigationInventorySnapshot, SourceKey: "local"}, wantErr: true},
24		{name: "resolve ok", request: NavigationInventoryRequest{Version: Version, RequestID: 2, Operation: NavigationInventoryResolve, SourceKey: "remote-a", EntryKey: "abc", Registration: registration}},
25		{name: "resolve local ok", request: NavigationInventoryRequest{Version: Version, RequestID: 3, Operation: NavigationInventoryResolve, SourceKey: NavigationInventoryLocalSourceKey, EntryKey: "abc"}},
26		{name: "resolve local with registration", request: NavigationInventoryRequest{Version: Version, RequestID: 3, Operation: NavigationInventoryResolve, SourceKey: NavigationInventoryLocalSourceKey, EntryKey: "abc", Registration: registration}, wantErr: true},
27		{name: "resolve missing registration", request: NavigationInventoryRequest{Version: Version, RequestID: 2, Operation: NavigationInventoryResolve, SourceKey: "remote-a", EntryKey: "abc"}, wantErr: true},
28		{name: "resolve bad key", request: NavigationInventoryRequest{Version: Version, RequestID: 2, Operation: NavigationInventoryResolve, SourceKey: "a\x1b", EntryKey: "abc", Registration: registration}, wantErr: true},
29	}
30	for _, tt := range tests {
31		t.Run(tt.name, func(t *testing.T) {
32			err := ValidateNavigationInventoryRequest(tt.request)
33			if (err != nil) != tt.wantErr {
34				t.Fatalf("ValidateNavigationInventoryRequest() = %v, wantErr %t", err, tt.wantErr)
35			}
36		})
37	}
38}
39
40func TestValidateNavigationInventoryResponseUnions(t *testing.T) {
41	group := NavigationInventorySourceGroup{SourceKey: "local", Status: NavigationInventorySourceOK, Entries: []NavigationInventoryEntry{{SourceKey: "local", EntryKey: "a", Name: "one"}}}
42	tests := []struct {
43		name     string
44		response NavigationInventoryResponse
45		wantErr  bool
46	}{
47		{name: "snapshot ok", response: NavigationInventoryResponse{RequestID: 1, Operation: NavigationInventorySnapshot, Status: NavigationInventoryOK, Groups: []NavigationInventorySourceGroup{group}}},
48		{name: "snapshot with target", response: NavigationInventoryResponse{RequestID: 1, Operation: NavigationInventorySnapshot, Status: NavigationInventoryOK, Groups: []NavigationInventorySourceGroup{group}, Resolved: &AttachTarget{}}, wantErr: true},
49		{name: "duplicate source", response: NavigationInventoryResponse{RequestID: 1, Operation: NavigationInventorySnapshot, Status: NavigationInventoryOK, Groups: []NavigationInventorySourceGroup{group, group}}, wantErr: true},
50		{name: "too many groups", response: NavigationInventoryResponse{RequestID: 1, Operation: NavigationInventorySnapshot, Status: NavigationInventoryOK, Groups: make([]NavigationInventorySourceGroup, NavigationInventoryMaxSourceGroups+1)}, wantErr: true},
51		{name: "control char label", response: NavigationInventoryResponse{RequestID: 1, Operation: NavigationInventorySnapshot, Status: NavigationInventoryOK, Groups: []NavigationInventorySourceGroup{{SourceKey: "local", Status: NavigationInventorySourceOK, Entries: []NavigationInventoryEntry{{SourceKey: "local", EntryKey: "a", Name: "bad\x1b"}}}}}, wantErr: true},
52		{name: "oversize label", response: NavigationInventoryResponse{RequestID: 1, Operation: NavigationInventorySnapshot, Status: NavigationInventoryOK, Groups: []NavigationInventorySourceGroup{{SourceKey: "local", Status: NavigationInventorySourceOK, Entries: []NavigationInventoryEntry{{SourceKey: "local", EntryKey: "a", Name: strings.Repeat("x", NavigationInventoryMaxDisplayBytes+1)}}}}}, wantErr: true},
53		{name: "version mismatch clean", response: NavigationInventoryResponse{RequestID: 1, Operation: NavigationInventorySnapshot, Status: NavigationInventoryVersionMismatch}},
54		{name: "version mismatch with target", response: NavigationInventoryResponse{RequestID: 1, Operation: NavigationInventorySnapshot, Status: NavigationInventoryVersionMismatch, Groups: []NavigationInventorySourceGroup{group}}, wantErr: true},
55	}
56	for _, tt := range tests {
57		t.Run(tt.name, func(t *testing.T) {
58			err := ValidateNavigationInventoryResponse(tt.response)
59			if (err != nil) != tt.wantErr {
60				t.Fatalf("ValidateNavigationInventoryResponse() = %v, wantErr %t", err, tt.wantErr)
61			}
62		})
63	}
64}
65
66func TestNavigationCapabilityInventoryValid(t *testing.T) {
67	if err := ValidateNavigation(IntentAttach, NavigationCapabilityInventory); err != nil {
68		t.Fatalf("ValidateNavigation(inventory) = %v", err)
69	}
70}
71
72// TestValidateNavigationBindsInventoryToTheIntentsThatServeIt pins the shared
73// client/daemon rule: inventory is negotiable on the intents whose attachment
74// owns a relay, and no capability is admissible on the others.
75func TestValidateNavigationBindsInventoryToTheIntentsThatServeIt(t *testing.T) {
76	tests := []struct {
77		name         string
78		intent       uint8
79		capabilities NavigationCapabilities
80		wantErr      bool
81	}{
82		{name: "attach inventory", intent: IntentAttach, capabilities: NavigationCapabilityInventory},
83		{name: "resume inventory", intent: IntentResume, capabilities: NavigationCapabilityInventory},
84		{name: "new inventory", intent: IntentNew, capabilities: NavigationCapabilityInventory},
85		{name: "ephemeral inventory", intent: IntentEphemeral, capabilities: NavigationCapabilityInventory, wantErr: true},
86		{name: "ephemeral clean", intent: IntentEphemeral},
87		{name: "unknown bit", intent: IntentAttach, capabilities: 1 << 7, wantErr: true},
88	}
89	for _, tt := range tests {
90		t.Run(tt.name, func(t *testing.T) {
91			err := ValidateNavigation(tt.intent, tt.capabilities)
92			if (err != nil) != tt.wantErr {
93				t.Fatalf("ValidateNavigation(%d, %d) = %v, wantErr %t", tt.intent, tt.capabilities, err, tt.wantErr)
94			}
95		})
96	}
97}

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