Files
HackBrowserData/internal/browser/browser_test.go
T
Roger 2e7ee3c69f test: tidy misplaced, stale, and redundant tests (#691)
Tests now sit beside the code they cover; ones a golden or another test already pins are gone, and core tests gain the assertions a real regression would trip.
2026-11-09 17:25:37 +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).UserDataDirs) > 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)
}