v2.15.0 cf76057

push_test.go RawHistoryFolder

1package cli
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7)
8
9func TestValidateBuildArg(t *testing.T) {
10	tests := []struct {
11		name    string
12		arg     string
13		wantErr bool
14	}{
15		{"valid simple", "FOO=bar", false},
16		{"valid with underscore key", "_FOO=bar", false},
17		{"valid with numbers in key", "FOO123=bar", false},
18		{"valid empty value", "FOO=", false},
19		{"valid complex value", "FOO=bar baz=qux", false},
20		{"invalid no equals", "FOO", true},
21		{"invalid starts with number", "1FOO=bar", true},
22		{"invalid starts with dash", "-FOO=bar", true},
23		{"invalid special chars in key", "FOO-BAR=baz", true},
24		{"invalid empty string", "", true},
25		{"invalid equals only", "=value", true},
26	}
27
28	for _, tt := range tests {
29		t.Run(tt.name, func(t *testing.T) {
30			err := validateBuildArg(tt.arg)
31			if tt.wantErr {
32				assert.Error(t, err)
33			} else {
34				assert.NoError(t, err)
35			}
36		})
37	}
38}
39
40func TestParseImageRef(t *testing.T) {
41	tests := []struct {
42		name         string
43		image        string
44		wantRegistry string
45		wantName     string
46		wantTag      string
47	}{
48		{"full ref", "reg.example.com/myapp:v1.0.0", "reg.example.com", "myapp", "v1.0.0"},
49		{"no tag", "reg.example.com/myapp", "reg.example.com", "myapp", "latest"},
50		{"latest tag", "reg.example.com/myapp:latest", "reg.example.com", "myapp", "latest"},
51		{"no slash", "myapp:v1.0.0", "", "", ""},
52	}
53
54	for _, tt := range tests {
55		t.Run(tt.name, func(t *testing.T) {
56			registry, name, tag := parseImageRef(tt.image)
57			assert.Equal(t, tt.wantRegistry, registry)
58			assert.Equal(t, tt.wantName, name)
59			assert.Equal(t, tt.wantTag, tag)
60		})
61	}
62}
63
64func TestBuildAndPush_BuildArgs(t *testing.T) {
65	// Verify buildImageArgs produces --load instead of --push
66	args := buildImageArgs("v1.0.0", "linux/amd64", "Dockerfile", []string{"CGO_ENABLED=0"}, "reg.example.com/app:v1.0.0", "reg.example.com/app:latest")
67
68	assert.Contains(t, args, "--load")
69	assert.NotContains(t, args, "--push")
70	assert.Contains(t, args, "--platform")
71	assert.Contains(t, args, "-f")
72	assert.Contains(t, args, "Dockerfile")
73}
74
75func TestBuildImageArgs_CustomDockerfile(t *testing.T) {
76	args := buildImageArgs("v1.0.0", "linux/amd64", "docker/app/Dockerfile", nil, "reg.example.com/app:v1.0.0", "reg.example.com/app:latest")
77
78	assert.Contains(t, args, "-f")
79	assert.Contains(t, args, "docker/app/Dockerfile")
80}

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