-
Notifications
You must be signed in to change notification settings - Fork 7
Pin the major platform/core version for updates #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
e66a3d8
0b11841
0b318ae
98440c3
b41a3af
28d2ac4
d8edeb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,15 +31,16 @@ import ( | |
| var runnerVersion = "0.6.1" | ||
|
|
||
| type Configuration struct { | ||
| appsDir *paths.Path | ||
| dataDir *paths.Path | ||
| routerSocketPath *paths.Path | ||
| customEIModelsDir *paths.Path | ||
| PythonImage string | ||
| UsedPythonImageTag string | ||
| RunnerVersion string | ||
| AllowRoot bool | ||
| LibrariesAPIURL *url.URL | ||
| appsDir *paths.Path | ||
| dataDir *paths.Path | ||
| routerSocketPath *paths.Path | ||
| customEIModelsDir *paths.Path | ||
| PythonImage string | ||
| UsedPythonImageTag string | ||
| RunnerVersion string | ||
| AllowRoot bool | ||
| LibrariesAPIURL *url.URL | ||
| MaxAllowedMajorVersion int | ||
| } | ||
|
|
||
| func NewFromEnv() (Configuration, error) { | ||
|
|
@@ -105,17 +106,25 @@ func NewFromEnv() (Configuration, error) { | |
| if err != nil { | ||
| return Configuration{}, fmt.Errorf("invalid LIBRARIES_API_URL: %w", err) | ||
| } | ||
| maxVersionStr := os.Getenv("ARDUINO_APP_CLI__MAX_UPDATE_MAJOR_VERSION") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make this a version constraint string, parsable with relaxed-semver https://pkg.go.dev/go.bug.st/relaxed-semver#readme-version-constraints. For instance, the default value should be |
||
|
|
||
| maxVersion, err := strconv.Atoi(maxVersionStr) | ||
| if err != nil || maxVersion <= 0 { | ||
| maxVersion = 0 | ||
| } | ||
| slog.Debug("Using max update major version", slog.Int("version", maxVersion)) | ||
|
|
||
| c := Configuration{ | ||
| appsDir: appsDir, | ||
| dataDir: dataDir, | ||
| routerSocketPath: routerSocket, | ||
| customEIModelsDir: customEIModelsDir, | ||
| PythonImage: pythonImage, | ||
| UsedPythonImageTag: usedPythonImageTag, | ||
| RunnerVersion: runnerVersion, | ||
| AllowRoot: allowRoot, | ||
| LibrariesAPIURL: parsedLibrariesURL, | ||
| appsDir: appsDir, | ||
| dataDir: dataDir, | ||
| routerSocketPath: routerSocket, | ||
| customEIModelsDir: customEIModelsDir, | ||
| PythonImage: pythonImage, | ||
| UsedPythonImageTag: usedPythonImageTag, | ||
| RunnerVersion: runnerVersion, | ||
| AllowRoot: allowRoot, | ||
| LibrariesAPIURL: parsedLibrariesURL, | ||
| MaxAllowedMajorVersion: maxVersion, | ||
| } | ||
| if err := c.init(); err != nil { | ||
| return Configuration{}, err | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,13 +22,15 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "log/slog" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "sync" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/Masterminds/semver/v3" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/arduino/arduino-cli/commands" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/arduino/arduino-cli/commands/cmderrors" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/sirupsen/logrus" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/arduino/arduino-app-cli/internal/helpers" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/arduino/arduino-app-cli/internal/orchestrator" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/arduino/arduino-app-cli/internal/orchestrator/config" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/arduino/arduino-app-cli/internal/update" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,7 +55,7 @@ func setConfig(ctx context.Context, srv rpc.ArduinoCoreServiceServer) error { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ListUpgradablePackages implements ServiceUpdater. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (a *ArduinoPlatformUpdater) ListUpgradablePackages(ctx context.Context, _ func(update.UpgradablePackage) bool) ([]update.UpgradablePackage, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (a *ArduinoPlatformUpdater) ListUpgradablePackages(cfg config.Configuration, ctx context.Context, _ func(update.UpgradablePackage) bool) ([]update.UpgradablePackage, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if !a.lock.TryLock() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, update.ErrOperationAlreadyInProgress | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -120,18 +122,65 @@ func (a *ArduinoPlatformUpdater) ListUpgradablePackages(ctx context.Context, _ f | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if platformSummary == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, nil // No platform found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| releasesMap := platformSummary.GetReleases() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if platformSummary.GetLatestVersion() == platformSummary.GetInstalledVersion() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, nil // No update available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| releases := make([]string, 0, len(releasesMap)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for k := range releasesMap { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| releases = append(releases, k) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bestVersion, err := findBestCandidate( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformSummary.GetInstalledVersion(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| releases, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cfg.MaxAllowedMajorVersion, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if bestVersion == "" || err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return []update.UpgradablePackage{{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Type: update.Arduino, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Name: "arduino:zephyr", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FromVersion: platformSummary.GetInstalledVersion(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ToVersion: platformSummary.GetLatestVersion(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ToVersion: bestVersion, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't seem that this ToVersion is used in the upgrade function, so I think we always upgrade to the latest version |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }}, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func findBestCandidate(installedStr string, availableVersions []string, maxMajorConfig int) (string, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| installedV, err := semver.NewVersion(installedStr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "", err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| maxMajor := uint64(maxMajorConfig) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if maxMajorConfig <= 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| maxMajor = installedV.Major() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var bestUpdateV *semver.Version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, vStr := range availableVersions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| candidateV, err := semver.NewVersion(vStr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if candidateV.Major() > maxMajor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if !candidateV.GreaterThan(installedV) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if bestUpdateV == nil || candidateV.GreaterThan(bestUpdateV) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bestUpdateV = candidateV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if bestUpdateV == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "", nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return bestUpdateV.Original(), nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+148
to
+183
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the constraint in a way like this
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // UpgradePackages implements ServiceUpdater. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []string) (<-chan update.Event, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package arduino | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestFindBestCandidate(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| installed string | ||
| available []string | ||
| maxMajorConfig int | ||
| expectedVersion string | ||
| expectError bool | ||
| }{ | ||
| { | ||
| name: "Standard update: minor upgrade available", | ||
| installed: "1.0.0", | ||
| available: []string{"1.0.1", "1.1.0"}, | ||
| maxMajorConfig: 0, | ||
| expectedVersion: "1.1.0", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "Major update blocked by default (Config=0)", | ||
| installed: "1.9.9", | ||
| available: []string{"2.0.0", "1.9.10"}, | ||
| maxMajorConfig: 0, | ||
| expectedVersion: "1.9.10", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "Major update allowed by explicit config", | ||
| installed: "1.9.9", | ||
| available: []string{"2.0.0", "3.0.0"}, | ||
| maxMajorConfig: 2, | ||
| expectedVersion: "2.0.0", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "CRITICAL: Regression test for 'Zero Value' bug (Version 2+)", | ||
| installed: "2.1.0", | ||
| available: []string{"2.2.0", "3.0.0"}, | ||
| maxMajorConfig: 0, | ||
| expectedVersion: "2.2.0", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "No updates available (all older or same)", | ||
| installed: "1.5.0", | ||
| available: []string{"1.0.0", "1.5.0"}, | ||
| maxMajorConfig: 0, | ||
| expectedVersion: "", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "Handle unsorted list and pick highest valid", | ||
| installed: "1.0.0", | ||
| available: []string{"1.1.0", "1.5.0", "1.2.0"}, | ||
| maxMajorConfig: 0, | ||
| expectedVersion: "1.5.0", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "Skip invalid candidate strings", | ||
| installed: "1.0.0", | ||
| available: []string{"invalid-ver", "1.1.0"}, | ||
| maxMajorConfig: 0, | ||
| expectedVersion: "1.1.0", | ||
| expectError: false, | ||
| }, | ||
| { | ||
| name: "Error on invalid installed version string", | ||
| installed: "not-a-semver", | ||
| available: []string{"1.0.0"}, | ||
| maxMajorConfig: 0, | ||
| expectedVersion: "", | ||
| expectError: true, | ||
| }, | ||
| { | ||
| name: "Prerelease handling (standard logic ignores prereleases unless specifically handled)", | ||
| installed: "1.0.0", | ||
| available: []string{"1.0.1-beta"}, | ||
| maxMajorConfig: 0, | ||
| expectedVersion: "1.0.1-beta", | ||
| expectError: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := findBestCandidate(tt.installed, tt.available, tt.maxMajorConfig) | ||
|
|
||
| if (err != nil) != tt.expectError { | ||
| t.Errorf("findBestCandidate() error = %v, expectError %v", err, tt.expectError) | ||
| return | ||
| } | ||
| if got != tt.expectedVersion { | ||
| t.Errorf("findBestCandidate() = %v, want %v", got, tt.expectedVersion) | ||
| } | ||
| }) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.