main bac21c6

image_test.go RawHistoryFolder

1package validation
2
3import (
4	"strings"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8	"github.com/stretchr/testify/require"
9)
10
11func TestValidateImageDigest(t *testing.T) {
12	validLower := "sha256:" + strings.Repeat("a", 64)
13	require.NoError(t, ValidateImageDigest(validLower))
14
15	for _, digest := range []string{
16		"sha256:" + strings.Repeat("A", 64),
17		"",
18		"sha256:" + strings.Repeat("a", 63),
19		"sha256:" + strings.Repeat("a", 65),
20		"sha256:" + strings.Repeat("g", 64),
21		"sha512:" + strings.Repeat("a", 64),
22	} {
23		assert.Error(t, ValidateImageDigest(digest), digest)
24	}
25}
26
27func TestParseImageReference(t *testing.T) {
28	tests := []struct {
29		name     string
30		imageRef string
31		wantName string
32		wantRef  string
33	}{
34		{
35			name:     "simple image with latest tag",
36			imageRef: "myapp:latest",
37			wantName: "myapp",
38			wantRef:  "latest",
39		},
40		{
41			name:     "simple image with custom tag",
42			imageRef: "myapp:v1.0.0",
43			wantName: "myapp",
44			wantRef:  "v1.0.0",
45		},
46		{
47			name:     "simple image with digest",
48			imageRef: "myapp@sha256:abc123def456",
49			wantName: "myapp",
50			wantRef:  "sha256:abc123def456",
51		},
52		{
53			name:     "registry with image and tag",
54			imageRef: "registry.example.com/myapp:latest",
55			wantName: "registry.example.com/myapp",
56			wantRef:  "latest",
57		},
58		{
59			name:     "registry with port and image and tag",
60			imageRef: "registry.example.com:5000/myapp:v1.0",
61			wantName: "registry.example.com:5000/myapp",
62			wantRef:  "v1.0",
63		},
64		{
65			name:     "registry with port, image, and digest",
66			imageRef: "registry.example.com:5000/myapp@sha256:abc123",
67			wantName: "registry.example.com:5000/myapp",
68			wantRef:  "sha256:abc123",
69		},
70		{
71			name:     "simple image without tag (defaults to latest)",
72			imageRef: "myapp",
73			wantName: "myapp",
74			wantRef:  "latest",
75		},
76		{
77			name:     "registry with image without tag",
78			imageRef: "registry.example.com/myapp",
79			wantName: "registry.example.com/myapp",
80			wantRef:  "latest",
81		},
82		{
83			name:     "nested path image with tag",
84			imageRef: "registry.example.com/path/to/myapp:latest",
85			wantName: "registry.example.com/path/to/myapp",
86			wantRef:  "latest",
87		},
88		{
89			name:     "localhost registry with port",
90			imageRef: "localhost:5000/myapp:latest",
91			wantName: "localhost:5000/myapp",
92			wantRef:  "latest",
93		},
94		{
95			name:     "IP address registry with port",
96			imageRef: "192.168.1.100:5000/myapp:latest",
97			wantName: "192.168.1.100:5000/myapp",
98			wantRef:  "latest",
99		},
100	}
101
102	for _, tt := range tests {
103		t.Run(tt.name, func(t *testing.T) {
104			gotName, gotRef := ParseImageReference(tt.imageRef)
105			assert.Equal(t, tt.wantName, gotName, "name mismatch")
106			assert.Equal(t, tt.wantRef, gotRef, "reference mismatch")
107		})
108	}
109}

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