package bridge

import (
	"os"
	"testing"
)

func TestLauncherExecutablePathUsesCurrentExecutable(t *testing.T) {
	t.Parallel()

	want := "/opt/mirage/bin/mirage-qt"
	got, err := launcherExecutablePath(func() (string, error) { return want, nil })
	if err != nil {
		t.Fatalf("launcherExecutablePath() error = %v", err)
	}
	if got != want {
		t.Fatalf("launcherExecutablePath() = %q, want %q", got, want)
	}
}

func TestLauncherExecutablePathPrefersEnvOverride(t *testing.T) {
	t.Parallel()

	const want = "/custom/mirage-qt"
	old := os.Getenv("MIRAGE_BRIDGE_PROGRAM")
	t.Cleanup(func() { _ = os.Setenv("MIRAGE_BRIDGE_PROGRAM", old) })
	if err := os.Setenv("MIRAGE_BRIDGE_PROGRAM", want); err != nil {
		t.Fatalf("Setenv: %v", err)
	}

	got, err := launcherExecutablePath(func() (string, error) { return "/ignored", nil })
	if err != nil {
		t.Fatalf("launcherExecutablePath() error = %v", err)
	}
	if got != want {
		t.Fatalf("launcherExecutablePath() = %q, want %q", got, want)
	}
}
