detached e8e1134

fix(tests) use os.Getpid in PID test and add missing test cases

commit
e8e113414d63d7b4f4bc577face94f6d3b6169da
author
bnema · · 2026-02-06 20:43 UTC
parent
48b313f
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
4 files · +38 -12
M internal/adapters/in/cli/local_test.go +25 -0
@@ -38,6 +38,31 @@ func TestResolveLocalSecretsBackend(t *testing.T) {
3838 })
3939 }
4040
41+func TestCreateLocalDomainSecretStore_UsesPassStoreForPass(t *testing.T) {
42+ // pass(1) must be available on the system for this test
43+ if _, err := domainsecrets.NewPassStore(zerowrap.New(zerowrap.Config{Level: "error", Format: "console"})); err != nil {
44+ t.Skipf("pass store not available: %v", err)
45+ }
46+
47+ v := viper.New()
48+ v.Set("auth.secrets_backend", "pass")
49+
50+ log := zerowrap.New(zerowrap.Config{Level: "error", Format: "console"})
51+ store, err := createLocalDomainSecretStore(v, t.TempDir(), log)
52+ require.NoError(t, err)
53+ require.IsType(t, &domainsecrets.PassStore{}, store)
54+}
55+
56+func TestCreateLocalDomainSecretStore_RejectsSopsBackend(t *testing.T) {
57+ v := viper.New()
58+ v.Set("auth.secrets_backend", "sops")
59+
60+ log := zerowrap.New(zerowrap.Config{Level: "error", Format: "console"})
61+ _, err := createLocalDomainSecretStore(v, t.TempDir(), log)
62+ require.Error(t, err)
63+ require.Contains(t, err.Error(), "sops backend not yet supported")
64+}
65+
4166 func TestCreateLocalDomainSecretStore_UsesFileStoreForUnsafe(t *testing.T) {
4267 v := viper.New()
4368 v.Set("auth.secrets_backend", "unsafe")
@@ -38,6 +38,31 @@ func TestResolveLocalSecretsBackend(t *testing.T) {
38 })38 })
39 }39 }
40 40
41+func TestCreateLocalDomainSecretStore_UsesPassStoreForPass(t *testing.T) {
42+ // pass(1) must be available on the system for this test
43+ if _, err := domainsecrets.NewPassStore(zerowrap.New(zerowrap.Config{Level: "error", Format: "console"})); err != nil {
44+ t.Skipf("pass store not available: %v", err)
45+ }
46+
47+ v := viper.New()
48+ v.Set("auth.secrets_backend", "pass")
49+
50+ log := zerowrap.New(zerowrap.Config{Level: "error", Format: "console"})
51+ store, err := createLocalDomainSecretStore(v, t.TempDir(), log)
52+ require.NoError(t, err)
53+ require.IsType(t, &domainsecrets.PassStore{}, store)
54+}
55+
56+func TestCreateLocalDomainSecretStore_RejectsSopsBackend(t *testing.T) {
57+ v := viper.New()
58+ v.Set("auth.secrets_backend", "sops")
59+
60+ log := zerowrap.New(zerowrap.Config{Level: "error", Format: "console"})
61+ _, err := createLocalDomainSecretStore(v, t.TempDir(), log)
62+ require.Error(t, err)
63+ require.Contains(t, err.Error(), "sops backend not yet supported")
64+}
65+
41 func TestCreateLocalDomainSecretStore_UsesFileStoreForUnsafe(t *testing.T) {66 func TestCreateLocalDomainSecretStore_UsesFileStoreForUnsafe(t *testing.T) {
42 v := viper.New()67 v := viper.New()
43 v.Set("auth.secrets_backend", "unsafe")68 v.Set("auth.secrets_backend", "unsafe")
M internal/adapters/in/cli/remote/config_test.go +9 -0
@@ -56,6 +56,15 @@ func TestResolveInsecureTLSForRemote_FromRemoteEntry(t *testing.T) {
5656 }
5757 }
5858
59+func TestResolveInsecureTLSForRemote_DefaultSecure(t *testing.T) {
60+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())
61+
62+ // With no flag, no env, and no config, TLS should be secure by default
63+ if ResolveInsecureTLSForRemote(false, "") {
64+ t.Fatalf("expected insecure TLS false by default")
65+ }
66+}
67+
5968 func TestResolveInsecureTLSForRemote_EnvAndFlagPrecedence(t *testing.T) {
6069 t.Setenv("XDG_CONFIG_HOME", t.TempDir())
6170 t.Setenv("GORDON_INSECURE", "true")
@@ -56,6 +56,15 @@ func TestResolveInsecureTLSForRemote_FromRemoteEntry(t *testing.T) {
56 }56 }
57 }57 }
58 58
59+func TestResolveInsecureTLSForRemote_DefaultSecure(t *testing.T) {
60+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())
61+
62+ // With no flag, no env, and no config, TLS should be secure by default
63+ if ResolveInsecureTLSForRemote(false, "") {
64+ t.Fatalf("expected insecure TLS false by default")
65+ }
66+}
67+
59 func TestResolveInsecureTLSForRemote_EnvAndFlagPrecedence(t *testing.T) {68 func TestResolveInsecureTLSForRemote_EnvAndFlagPrecedence(t *testing.T) {
60 t.Setenv("XDG_CONFIG_HOME", t.TempDir())69 t.Setenv("XDG_CONFIG_HOME", t.TempDir())
61 t.Setenv("GORDON_INSECURE", "true")70 t.Setenv("GORDON_INSECURE", "true")
M internal/app/run.go +0 -10
@@ -1341,16 +1341,6 @@ func removePidFile(pidFile string, log zerowrap.Logger) {
13411341 }
13421342 }
13431343
1344-// findPidFile finds the Gordon PID file.
1345-// Checks secure locations first, then falls back to legacy /tmp location.
1346-func findPidFile() string {
1347- location, _, err := findRunningPidFile()
1348- if err != nil {
1349- return ""
1350- }
1351- return location
1352-}
1353-
13541344 func pidFileLocations() []string {
13551345 var locations []string
13561346 seen := make(map[string]struct{})
@@ -1341,16 +1341,6 @@ func removePidFile(pidFile string, log zerowrap.Logger) {
1341 }1341 }
1342 }1342 }
1343 1343
1344-// findPidFile finds the Gordon PID file.
1345-// Checks secure locations first, then falls back to legacy /tmp location.
1346-func findPidFile() string {
1347- location, _, err := findRunningPidFile()
1348- if err != nil {
1349- return ""
1350- }
1351- return location
1352-}
1353-
1354 func pidFileLocations() []string {1344 func pidFileLocations() []string {
1355 var locations []string1345 var locations []string
1356 seen := make(map[string]struct{})1346 seen := make(map[string]struct{})
M internal/app/run_pid_test.go +4 -2
@@ -3,6 +3,7 @@ package app
33 import (
44 "os"
55 "path/filepath"
6+ "strconv"
67 "testing"
78
89 "github.com/stretchr/testify/assert"
@@ -15,12 +16,13 @@ func TestFindRunningPidFileInLocations_PrefersLiveProcessOverStale(t *testing.T)
1516 liveFile := filepath.Join(tmpDir, "live.pid")
1617
1718 require.NoError(t, os.WriteFile(staleFile, []byte("999999"), 0600))
18- require.NoError(t, os.WriteFile(liveFile, []byte("1"), 0600))
19+ myPid := os.Getpid()
20+ require.NoError(t, os.WriteFile(liveFile, []byte(strconv.Itoa(myPid)), 0600))
1921
2022 path, pid, err := findRunningPidFileInLocations([]string{staleFile, liveFile})
2123 require.NoError(t, err)
2224 assert.Equal(t, liveFile, path)
23- assert.Equal(t, 1, pid)
25+ assert.Equal(t, myPid, pid)
2426
2527 _, statErr := os.Stat(staleFile)
2628 assert.True(t, os.IsNotExist(statErr))
@@ -3,6 +3,7 @@ package app
3 import (3 import (
4 "os"4 "os"
5 "path/filepath"5 "path/filepath"
6+ "strconv"
6 "testing"7 "testing"
7 8
8 "github.com/stretchr/testify/assert"9 "github.com/stretchr/testify/assert"
@@ -15,12 +16,13 @@ func TestFindRunningPidFileInLocations_PrefersLiveProcessOverStale(t *testing.T)
15 liveFile := filepath.Join(tmpDir, "live.pid")16 liveFile := filepath.Join(tmpDir, "live.pid")
16 17
17 require.NoError(t, os.WriteFile(staleFile, []byte("999999"), 0600))18 require.NoError(t, os.WriteFile(staleFile, []byte("999999"), 0600))
18- require.NoError(t, os.WriteFile(liveFile, []byte("1"), 0600))19+ myPid := os.Getpid()
20+ require.NoError(t, os.WriteFile(liveFile, []byte(strconv.Itoa(myPid)), 0600))
19 21
20 path, pid, err := findRunningPidFileInLocations([]string{staleFile, liveFile})22 path, pid, err := findRunningPidFileInLocations([]string{staleFile, liveFile})
21 require.NoError(t, err)23 require.NoError(t, err)
22 assert.Equal(t, liveFile, path)24 assert.Equal(t, liveFile, path)
23- assert.Equal(t, 1, pid)25+ assert.Equal(t, myPid, pid)
24 26
25 _, statErr := os.Stat(staleFile)27 _, statErr := os.Stat(staleFile)
26 assert.True(t, os.IsNotExist(statErr))28 assert.True(t, os.IsNotExist(statErr))

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 8

Tags 106

↑↓ moveenter openesc close