Add platform-independent path/config resolution library
Implements core/paths (Config/Data/State/Cache/Runtime/Log/Bin
directory resolution with canonical-vs-search-dir separation, XDG on
Unix, native APPDATA/LOCALAPPDATA/PROGRAMDATA layering on Windows,
~/Library on macOS Desktop, injectable environment/platform for
deterministic cross-platform tests) and core/config (file search,
first-match resolution, layered YAML merging, safe ${VAR} expansion,
Explain/doctor introspection) on top of the shared Application/
Kind/Scope model in the core package.
This commit is contained in:
1 parent
027b327c3d
commit
13801bec11
41 files changed
+4834
-2
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"yetano.dev/yetano/core/paths"
|
||||
)
|
||||
|
||||
func TestConfigExplain(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeFile(t, filepath.Join(root, "home", "test", ".config", "yet", "yet.yaml"), "port: 8080\n")
|
||||
env := map[string]string{"HOME": "/home/test"}
|
||||
r := mustResolver(t, yetApp(),
|
||||
WithEnvironment(env),
|
||||
WithPathsOptions(paths.WithPlatform("linux"), paths.WithRoot(root)),
|
||||
WithWorkdirPath(filepath.Join(root, "workdir")),
|
||||
)
|
||||
|
||||
ex, err := r.Explain()
|
||||
if err != nil {
|
||||
t.Fatalf("Explain: %v", err)
|
||||
}
|
||||
if ex.Selected == "" {
|
||||
t.Fatal("Explain().Selected is empty, want the existing user layer")
|
||||
}
|
||||
if want := filepath.Join(root, "home", "test", ".config", "yet", "yet.yaml"); ex.Selected != want {
|
||||
t.Errorf("Explain().Selected = %q, want %q", ex.Selected, want)
|
||||
}
|
||||
if len(ex.Paths.Paths) == 0 {
|
||||
t.Error("Explain().Paths.Paths is empty, want core/paths categories included")
|
||||
}
|
||||
|
||||
text := ex.String()
|
||||
if !strings.Contains(text, "Configuration layers:") || !strings.Contains(text, "Selected:") {
|
||||
t.Errorf("Explain().String() missing expected sections:\n%s", text)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user