v0.36.0 1fb2421

cli_binary_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package app
4
5import (
6	"bytes"
7	"errors"
8	"os/exec"
9	"testing"
10
11	"github.com/stretchr/testify/assert"
12	"github.com/stretchr/testify/require"
13
14	"bnema.dev/ermite-api/gen/ermite"
15)
16
17// runBinary runs the built ermite with only the given variables.
18func runBinary(t *testing.T, vars []string, args ...string) (stdout, stderr string, code int) {
19	t.Helper()
20	cmd := exec.Command(binary(t), args...)
21	cmd.Env = append(baseEnv(), vars...)
22	var out, errb bytes.Buffer
23	cmd.Stdout, cmd.Stderr = &out, &errb
24	err := cmd.Run()
25	var exit *exec.ExitError
26	if errors.As(err, &exit) {
27		code = exit.ExitCode()
28	} else {
29		require.NoError(t, err)
30	}
31	return out.String(), errb.String(), code
32}
33
34func TestBinaryRemoteCommandErrorIsOneLineAndExitsOne(t *testing.T) {
35	_, stderr, code := runBinary(t, nil, "repo", "list")
36	assert.Equal(t, 1, code)
37	assert.Regexp(t, `^ermite: ERMITE_URL is not set[^\n]*\n$`, stderr)
38}
39
40func TestBinaryAgainstStubServer(t *testing.T) {
41	f := &fakeAPI{listRepos: func(*ermite.ListReposRequest) (*ermite.ListReposResponse, error) {
42		return &ermite.ListReposResponse{Repos: []*ermite.Repo{repoAlpha}}, nil
43	}}
44	url := f.serve(t)
45	stdout, stderr, code := runBinary(t, []string{"ERMITE_URL=" + url, "ERMITE_TOKEN=ermite_t"}, "repo", "list", "--json")
46	assert.Equal(t, 0, code, stderr)
47	assert.Contains(t, stdout, `"name": "alpha"`)
48	assert.Contains(t, f.header[0].Get("User-Agent"), "ermite/")
49	assert.Contains(t, f.header[0].Get("User-Agent"), "(cli)")
50
51	_, stderr, code = runBinary(t, []string{"ERMITE_URL=" + url}, "repo", "delete", "alpha")
52	assert.Equal(t, 1, code)
53	assert.Contains(t, stderr, "ermite: aborted")
54}

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 4

Tags 45

↑↓ moveenter openesc close