gosuki/mozilla/profiles_test.go
Chakib Ben Ziane 1102df001c generic profile commands, modules need to implement ProfileManager
- no need to implement profile management commands for each module
- [todo] profile commands available when ProfileManager interface implemented
2023-01-31 22:21:39 +01:00

91 lines
1.5 KiB
Go

package mozilla
import (
"testing"
"github.com/stretchr/testify/assert"
)
var OkProfile = &INIProfileLoader{
BasePath: "testdata",
ProfilesFile: "profiles_ok.ini",
}
var okPaths = []string{
"path.default",
"path.profile1",
}
var okNames = []string{
"default",
"profile1",
}
var BadProfile = &INIProfileLoader{
BasePath: "testdata",
ProfilesFile: "profiles_bad.ini",
}
func TestListProfiles(t *testing.T) {
t.Run("OK", func(t *testing.T) {
pm := &MozProfileManager{
PathGetter: OkProfile,
}
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{
PathGetter: BadProfile,
}
_, err := pm.ListProfiles()
if err != ErrProfilesIni || err == nil {
t.Error("Expected error parsing bad profiles file")
}
})
}
func TestGetProfiles(t *testing.T) {
pm := &MozProfileManager{
PathGetter: OkProfile,
}
profs, err := pm.GetProfiles()
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
}
assert.ElementsMatch(t, okPaths, pPaths)
assert.ElementsMatch(t, okNames, pNames)
if profs[0].Name != "default" {
t.Error("Expected default profile in profiles.ini")
}
}