Files

111 lines
3.5 KiB
Go
Raw Permalink Normal View History

package paths
import (
"testing"
"yetano.dev/yetano/core"
)
func TestDarwinCLIUsesXDGLikeLayout(t *testing.T) {
env := map[string]string{"HOME": "/Users/test"}
r := mustResolver(t, yetApp(), WithPlatform("darwin"), WithEnvironment(env))
got, err := r.ConfigDir()
if err != nil {
t.Fatalf("ConfigDir: %v", err)
}
if want := "/Users/test/.config/yet"; got != want {
t.Errorf("ConfigDir() = %q, want %q (macOS CLI should match Linux layout)", got, want)
}
}
func TestDarwinDesktopUsesNativeLayout(t *testing.T) {
env := map[string]string{"HOME": "/Users/test"}
app := core.Application{Name: "yapama", Kind: core.Desktop}
r := mustResolver(t, app, WithPlatform("darwin"), WithEnvironment(env))
checks := []struct {
name string
fn func() (string, error)
want string
}{
{"ConfigDir", r.ConfigDir, "/Users/test/Library/Application Support/yapama"},
{"DataDir", r.DataDir, "/Users/test/Library/Application Support/yapama"},
{"StateDir", r.StateDir, "/Users/test/Library/Application Support/yapama/State"},
{"CacheDir", r.CacheDir, "/Users/test/Library/Caches/yapama"},
{"LogDir", r.LogDir, "/Users/test/Library/Logs/yapama"},
}
for _, c := range checks {
got, err := c.fn()
if err != nil {
t.Fatalf("%s: %v", c.name, err)
}
if got != c.want {
t.Errorf("%s = %q, want %q", c.name, got, c.want)
}
}
}
func TestDarwinDesktopSystemScope(t *testing.T) {
app := core.Application{Name: "yapama", Kind: core.Desktop, Scope: core.SystemScope}
r := mustResolver(t, app, WithPlatform("darwin"), WithEnvironment(map[string]string{}))
got, err := r.ConfigDir()
if err != nil {
t.Fatalf("ConfigDir: %v", err)
}
if want := "/Library/Application Support/yapama"; got != want {
t.Errorf("ConfigDir() = %q, want %q", got, want)
}
}
func TestDarwinDesktopConfigSearchDirsUserOverridesSystem(t *testing.T) {
env := map[string]string{"HOME": "/Users/test"}
app := core.Application{Name: "yapama", Kind: core.Desktop}
r := mustResolver(t, app, WithPlatform("darwin"), WithEnvironment(env))
dirs, err := r.ConfigSearchDirs()
if err != nil {
t.Fatalf("ConfigSearchDirs: %v", err)
}
want := []string{
"/Users/test/Library/Application Support/yapama",
"/Library/Application Support/yapama",
}
if len(dirs) != len(want) {
t.Fatalf("ConfigSearchDirs() = %v, want %v", dirs, want)
}
for i, w := range want {
if dirs[i].Path != w {
t.Errorf("ConfigSearchDirs()[%d].Path = %q, want %q", i, dirs[i].Path, w)
}
}
}
func TestDarwinServiceUsesXDGLikeLayout(t *testing.T) {
env := map[string]string{"HOME": "/Users/test"}
app := core.Application{Name: "yasta", Kind: core.Service}
r := mustResolver(t, app, WithPlatform("darwin"), WithEnvironment(env))
got, err := r.ConfigDir()
if err != nil {
t.Fatalf("ConfigDir: %v", err)
}
if want := "/Users/test/.config/yasta"; got != want {
t.Errorf("ConfigDir() = %q, want %q (macOS Service should match Linux layout)", got, want)
}
}
func TestDarwinServiceSystemRuntimeDirIsVarRun(t *testing.T) {
app := core.Application{Name: "yasta", Kind: core.Service, Scope: core.SystemScope}
r := mustResolver(t, app, WithPlatform("darwin"), WithEnvironment(map[string]string{}))
got, err := r.RuntimeDir()
if err != nil {
t.Fatalf("RuntimeDir: %v", err)
}
if want := "/var/run/yasta"; got != want {
t.Errorf("RuntimeDir() = %q, want %q (macOS has no /run)", got, want)
}
lin := mustResolver(t, app, WithPlatform("linux"), WithEnvironment(map[string]string{}))
if got, _ := lin.RuntimeDir(); got != "/run/yasta" {
t.Errorf("linux RuntimeDir() = %q, want /run/yasta", got)
}
}