42 lines
1.3 KiB
Go
42 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)
|
||
|
|
}
|
||
|
|
}
|