fix(tests) use os.Getpid in PID test and add missing test cases
- commit
- 83f9eba716f46924f1ac718c5912457b9f78ef17
- author
- bnema · · 2026-02-06 20:43 UTC
- parent
- 726a7cb
- signature
- unsigned
4 files · +38 -12
M internal/adapters/in/cli/local_test.go +25 -0
| @@ -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 | 66 | func TestCreateLocalDomainSecretStore_UsesFileStoreForUnsafe(t *testing.T) { | |
| 42 | 67 | v := viper.New() | |
| 43 | 68 | 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) { | |||
| 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 | 68 | func TestResolveInsecureTLSForRemote_EnvAndFlagPrecedence(t *testing.T) { | |
| 60 | 69 | t.Setenv("XDG_CONFIG_HOME", t.TempDir()) | |
| 61 | 70 | 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) { | |||
| 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 | 1344 | func pidFileLocations() []string { | |
| 1355 | 1345 | var locations []string | |
| 1356 | 1346 | 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 []string | 1345 | 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 | |||
| 3 | 3 | import ( | |
| 4 | 4 | "os" | |
| 5 | 5 | "path/filepath" | |
| 6 | + | "strconv" | |
| 6 | 7 | "testing" | |
| 7 | 8 | ||
| 8 | 9 | "github.com/stretchr/testify/assert" | |
| @@ -15,12 +16,13 @@ func TestFindRunningPidFileInLocations_PrefersLiveProcessOverStale(t *testing.T) | |||
| 15 | 16 | liveFile := filepath.Join(tmpDir, "live.pid") | |
| 16 | 17 | ||
| 17 | 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 | 22 | path, pid, err := findRunningPidFileInLocations([]string{staleFile, liveFile}) | |
| 21 | 23 | require.NoError(t, err) | |
| 22 | 24 | assert.Equal(t, liveFile, path) | |
| 23 | - | assert.Equal(t, 1, pid) | |
| 25 | + | assert.Equal(t, myPid, pid) | |
| 24 | 26 | ||
| 25 | 27 | _, statErr := os.Stat(staleFile) | |
| 26 | 28 | 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)) | ||