gosuki/mozilla/profiles_test.go

91 lines
1.5 KiB
Go
Raw Normal View History

2019-02-20 17:39:45 +00:00
package mozilla
import (
"testing"
"github.com/stretchr/testify/assert"
2019-02-20 17:39:45 +00:00
)
2019-03-01 18:03:48 +00:00
var OkProfile = &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",
}
2019-03-01 18:03:48 +00:00
var BadProfile = &INIProfileLoader{
2019-02-22 18:50:26 +00:00
BasePath: "testdata",
ProfilesFile: "profiles_bad.ini",
2019-02-20 17:39:45 +00:00
}
func TestListProfiles(t *testing.T) {
2019-02-22 18:50:26 +00:00
t.Run("OK", func(t *testing.T) {
pm := &MozProfileManager{
2022-11-07 19:07:13 +00:00
PathGetter: OkProfile,
2019-02-22 18:50:26 +00:00
}
t.Log("Listing profiles")
profiles, err := pm.ListProfiles()
if err != nil {
t.Error(err)
}
for _, p := range profiles {
t.Logf("found profiles: %s", p)
}
if profiles[0] != "Profile0" {
t.Error("Expected Profile0")
}
})
t.Run("Bad", func(t *testing.T) {
pm := &MozProfileManager{
2022-11-07 19:07:13 +00:00
PathGetter: BadProfile,
2019-02-22 18:50:26 +00:00
}
_, err := pm.ListProfiles()
if err != ErrProfilesIni || err == nil {
t.Error("Expected error parsing bad profiles file")
}
})
2019-02-20 17:39:45 +00:00
}
func TestGetProfiles(t *testing.T) {
pm := &MozProfileManager{
2022-11-07 19:07:13 +00:00
PathGetter: OkProfile,
2019-02-22 18:50:26 +00:00
}
2019-02-20 17:39:45 +00:00
profs, err := pm.GetProfiles()
if err != nil {
t.Error(err)
}
var pPaths []string
var pNames []string
2019-02-20 17:39:45 +00:00
for _, p := range profs {
pPaths = append(pPaths, p.Path)
pNames = append(pNames, p.Name)
//TEST: Test the absolute path
2019-02-20 17:39:45 +00:00
}
assert.ElementsMatch(t, okPaths, pPaths)
assert.ElementsMatch(t, okNames, pNames)
2019-02-22 18:50:26 +00:00
if profs[0].Name != "default" {
t.Error("Expected default profile in profiles.ini")
}
2019-02-20 17:39:45 +00:00
}