v0.8.1 1f54f61

identity_test.go RawHistoryFolder

1package daemonidentity
2
3import (
4	"errors"
5	"os"
6	"path/filepath"
7	"testing"
8)
9
10func TestLoadOrCreateStableAndIncarnationFresh(t *testing.T) {
11	root := t.TempDir()
12	first, err := LoadOrCreate(root)
13	if err != nil {
14		t.Fatal(err)
15	}
16	second, err := LoadOrCreate(root)
17	if err != nil {
18		t.Fatal(err)
19	}
20	if first != second {
21		t.Fatalf("identity changed: %q != %q", first, second)
22	}
23	a, err := NewIncarnation()
24	if err != nil {
25		t.Fatal(err)
26	}
27	b, err := NewIncarnation()
28	if err != nil {
29		t.Fatal(err)
30	}
31	if a.IsZero() || b.IsZero() || a == b {
32		t.Fatalf("incarnations not fresh: %x %x", a, b)
33	}
34}
35
36func TestLoadFailsClosed(t *testing.T) {
37	for _, tc := range []struct {
38		name    string
39		prepare func(string) error
40	}{
41		{"corrupt", func(root string) error {
42			if err := os.Mkdir(filepath.Dir(Path(root)), 0o700); err != nil {
43				return err
44			}
45			return os.WriteFile(Path(root), []byte("bad"), 0o600)
46		}},
47		{"permissions", func(root string) error {
48			if err := os.Mkdir(filepath.Dir(Path(root)), 0o700); err != nil {
49				return err
50			}
51			return os.WriteFile(Path(root), []byte("00112233445566778899aabbccddeeff"), 0o644)
52		}},
53		{"symlink", func(root string) error {
54			if err := os.Mkdir(filepath.Dir(Path(root)), 0o700); err != nil {
55				return err
56			}
57			target := filepath.Join(root, "target")
58			if err := os.WriteFile(target, []byte("00112233445566778899aabbccddeeff"), 0o600); err != nil {
59				return err
60			}
61			return os.Symlink(target, Path(root))
62		}},
63	} {
64		t.Run(tc.name, func(t *testing.T) {
65			root := t.TempDir()
66			if err := tc.prepare(root); err != nil {
67				t.Fatal(err)
68			}
69			if _, err := Load(root); !errors.Is(err, ErrInvalid) {
70				t.Fatalf("error=%v, want ErrInvalid", err)
71			}
72		})
73	}
74}
75
76func TestLoadAbsentDoesNotCreate(t *testing.T) {
77	root := filepath.Join(t.TempDir(), "absent")
78	if _, err := Load(root); !errors.Is(err, os.ErrNotExist) {
79		t.Fatalf("error=%v", err)
80	}
81	if _, err := os.Stat(root); !errors.Is(err, os.ErrNotExist) {
82		t.Fatalf("read created state: %v", err)
83	}
84}

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 12

Tags 11

↑↓ moveenter openesc close