v2.31.0-dev16 8d0a092

validation_test.go RawHistoryFolder

1package auto
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7)
8
9func TestMatchesDomainAllowlist(t *testing.T) {
10	tests := []struct {
11		name     string
12		domain   string
13		patterns []string
14		want     bool
15	}{
16		{name: "exact match", domain: "app.example.com", patterns: []string{"app.example.com"}, want: true},
17		{name: "no match", domain: "app.example.com", patterns: []string{"api.example.com"}, want: false},
18		{name: "wildcard match", domain: "app.example.com", patterns: []string{"*.example.com"}, want: true},
19		{name: "wildcard no match on root", domain: "example.com", patterns: []string{"*.example.com"}, want: false},
20		{name: "wildcard matches one level only", domain: "api.app.example.com", patterns: []string{"*.example.com"}, want: false},
21		{name: "empty allowlist", domain: "app.example.com", patterns: nil, want: false},
22		{name: "case insensitive", domain: "App.Example.Com", patterns: []string{"APP.EXAMPLE.COM"}, want: true},
23		{name: "multiple patterns", domain: "api.example.com", patterns: []string{"foo.com", "*.example.com"}, want: true},
24		{name: "star allows all", domain: "anything.example.com", patterns: []string{"*"}, want: true},
25		{name: "empty pattern skipped", domain: "app.example.com", patterns: []string{"", "app.example.com"}, want: true},
26		{name: "whitespace trimmed in pattern", domain: "app.example.com", patterns: []string{"  app.example.com  "}, want: true},
27	}
28
29	for _, tt := range tests {
30		t.Run(tt.name, func(t *testing.T) {
31			assert.Equal(t, tt.want, MatchesDomainAllowlist(tt.domain, tt.patterns))
32		})
33	}
34}
35
36func TestExtractRepoName(t *testing.T) {
37	tests := []struct {
38		name           string
39		imageRef       string
40		registryDomain string
41		want           string
42	}{
43		{name: "simple tag", imageRef: "myapp:latest", want: "myapp"},
44		{name: "version tag", imageRef: "myapp:v2.0.0", want: "myapp"},
45		{name: "digest", imageRef: "myapp@sha256:abc123", want: "myapp"},
46		{name: "strip registry", imageRef: "registry.example.com/myapp:latest", registryDomain: "registry.example.com", want: "myapp"},
47		{name: "org image", imageRef: "org/myapp:latest", want: "org/myapp"},
48		{name: "registry org image", imageRef: "registry.example.com/org/myapp:latest", registryDomain: "registry.example.com", want: "org/myapp"},
49		{name: "lowercase", imageRef: "MyApp:Latest", want: "myapp"},
50		{name: "no tag no digest", imageRef: "myapp", want: "myapp"},
51		{name: "empty registry domain", imageRef: "myapp:latest", registryDomain: "", want: "myapp"},
52	}
53
54	for _, tt := range tests {
55		t.Run(tt.name, func(t *testing.T) {
56			assert.Equal(t, tt.want, ExtractRepoName(tt.imageRef, tt.registryDomain))
57		})
58	}
59}
60
61func TestExtractRepoName_TreatsLegacyAndCurrentGordonRegistryHostsAsSameRepo(t *testing.T) {
62	current := "new-registry.example.com"
63	legacy := []string{"old-registry.example.com"}
64
65	oldRepo := ExtractRepoName("old-registry.example.com/app:latest", current, legacy...)
66	newRepo := ExtractRepoName("new-registry.example.com/app:latest", current, legacy...)
67
68	assert.Equal(t, "app", oldRepo)
69	assert.Equal(t, oldRepo, newRepo)
70}
71
72func TestExtractRepoName_HandlesPortsAndDigests(t *testing.T) {
73	assert.Equal(t, "org/app", ExtractRepoName("new-registry.example.com:5000/org/app:latest", "new-registry.example.com:5000"))
74	assert.Equal(t, "org/app", ExtractRepoName("old-registry.example.com:5001/org/app@sha256:deadbeef", "new-registry.example.com:5000", "old-registry.example.com:5001"))
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 7

Tags 106

↑↓ moveenter openesc close