run_internal_creds_test.go RawHistoryFolder

1package app
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7)
8
9func TestGetInternalCredentialsFindsRuntimeFile(t *testing.T) {
10	// Simulate daemon writing to XDG_RUNTIME_DIR/gordon/ while
11	// CLI has no XDG_RUNTIME_DIR set.
12	tmpRuntime := t.TempDir()
13	gordonRuntime := filepath.Join(tmpRuntime, "gordon")
14	if err := os.MkdirAll(gordonRuntime, 0700); err != nil {
15		t.Fatal(err)
16	}
17
18	// Write "live" creds to the runtime dir (as daemon would)
19	liveCreds := `{"username":"gordon-internal","password":"livepassword"}`
20	if err := os.WriteFile(filepath.Join(gordonRuntime, "internal-creds.json"), []byte(liveCreds), 0600); err != nil {
21		t.Fatal(err)
22	}
23
24	// Also write a stale creds file to home fallback
25	tmpHome := t.TempDir()
26	gordonHome := filepath.Join(tmpHome, ".gordon", "run")
27	if err := os.MkdirAll(gordonHome, 0700); err != nil {
28		t.Fatal(err)
29	}
30	staleCreds := `{"username":"gordon-internal","password":"stalepassword"}`
31	if err := os.WriteFile(filepath.Join(gordonHome, "internal-creds.json"), []byte(staleCreds), 0600); err != nil {
32		t.Fatal(err)
33	}
34
35	creds, err := GetInternalCredentialsFromCandidates([]string{
36		filepath.Join(gordonRuntime, "internal-creds.json"),
37		filepath.Join(gordonHome, "internal-creds.json"),
38	})
39	if err != nil {
40		t.Fatalf("unexpected error: %v", err)
41	}
42	if creds.Password != "livepassword" {
43		t.Errorf("got password %q, want %q", creds.Password, "livepassword")
44	}
45}
46
47func TestGetInternalCredentialsFallsBackToStale(t *testing.T) {
48	// If only the stale/home file exists, it should still work
49	tmpHome := t.TempDir()
50	gordonHome := filepath.Join(tmpHome, ".gordon", "run")
51	if err := os.MkdirAll(gordonHome, 0700); err != nil {
52		t.Fatal(err)
53	}
54	staleCreds := `{"username":"gordon-internal","password":"stalepassword"}`
55	if err := os.WriteFile(filepath.Join(gordonHome, "internal-creds.json"), []byte(staleCreds), 0600); err != nil {
56		t.Fatal(err)
57	}
58
59	creds, err := GetInternalCredentialsFromCandidates([]string{
60		filepath.Join(t.TempDir(), "gordon", "internal-creds.json"), // doesn't exist
61		filepath.Join(gordonHome, "internal-creds.json"),
62	})
63	if err != nil {
64		t.Fatalf("unexpected error: %v", err)
65	}
66	if creds.Password != "stalepassword" {
67		t.Errorf("got password %q, want %q", creds.Password, "stalepassword")
68	}
69}
70
71func TestGetInternalCredentialsNoCandidatesReturnsError(t *testing.T) {
72	_, err := GetInternalCredentialsFromCandidates([]string{
73		filepath.Join(t.TempDir(), "nonexistent", "internal-creds.json"),
74	})
75	if err == nil {
76		t.Fatal("expected error when no credentials found, got nil")
77	}
78}

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