Files
core/paths/explain_test.go
T

55 lines
1.4 KiB
Go
Raw Normal View History

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)
}
}