Files
core/config/nohome_test.go
terminarandClaude Opus 5.5 e8bf23a064 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>
2026-09-22 22:24:51 +02:00

43 lines
1.3 KiB
Go

package config
import (
"path/filepath"
"testing"
"yetano.dev/yetano/core/paths"
)
// A process without HOME (e.g. a system service) still finds its
// working-directory and system config; only the user tier is skipped.
func TestResolveWithoutHome(t *testing.T) {
root := t.TempDir()
workdir := filepath.Join(root, "work")
newResolver := func() *Resolver {
return mustResolver(t, yetApp(),
WithEnvironment(map[string]string{}),
WithWorkdirPath(workdir),
WithPathsOptions(paths.WithPlatform("linux"), paths.WithRoot(root)))
}
if _, found, err := newResolver().Resolve(); err != nil || found {
t.Fatalf("Resolve() on empty tree = found=%v err=%v, want found=false err=nil", found, err)
}
system := filepath.Join(root, "etc", "yet", "yet.yaml")
writeFile(t, system, "system: true\n")
layer, found, err := newResolver().Resolve()
if err != nil || !found {
t.Fatalf("Resolve() = found=%v err=%v, want the system file", found, err)
}
if layer.Path != system {
t.Errorf("Resolve() path = %q, want %q", layer.Path, system)
}
cwd := filepath.Join(workdir, "yet.yaml")
writeFile(t, cwd, "cwd: true\n")
layer, found, err = newResolver().Resolve()
if err != nil || !found || layer.Path != cwd {
t.Fatalf("Resolve() = %q found=%v err=%v, want %q", layer.Path, found, err, cwd)
}
}