detached e7b3a25

fsys_test.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package fsys
4
5import (
6	"errors"
7	"io"
8	"os"
9	"path/filepath"
10	"testing"
11)
12
13func TestOS(t *testing.T) {
14	fx := OS()
15	dir := filepath.Join(t.TempDir(), "a", "b")
16	if err := fx.MkdirAll(dir, 0o700); err != nil {
17		t.Fatal(err)
18	}
19	if err := fx.SyncDir(dir); err != nil {
20		t.Fatal(err)
21	}
22	name := filepath.Join(dir, "f.tmp")
23	f, err := fx.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
24	if err != nil {
25		t.Fatal(err)
26	}
27	for _, s := range []string{"hello ", "world"} {
28		if _, err := f.Write([]byte(s)); err != nil {
29			t.Fatal(err)
30		}
31	}
32	if err := f.Sync(); err != nil {
33		t.Fatal(err)
34	}
35	if err := f.SyncAll(); err != nil {
36		t.Fatal(err)
37	}
38	if err := f.Truncate(8); err != nil {
39		t.Fatal(err)
40	}
41	if _, err := f.Write([]byte("!")); err != nil { // appends after truncation
42		t.Fatal(err)
43	}
44	if sz, err := f.Size(); err != nil || sz != 9 {
45		t.Fatalf("Size = %d, %v", sz, err)
46	}
47	buf := make([]byte, 9)
48	if n, err := f.ReadAt(buf, 0); n != 9 || (err != nil && !errors.Is(err, io.EOF)) || string(buf) != "hello wo!" {
49		t.Fatalf("ReadAt = %d %v %q", n, err, buf)
50	}
51	if err := f.Close(); err != nil {
52		t.Fatal(err)
53	}
54
55	final := filepath.Join(dir, "f")
56	if err := fx.Rename(name, final); err != nil {
57		t.Fatal(err)
58	}
59	names, err := fx.ReadDir(dir)
60	if err != nil || len(names) != 1 || names[0] != "f" {
61		t.Fatalf("ReadDir = %v, %v", names, err)
62	}
63	if err := fx.Remove(final); err != nil {
64		t.Fatal(err)
65	}
66}
67
68func TestOSLock(t *testing.T) {
69	fx := OS()
70	path := filepath.Join(t.TempDir(), "LOCK")
71	l, err := fx.Lock(path)
72	if err != nil {
73		t.Fatal(err)
74	}
75	if _, err := fx.Lock(path); !errors.Is(err, ErrLocked) {
76		t.Fatalf("second lock: %v", err)
77	}
78	if err := l.Close(); err != nil {
79		t.Fatal(err)
80	}
81	l, err = fx.Lock(path)
82	if err != nil {
83		t.Fatalf("lock after release: %v", err)
84	}
85	_ = l.Close()
86}

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 1

Tags 2

↑↓ moveenter openesc close