2019-02-20 17:39:45 +00:00
|
|
|
package mozilla
|
|
|
|
|
|
|
|
import (
|
2023-09-19 17:32:55 +00:00
|
|
|
"git.blob42.xyz/gosuki/gosuki/pkg/profiles"
|
2023-01-31 21:21:39 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-09-19 17:32:55 +00:00
|
|
|
"testing"
|
2019-02-20 17:39:45 +00:00
|
|
|
)
|
|
|
|
|
2023-09-19 17:32:55 +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
|
|
|
|
2023-01-31 21:21:39 +00:00
|
|
|
var okPaths = []string{
|
|
|
|
"path.default",
|
|
|
|
"path.profile1",
|
|
|
|
}
|
|
|
|
|
|
|
|
var okNames = []string{
|
|
|
|
"default",
|
|
|
|
"profile1",
|
|
|
|
}
|
|
|
|
|
2023-09-19 17:32:55 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-09-19 17:32:55 +00:00
|
|
|
func TestGetProfiles(t *testing.T) {
|
2023-09-21 18:17:19 +00:00
|
|
|
// fake browser flavour
|
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) {
|
2022-10-23 13:08:06 +00:00
|
|
|
pm := &MozProfileManager{
|
2023-09-19 17:32:55 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-09-19 17:32:55 +00:00
|
|
|
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
|
|
|
}
|
2023-09-19 17:32:55 +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) {
|
2022-10-23 13:08:06 +00:00
|
|
|
pm := &MozProfileManager{
|
2023-09-19 17:32:55 +00:00
|
|
|
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
|
|
|
}
|