Files
HackBrowserData/internal/browser/browser_test.go
T
Roger 6ddfe48493 refactor: pin CLI output and rename path fields (#711)
Step 1 of #710. Goldens pin what a run prints before the entry code moves, and the renames follow two naming rules added to RFC-001. No behavior change.
2026-11-21 19:18:07 +08:00

50 lines
1.3 KiB
Go

package browser
import (
"sort"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var platformOf = map[string]func(Browser) Platform{
"darwin": func(browser Browser) Platform { return browser.Darwin },
"linux": func(browser Browser) Platform { return browser.Linux },
"windows": func(browser Browser) Platform { return browser.Windows },
}
func namesOn(platform func(Browser) Platform) []string {
var names []string
for _, browser := range browsers {
if len(platform(browser).UserDataDirPaths) > 0 {
names = append(names, browser.Name)
}
}
return names
}
func TestSupported_ListsThisOSRowsInTableOrder(t *testing.T) {
var names []string
for _, browser := range Supported() {
names = append(names, browser.Name)
}
assert.Equal(t, namesOn(Browser.Platform), names)
}
func TestLookup_FindsEveryRowWhateverTheOS(t *testing.T) {
for _, want := range browsers {
got, ok := Lookup(want.Name)
require.True(t, ok, want.Name)
assert.Equal(t, want, got)
}
_, ok := Lookup("netscape")
assert.False(t, ok)
}
func TestNames_AreSupportedSorted(t *testing.T) {
names := Names()
assert.True(t, sort.StringsAreSorted(names), "the -b help has always listed them sorted")
assert.ElementsMatch(t, namesOn(Browser.Platform), names)
}