paths: skip the user search tier when there is no home directory
ConfigSearchDirs/DataSearchDirs/ExecutableSearchDirs (and therefore core/config's Resolve/ResolveAll/LoadMerged) failed outright with ErrNoHomeDirectory when HOME/USERPROFILE was unset, so a service started without HOME could no longer find its working-directory or /etc/<app> config -- a regression against the hand-rolled lookups being migrated onto core, which just skipped the user location. Missing-home now only drops the user tier from the search lists; the canonical <Category>Dir() methods still report ErrNoHomeDirectory. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
72b656262d
commit
e8bf23a064
7 files changed
+220
-57
No files matched your search
@@ -0,0 +1,72 @@
|
||||
package paths
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"yetano.dev/yetano/core"
|
||||
)
|
||||
|
||||
// Without a home directory, the search-dir builders drop only the user
|
||||
// tier; the system tier stays searchable, while the canonical *Dir()
|
||||
// methods keep reporting ErrNoHomeDirectory.
|
||||
func TestSearchDirsWithoutHome(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
platform string
|
||||
app core.Application
|
||||
search func(*Resolver) ([]SearchResult, error)
|
||||
want []string
|
||||
}{
|
||||
{"linux config", "linux", yetApp(), (*Resolver).ConfigSearchDirs, []string{"/etc/yet"}},
|
||||
{"freebsd config", "freebsd", yetApp(), (*Resolver).ConfigSearchDirs, []string{"/usr/local/etc/yet"}},
|
||||
{"linux data", "linux", yetApp(), (*Resolver).DataSearchDirs, []string{"/usr/local/share/yet", "/usr/share/yet"}},
|
||||
{"linux bin", "linux", yetApp(), (*Resolver).ExecutableSearchDirs, []string{"/usr/local/bin"}},
|
||||
{"darwin desktop config", "darwin", core.Application{Name: "Yet", Kind: core.Desktop}, (*Resolver).ConfigSearchDirs, []string{"/Library/Application Support/Yet"}},
|
||||
{"windows config", "windows", yetApp(), (*Resolver).ConfigSearchDirs, []string{`C:\ProgramData\yet`}},
|
||||
{"windows data", "windows", yetApp(), (*Resolver).DataSearchDirs, []string{`C:\ProgramData\yet`}},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
r := mustResolver(t, tc.app, WithPlatform(tc.platform), WithEnvironment(map[string]string{}))
|
||||
dirs, err := tc.search(r)
|
||||
if err != nil {
|
||||
t.Fatalf("search dirs: %v", err)
|
||||
}
|
||||
var got []string
|
||||
for _, d := range dirs {
|
||||
got = append(got, d.Path)
|
||||
}
|
||||
if len(got) != len(tc.want) {
|
||||
t.Fatalf("search dirs = %v, want %v", got, tc.want)
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != tc.want[i] {
|
||||
t.Fatalf("search dirs = %v, want %v", got, tc.want)
|
||||
}
|
||||
}
|
||||
if _, err := r.ConfigDir(); err != ErrNoHomeDirectory {
|
||||
t.Errorf("ConfigDir() error = %v, want ErrNoHomeDirectory", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A partially available Windows user tier (APPDATA set, LOCALAPPDATA and
|
||||
// USERPROFILE unset) keeps the layers it can resolve.
|
||||
func TestWindowsConfigSearchPartialUserTier(t *testing.T) {
|
||||
r := mustResolver(t, yetApp(), WithPlatform("windows"),
|
||||
WithEnvironment(map[string]string{"APPDATA": `C:\Users\t\AppData\Roaming`}))
|
||||
dirs, err := r.ConfigSearchDirs()
|
||||
if err != nil {
|
||||
t.Fatalf("ConfigSearchDirs: %v", err)
|
||||
}
|
||||
want := []string{`C:\Users\t\AppData\Roaming\yet`, `C:\ProgramData\yet`}
|
||||
if len(dirs) != len(want) {
|
||||
t.Fatalf("ConfigSearchDirs = %v, want %v", dirs, want)
|
||||
}
|
||||
for i, d := range dirs {
|
||||
if d.Path != want[i] {
|
||||
t.Fatalf("ConfigSearchDirs[%d] = %q, want %q", i, d.Path, want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user