Git Repository

Stackyard

Stackyard scannt lokale Entwicklungsordner und bündelt Projekte, Git-Status, TODOs, Toolchains, Docker-Compose-Setups, Datei- und Launcher-Funktionen sowie Operations-Informationen in einer lokalen WebUI.

Projektseite ↗
HTTPShttps://zanvex.de/git/stackyard.git

internal/config/config_test.go

Zum Verzeichnis
package config

import (
	"os"
	"path/filepath"
	"runtime"
	"testing"
)

func TestLoadAppliesDefaultsAndExpandsPaths(t *testing.T) {
	testHome := t.TempDir()
	t.Setenv("HOME", testHome)
	t.Setenv("USERPROFILE", testHome)

	dir := t.TempDir()
	configPath := filepath.Join(dir, "config.yaml")
	if err := os.WriteFile(configPath, []byte(`
roots:
  - name: DEV
    path: ./projects
database:
  path: ~/stackyard.db
`), 0o644); err != nil {
		t.Fatalf("write config: %v", err)
	}

	cfg, err := Load(configPath)
	if err != nil {
		t.Fatalf("load config: %v", err)
	}

	if cfg.Server.Listen != "127.0.0.1:8799" {
		t.Fatalf("unexpected listen address: %q", cfg.Server.Listen)
	}
	if cfg.Scanner.MaxDepth != 2 {
		t.Fatalf("unexpected max depth: %d", cfg.Scanner.MaxDepth)
	}
	if cfg.Monitoring.RefreshSeconds != 10 {
		t.Fatalf("unexpected monitoring refresh: %d", cfg.Monitoring.RefreshSeconds)
	}
	if cfg.Roots[0].Path != filepath.Join(dir, "projects") {
		t.Fatalf("unexpected root path: %q", cfg.Roots[0].Path)
	}
	if cfg.Database.Path != filepath.Join(testHome, "stackyard.db") {
		t.Fatalf("unexpected database path: %q", cfg.Database.Path)
	}
	if len(cfg.Scanner.IgnoreDirs) == 0 {
		t.Fatalf("expected default ignore dirs")
	}
	if !cfg.Launchers.VSCode.Enabled || cfg.Launchers.VSCode.Command != "code" {
		t.Fatalf("expected vscode launcher defaults, got %+v", cfg.Launchers.VSCode)
	}
	if !cfg.Launchers.Terminal.Enabled || !cfg.Launchers.Explorer.Enabled {
		t.Fatalf("expected terminal/explorer defaults")
	}
}

func TestLoadRequiresRoots(t *testing.T) {
	dir := t.TempDir()
	configPath := filepath.Join(dir, "config.yaml")
	if err := os.WriteFile(configPath, []byte(`server: {}`), 0o644); err != nil {
		t.Fatalf("write config: %v", err)
	}

	if _, err := Load(configPath); err == nil {
		t.Fatal("expected error for missing roots")
	}
}

func TestDefaultPathUsesExecutableDirectory(t *testing.T) {
	want := filepath.Join("opt", "stackyard", "config.yaml")
	got := defaultPath(filepath.Join("opt", "stackyard", "stackyard.exe"), nil)
	if got != want {
		t.Fatalf("expected %q, got %q", want, got)
	}
	if got := defaultPath("", os.ErrNotExist); got != "config.yaml" {
		t.Fatalf("unexpected fallback path: %q", got)
	}
}

func TestTranslateWindowsPathOnNonWindowsFormat(t *testing.T) {
	got, ok := translateWindowsPath(`E:\_DEV\project-a`)
	if !ok {
		t.Fatal("expected windows path to be recognized")
	}
	if runtime.GOOS == "windows" {
		if got != filepath.Clean("E:/_DEV/project-a") {
			t.Fatalf("unexpected windows path: %q", got)
		}
		return
	}
	if got != filepath.Clean("/mnt/e/_DEV/project-a") {
		t.Fatalf("unexpected translated path: %q", got)
	}
}