summaryrefslogtreecommitdiff
path: root/internal/flamegraph/liveserver_open_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-02 08:46:56 +0200
committerPaul Buetow <paul@buetow.org>2026-03-02 08:46:56 +0200
commit717cf6a47cd19cc284b023825a3bac3272ebe171 (patch)
tree5be553754917157311d107538a99e34b2f8aa839 /internal/flamegraph/liveserver_open_test.go
parentb3327d17f9f5c7080b05d6d5457cf25550d40ad9 (diff)
Make --open a command template with no defaults
Diffstat (limited to 'internal/flamegraph/liveserver_open_test.go')
-rw-r--r--internal/flamegraph/liveserver_open_test.go54
1 files changed, 14 insertions, 40 deletions
diff --git a/internal/flamegraph/liveserver_open_test.go b/internal/flamegraph/liveserver_open_test.go
index 9d280b9..0a42a61 100644
--- a/internal/flamegraph/liveserver_open_test.go
+++ b/internal/flamegraph/liveserver_open_test.go
@@ -5,40 +5,15 @@ import (
"testing"
)
-func TestBrowserOpenCommandPartsUsesLinuxDefault(t *testing.T) {
- got, err := browserOpenCommandParts("linux", "", "http://localhost:1234/")
- if err != nil {
- t.Fatalf("browserOpenCommandParts returned error: %v", err)
- }
- want := []string{"firefox", "http://localhost:1234/"}
- if len(got) != len(want) {
- t.Fatalf("len(parts) = %d, want %d", len(got), len(want))
- }
- for i := range want {
- if got[i] != want[i] {
- t.Fatalf("parts[%d] = %q, want %q", i, got[i], want[i])
- }
- }
-}
-
-func TestBrowserOpenCommandPartsUsesDarwinDefault(t *testing.T) {
- got, err := browserOpenCommandParts("darwin", "", "http://localhost:1234/")
- if err != nil {
- t.Fatalf("browserOpenCommandParts returned error: %v", err)
- }
- want := []string{"open", "-a", "Firefox", "http://localhost:1234/"}
- if len(got) != len(want) {
- t.Fatalf("len(parts) = %d, want %d", len(got), len(want))
- }
- for i := range want {
- if got[i] != want[i] {
- t.Fatalf("parts[%d] = %q, want %q", i, got[i], want[i])
- }
+func TestBrowserOpenCommandPartsRequiresCommand(t *testing.T) {
+ _, err := browserOpenCommandParts("", "http://localhost:1234/")
+ if err == nil {
+ t.Fatalf("expected error for empty open command")
}
}
-func TestBrowserOpenCommandPartsOverrideAppendsURL(t *testing.T) {
- got, err := browserOpenCommandParts("linux", "chromium --new-window", "http://localhost:1234/")
+func TestBrowserOpenCommandPartsAppendsURLWhenMissing(t *testing.T) {
+ got, err := browserOpenCommandParts("chromium --new-window", "http://localhost:1234/")
if err != nil {
t.Fatalf("browserOpenCommandParts returned error: %v", err)
}
@@ -53,8 +28,8 @@ func TestBrowserOpenCommandPartsOverrideAppendsURL(t *testing.T) {
}
}
-func TestBrowserOpenCommandPartsOverrideReplacesPlaceholder(t *testing.T) {
- got, err := browserOpenCommandParts("linux", "open-browser --target={url}", "http://localhost:1234/")
+func TestBrowserOpenCommandPartsReplacesURLPlaceholder(t *testing.T) {
+ got, err := browserOpenCommandParts("open-browser --target={url}", "http://localhost:1234/")
if err != nil {
t.Fatalf("browserOpenCommandParts returned error: %v", err)
}
@@ -69,7 +44,7 @@ func TestBrowserOpenCommandPartsOverrideReplacesPlaceholder(t *testing.T) {
}
}
-func TestMaybeOpenLiveBrowserDisabledSkipsOpen(t *testing.T) {
+func TestMaybeOpenLiveBrowserWithoutCommandSkipsOpen(t *testing.T) {
called := false
orig := openBrowserURLFn
openBrowserURLFn = func(url, openCommand string) error {
@@ -78,16 +53,16 @@ func TestMaybeOpenLiveBrowserDisabledSkipsOpen(t *testing.T) {
}
t.Cleanup(func() { openBrowserURLFn = orig })
- err := maybeOpenLiveBrowser("http://localhost:1234/", LiveServerOptions{AutoOpenBrowser: false})
+ err := maybeOpenLiveBrowser("http://localhost:1234/", LiveServerOptions{})
if err != nil {
t.Fatalf("maybeOpenLiveBrowser returned error: %v", err)
}
if called {
- t.Fatalf("expected browser opener not to be called when disabled")
+ t.Fatalf("expected browser opener not to be called without open command")
}
}
-func TestMaybeOpenLiveBrowserEnabledCallsOpen(t *testing.T) {
+func TestMaybeOpenLiveBrowserWithCommandCallsOpen(t *testing.T) {
called := false
orig := openBrowserURLFn
openBrowserURLFn = func(url, openCommand string) error {
@@ -103,8 +78,7 @@ func TestMaybeOpenLiveBrowserEnabledCallsOpen(t *testing.T) {
t.Cleanup(func() { openBrowserURLFn = orig })
err := maybeOpenLiveBrowser("http://localhost:1234/", LiveServerOptions{
- AutoOpenBrowser: true,
- OpenCommand: "chromium",
+ OpenCommand: "chromium",
})
if err != nil {
t.Fatalf("maybeOpenLiveBrowser returned error: %v", err)
@@ -122,7 +96,7 @@ func TestMaybeOpenLiveBrowserPropagatesOpenError(t *testing.T) {
t.Cleanup(func() { openBrowserURLFn = orig })
err := maybeOpenLiveBrowser("http://localhost:1234/", LiveServerOptions{
- AutoOpenBrowser: true,
+ OpenCommand: "chromium",
})
if err == nil || err.Error() != "launch failed" {
t.Fatalf("expected launch failed error, got %v", err)