Files
core/paths/explain_test.go
T
terminar 13801bec11 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.
2026-09-19 16:26:01 +02:00

56 lines
1.4 KiB
Go

package paths
import (
"os"
"strings"
"testing"
)
func TestExplainLinux(t *testing.T) {
env := map[string]string{"HOME": "/home/test"}
r := mustResolver(t, yetApp(), WithPlatform("linux"), WithEnvironment(env))
ex, err := r.Explain()
if err != nil {
t.Fatalf("Explain: %v", err)
}
if ex.Application.Name != "yet" {
t.Errorf("Explain().Application.Name = %q, want yet", ex.Application.Name)
}
var configPath string
for _, p := range ex.Paths {
if p.Kind == ConfigPath {
configPath = p.Path
}
if p.Kind == RuntimePath && p.Path != "" {
t.Errorf("expected RuntimePath to be unavailable (no XDG_RUNTIME_DIR), got %q", p.Path)
}
}
if configPath != "/home/test/.config/yet" {
t.Errorf("Explain() config path = %q, want /home/test/.config/yet", configPath)
}
text := ex.String()
if !strings.Contains(text, "yet") || !strings.Contains(text, "config") {
t.Errorf("Explain().String() missing expected content:\n%s", text)
}
}
func TestExplainNeverMutatesFilesystem(t *testing.T) {
root := t.TempDir()
env := map[string]string{"HOME": "/home/test"}
r := mustResolver(t, yetApp(), WithPlatform("linux"), WithEnvironment(env), WithRoot(root))
if _, err := r.Explain(); err != nil {
t.Fatalf("Explain: %v", err)
}
entries, err := os.ReadDir(root)
if err != nil {
t.Fatal(err)
}
if len(entries) != 0 {
t.Errorf("Explain() created filesystem entries under root: %v", entries)
}
}