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.
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|