Files
podman/pkg/machine/os/ostree_test.go
Brent Baude aba2df7517 Add podman machine os upgrade command
Implements automatic OS upgrade functionality for Podman machines that requires no user input beyond running the command. The upgrade logic automatically determines the appropriate upgrade path using a three-way comparison between client version, machine version, and OCI registry:

* When the client version is older than the machine version, no action is taken and an error is returned.
* When the client version matches the machine version, the OCI registry is queried to check for in-band updates by comparing image digests.  This handles minor, patch level, and updates oci image use cases.
* When the client version is newer than the machine version, the machine is upgraded to match the client's major.minor version.
* No manual image selection or version specification required.

The command supports dry-run mode and JSON (only) output format for automation.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2026-01-16 14:14:06 -06:00

92 lines
1.8 KiB
Go

package os
import (
"testing"
"github.com/blang/semver/v4"
)
func Test_compareMajorMinor(t *testing.T) {
type args struct {
versionA semver.Version
versionB semver.Version
}
tests := []struct {
name string
args args
want int
}{
{
name: "equal major and minor versions and different patch",
args: args{
versionA: semver.MustParse("1.2.3"),
versionB: semver.MustParse("1.2.5"),
},
want: 0,
},
{
name: "A major version less than B",
args: args{
versionA: semver.MustParse("1.5.0"),
versionB: semver.MustParse("2.5.0"),
},
want: -1,
},
{
name: "A major version greater than B",
args: args{
versionA: semver.MustParse("3.2.0"),
versionB: semver.MustParse("2.9.0"),
},
want: 1,
},
{
name: "A minor version less than B (same major)",
args: args{
versionA: semver.MustParse("1.2.0"),
versionB: semver.MustParse("1.5.0"),
},
want: -1,
},
{
name: "A minor version greater than B (same major)",
args: args{
versionA: semver.MustParse("1.8.0"),
versionB: semver.MustParse("1.3.0"),
},
want: 1,
},
{
name: "completely equal versions",
args: args{
versionA: semver.MustParse("1.2.3"),
versionB: semver.MustParse("1.2.3"),
},
want: 0,
},
{
name: "zero versions",
args: args{
versionA: semver.MustParse("0.0.0"),
versionB: semver.MustParse("0.0.1"),
},
want: 0,
},
{
name: "A is zero, B is not",
args: args{
versionA: semver.MustParse("0.0.0"),
versionB: semver.MustParse("1.0.0"),
},
want: -1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := compareMajorMinor(tt.args.versionA, tt.args.versionB); got != tt.want {
t.Errorf("compareMajorMinor() = %v, want %v", got, tt.want)
}
})
}
}