settings_test.go RawHistoryFolder

1package webterm
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/require"
7)
8
9func TestWebSettings(t *testing.T) {
10	for _, tt := range []struct {
11		name, listen, origin, wantListen, wantOrigin string
12	}{
13		{"defaults", "", "", Address, Origin},
14		{"loopback port", "127.0.0.1:9000", "", "127.0.0.1:9000", "http://127.0.0.1:9000"},
15		{"IPv6", "[::1]:9000", "", "[::1]:9000", "http://[::1]:9000"},
16		{"proxy", "", "https://Terminal.example.internal:443/", Address, "https://terminal.example.internal"},
17		{"private HTTP", "100.64.0.10:8778", "http://100.64.0.10:8778", "100.64.0.10:8778", "http://100.64.0.10:8778"},
18		{"wildcard explicit", "0.0.0.0:9000", "https://terminal.example.internal", "0.0.0.0:9000", "https://terminal.example.internal"},
19		{"IPv6 proxy", "[::]:9000", "https://[fd00::1]:9443", "[::]:9000", "https://[fd00::1]:9443"},
20	} {
21		t.Run(tt.name, func(t *testing.T) {
22			got, err := ParseSettings(tt.listen, tt.origin)
23			require.NoError(t, err)
24			require.Equal(t, Settings{Listen: tt.wantListen, Origin: tt.wantOrigin}, got)
25		})
26	}
27	for _, listen := range []string{"localhost:8778", ":8778", "127.0.0.1:0", "127.0.0.1:65536", "127.0.0.1:http", "[fe80::1%eth0]:8778", "224.0.0.1:8778"} {
28		t.Run(listen, func(t *testing.T) {
29			_, err := ParseSettings(listen, Origin)
30			require.Error(t, err)
31		})
32	}
33	for _, origin := range []string{"//example.internal", "ftp://example.internal", "https://user@example.internal", "https://example.internal/path", "https://example.internal?", "https://example.internal#", "https://example.internal:0", "https://example.internal:65536", "https://example.internal:", "https://*.example.internal", "https://0.0.0.0", "https://[::]", "https://bad_host", "https://example.internal/%2f", "https://[fe80::1%25eth0]"} {
34		t.Run(origin, func(t *testing.T) {
35			_, err := ParseSettings("", origin)
36			require.Error(t, err)
37		})
38	}
39	for _, listen := range []string{"0.0.0.0:8778", "[::]:8778", "100.64.0.10:8778"} {
40		_, err := ParseSettings(listen, "")
41		require.Error(t, err)
42	}
43}
44
45func TestWebProbeAddressZeroValue(t *testing.T) {
46	var settings Settings
47	require.Equal(t, "", settings.ProbeAddress(), "zero-value settings must not panic")
48	settings.Listen = "not-an-address"
49	require.Equal(t, "", settings.ProbeAddress())
50}
51
52func TestWebProbeAddress(t *testing.T) {
53	for _, tt := range []struct{ listen, want string }{
54		{"0.0.0.0:9000", "127.0.0.1:9000"},
55		{"[::]:9000", "[::1]:9000"},
56		{"127.0.0.2:9000", "127.0.0.2:9000"},
57	} {
58		t.Run(tt.listen, func(t *testing.T) {
59			settings, err := ParseSettings(tt.listen, "https://terminal.example.internal")
60			require.NoError(t, err)
61			require.Equal(t, tt.want, settings.ProbeAddress())
62		})
63	}
64}

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