-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_coverage_test.go
More file actions
79 lines (69 loc) · 1.64 KB
/
utils_coverage_test.go
File metadata and controls
79 lines (69 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// utils_coverage_test.go
//go:build windows
// +build windows
package main
import (
"runtime"
"testing"
)
func TestOpenBrowserFunction(t *testing.T) {
tests := []struct {
name string
url string
}{
{
name: "test open browser with valid URL",
url: "https://example.com",
},
{
name: "test open browser with invalid URL",
url: "not-a-valid-url",
},
{
name: "test open browser with empty URL",
url: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("Skipping Windows-specific test")
}
// Test that openBrowser doesn't panic
// We can't easily test the actual browser opening without side effects
defer func() {
if r := recover(); r != nil {
t.Errorf("openBrowser() panicked with URL %s: %v", tt.url, r)
}
}()
// Execute the function - it will try to open browser but we can test the code path
openBrowser(tt.url)
})
}
}
func TestOpenBrowserOnNonWindowsPlatform(t *testing.T) {
// This test simulates the non-Windows behavior
tests := []struct {
name string
url string
}{
{
name: "non-windows error handling",
url: "https://example.com",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// We can test the function by temporarily changing runtime.GOOS
// but since that's not possible, we'll test the logic instead
// The function checks: if runtime.GOOS != "windows"
if runtime.GOOS != "windows" {
// On non-Windows, it should call showError
openBrowser(tt.url)
} else {
// On Windows, test the rundll32 execution path
openBrowser(tt.url)
}
})
}
}