ui_adoption_test.go RawHistoryFolder

1package cli
2
3import (
4	"bytes"
5	"context"
6	"io"
7	"sync"
8	"testing"
9
10	"github.com/stretchr/testify/mock"
11
12	"github.com/bnema/gordon/internal/adapters/dto"
13	climocks "github.com/bnema/gordon/internal/adapters/in/cli/mocks"
14)
15
16// uiAdoptionSeamMu guards mutations of the package-level cliWriteLine and
17// cliWritef variables. Any test that overrides these seams must hold this
18// mutex for the duration of the override and restore the originals on cleanup.
19var uiAdoptionSeamMu sync.Mutex
20
21func TestPresentationHelpers(t *testing.T) {
22	if got := cliRenderTitle("Title"); got == "" {
23		t.Fatal("cliRenderTitle returned empty output")
24	}
25	if got := cliRenderEmptyState("none"); got == "" {
26		t.Fatal("cliRenderEmptyState returned empty output")
27	}
28	if got := cliRenderSuccess("ok"); got == "" {
29		t.Fatal("cliRenderSuccess returned empty output")
30	}
31	if got := cliRenderWarning("warn"); got == "" {
32		t.Fatal("cliRenderWarning returned empty output")
33	}
34	if got := cliRenderInfo("info"); got == "" {
35		t.Fatal("cliRenderInfo returned empty output")
36	}
37	if got := cliRenderListItem("item"); got == "" {
38		t.Fatal("cliRenderListItem returned empty output")
39	}
40}
41
42func TestUIAdoptionRuntimeSeams(t *testing.T) {
43	uiAdoptionSeamMu.Lock()
44	defer uiAdoptionSeamMu.Unlock()
45
46	origWriteLine := cliWriteLine
47	origWritef := cliWritef
48	defer func() {
49		cliWriteLine = origWriteLine
50		cliWritef = origWritef
51	}()
52
53	lineCalls := 0
54	writefCalls := 0
55	cliWriteLine = func(w io.Writer, msg string) error {
56		lineCalls++
57		_, err := io.WriteString(w, msg+"\n")
58		return err
59	}
60	cliWritef = func(w io.Writer, format string, args ...any) error {
61		writefCalls++
62		_, err := io.WriteString(w, "formatted\n")
63		return err
64	}
65
66	versionCmd := newVersionCmd()
67	versionCmd.SetArgs(nil)
68	versionCmd.SetOut(new(bytes.Buffer))
69	if err := versionCmd.Execute(); err != nil {
70		t.Fatalf("version command execution failed: %v", err)
71	}
72
73	imagesMock := climocks.NewMockimagesClient(t)
74	imagesMock.EXPECT().ListImages(context.Background()).Return([]dto.Image{{Repository: "repo/app", Tag: "latest", ID: "sha256:abc", Size: 1}}, nil).Once()
75
76	imgBuf := new(bytes.Buffer)
77	if err := runImagesList(context.Background(), imagesMock, imgBuf, false); err != nil {
78		t.Fatalf("runImagesList failed: %v", err)
79	}
80
81	pruneMock := climocks.NewMockimagesClient(t)
82	pruneMock.EXPECT().PruneImages(context.Background(), mock.Anything).Return(&dto.ImagePruneResponse{Plan: dto.PruneSummary{}}, nil).Once()
83
84	pruneBuf := new(bytes.Buffer)
85	if err := runImagesPrune(context.Background(), pruneMock, imagesPruneOptions{DryRun: true}, pruneBuf); err != nil {
86		t.Fatalf("runImagesPrune failed: %v", err)
87	}
88
89	if lineCalls == 0 {
90		t.Fatal("expected cliWriteLine to be called")
91	}
92	if writefCalls == 0 {
93		t.Fatal("expected cliWritef to be called")
94	}
95}

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