mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Modifying darwin brave version output (#31208)
drop lagging .0 add 58 to second version number and prepend fixes #31122 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - [x] Added/updated automated tests - [x] Manual QA for all new/changed functionality
This commit is contained in:
parent
c7e17c8066
commit
b5627b6a0e
4 changed files with 104 additions and 1 deletions
|
|
@ -0,0 +1,38 @@
|
|||
package externalrefs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
maintained_apps "github.com/fleetdm/fleet/v4/ee/maintained-apps"
|
||||
)
|
||||
|
||||
func BraveVersionTransformer(app *maintained_apps.FMAManifestApp) (*maintained_apps.FMAManifestApp, error) {
|
||||
var modifiedVersion string
|
||||
homebrewVersion := app.Version
|
||||
// Input format: 1.79.123.0
|
||||
|
||||
// drop lagging .0
|
||||
if strings.HasSuffix(homebrewVersion, ".0") {
|
||||
modifiedVersion = homebrewVersion[:len(homebrewVersion)-2]
|
||||
} else {
|
||||
return app, fmt.Errorf("Expected Brave version to end with '.0' but found '%s'", homebrewVersion)
|
||||
}
|
||||
|
||||
// add 58 to second value
|
||||
parts := strings.Split(modifiedVersion, ".")
|
||||
if len(parts) == 3 {
|
||||
if second, err := strconv.Atoi(parts[1]); err == nil {
|
||||
parts = append([]string{fmt.Sprintf("%d", second+58)}, parts...)
|
||||
} else {
|
||||
return app, fmt.Errorf("Failed to parse '%s' of Brave version '%s': %v", parts[1], homebrewVersion, err)
|
||||
}
|
||||
// Output format: 137.1.79.123
|
||||
app.Version = strings.Join(parts, ".")
|
||||
} else {
|
||||
return app, fmt.Errorf("Expected Brave version to have four parts but found '%s'", homebrewVersion)
|
||||
}
|
||||
|
||||
return app, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package externalrefs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
maintained_apps "github.com/fleetdm/fleet/v4/ee/maintained-apps"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBraveVersionTransformer(t *testing.T) {
|
||||
t.Run("Version does not end with .0", func(t *testing.T) {
|
||||
app := &maintained_apps.FMAManifestApp{
|
||||
UniqueIdentifier: "brave-browser/darwin",
|
||||
Version: "1.79.123",
|
||||
}
|
||||
result, err := BraveVersionTransformer(app)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Expected Brave version to end with '.0' but found '1.79.123'", err.Error())
|
||||
assert.Equal(t, "1.79.123", result.Version)
|
||||
})
|
||||
|
||||
t.Run("version has less than three parts after dropping .0", func(t *testing.T) {
|
||||
app := &maintained_apps.FMAManifestApp{
|
||||
UniqueIdentifier: "brave-browser/darwin",
|
||||
Version: "1.79.0",
|
||||
}
|
||||
result, err := BraveVersionTransformer(app)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Expected Brave version to have four parts but found '1.79.0'", err.Error())
|
||||
assert.Equal(t, "1.79.0", result.Version)
|
||||
})
|
||||
|
||||
t.Run("version has more than three parts after dropping .0", func(t *testing.T) {
|
||||
app := &maintained_apps.FMAManifestApp{
|
||||
UniqueIdentifier: "brave-browser/darwin",
|
||||
Version: "1.1.1.79.0",
|
||||
}
|
||||
result, err := BraveVersionTransformer(app)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Expected Brave version to have four parts but found '1.1.1.79.0'", err.Error())
|
||||
assert.Equal(t, "1.1.1.79.0", result.Version)
|
||||
})
|
||||
|
||||
t.Run("cannot parse second part as integer", func(t *testing.T) {
|
||||
app := &maintained_apps.FMAManifestApp{
|
||||
UniqueIdentifier: "brave-browser/darwin",
|
||||
Version: "1.a79.123.0",
|
||||
}
|
||||
result, err := BraveVersionTransformer(app)
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, "Failed to parse 'a79' of Brave version '1.a79.123.0': strconv.Atoi: parsing \"a79\": invalid syntax", err.Error())
|
||||
assert.Equal(t, "1.a79.123.0", result.Version)
|
||||
})
|
||||
|
||||
t.Run("Valid Brave Version", func(t *testing.T) {
|
||||
app := &maintained_apps.FMAManifestApp{
|
||||
UniqueIdentifier: "brave-browser/darwin",
|
||||
Version: "1.79.123.0",
|
||||
}
|
||||
result, err := BraveVersionTransformer(app)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "137.1.79.123", result.Version)
|
||||
})
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import (
|
|||
var Funcs = map[string][]func(*maintained_apps.FMAManifestApp) (*maintained_apps.FMAManifestApp, error){
|
||||
"microsoft-word/darwin": {MicrosoftVersionFromReleaseNotes},
|
||||
"microsoft-excel/darwin": {MicrosoftVersionFromReleaseNotes},
|
||||
"brave-browser/darwin": {BraveVersionTransformer},
|
||||
"whatsapp/darwin": {WhatsAppVersionShortener},
|
||||
"google-chrome/darwin": {ChromePKGInstaller},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"versions": [
|
||||
{
|
||||
"version": "1.79.126.0",
|
||||
"version": "137.1.79.126",
|
||||
"queries": {
|
||||
"exists": "SELECT 1 FROM apps WHERE bundle_identifier = 'com.brave.Browser';"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue