gosuki/pkg/browsers/mozilla/profiles_test.go

68 lines
1.3 KiB
Go
Raw Normal View History

2019-02-20 17:39:45 +00:00
package mozilla
import (
"git.blob42.xyz/gosuki/gosuki/pkg/profiles"
"github.com/stretchr/testify/assert"
"testing"
2019-02-20 17:39:45 +00:00
)
var OkProfile = &profiles.INIProfileLoader{
2019-02-22 18:50:26 +00:00
BasePath: "testdata",
ProfilesFile: "profiles_ok.ini",
}
2019-02-20 17:39:45 +00:00
var okPaths = []string{
"path.default",
"path.profile1",
}
var okNames = []string{
"default",
"profile1",
}
var BadProfile = &profiles.INIProfileLoader{
2019-02-22 18:50:26 +00:00
BasePath: "testdata",
ProfilesFile: "profiles_bad.ini",
2019-02-20 17:39:45 +00:00
}
func TestGetProfiles(t *testing.T) {
2023-09-19 17:35:38 +00:00
MozBrowsers["test"] = profiles.BrowserFlavour{"test", "testdata"}
2019-02-22 18:50:26 +00:00
t.Run("OK", func(t *testing.T) {
pm := &MozProfileManager{
PathResolver: OkProfile,
2019-02-22 18:50:26 +00:00
}
2023-09-19 17:35:38 +00:00
profs, err := pm.GetProfiles("test")
2019-02-22 18:50:26 +00:00
if err != nil {
t.Error(err)
}
var pPaths []string
var pNames []string
for _, p := range profs {
pPaths = append(pPaths, p.Path)
pNames = append(pNames, p.Name)
//TEST: Test the absolute path
2019-02-22 18:50:26 +00:00
}
assert.ElementsMatch(t, okPaths, pPaths)
assert.ElementsMatch(t, okNames, pNames)
if profs[0].Name != "default" {
t.Error("Expected default profile in profiles.ini")
2019-02-22 18:50:26 +00:00
}
})
t.Run("Bad", func(t *testing.T) {
pm := &MozProfileManager{
PathResolver: BadProfile,
2019-02-22 18:50:26 +00:00
}
2023-09-19 17:35:38 +00:00
_, err := pm.GetProfiles("test")
2019-02-22 18:50:26 +00:00
if err != ErrProfilesIni || err == nil {
t.Error("Expected error parsing bad profiles file")
}
})
2019-02-20 17:39:45 +00:00
}