Files
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

33 lines
1.1 KiB
Go

package browser
import (
"runtime"
"testing"
)
// TestOpenWithUnreachablePATH confirms Open returns a "not found" error when
// xdg-open / open / rundll32 cannot be located. We set PATH to an empty
// temp dir so the call can't actually spawn a browser — otherwise running
// the tests would pop open a real URL in the user's desktop browser.
func TestOpenWithUnreachablePATH(t *testing.T) {
t.Setenv("PATH", t.TempDir()) // no executables here
err := Open("about:blank")
if err == nil {
t.Error("Open should error when the dispatcher binary is not on PATH")
}
}
// TestOpenUnsupportedPlatform verifies the default case. We can only reach
// it on non-Linux/Darwin/Windows hosts; elsewhere we skip rather than try
// to duplicate the switch body.
func TestOpenUnsupportedPlatform(t *testing.T) {
switch runtime.GOOS {
case "linux", "darwin", "windows":
t.Skipf("host is %s, cannot exercise unsupported-platform branch without build tags", runtime.GOOS)
}
err := Open("about:blank")
if err == nil {
t.Error("Open on unsupported platform should return error")
}
}