Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/board/os_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ func parseOSImageVersion(r io.Reader) (string, bool) {

return "", false
}

// Calculates whether user partition preservation is supported,
// according to the current and target OS image versions.
//
// Preservation is supported if both versions are not the R0 image.
func IsUserPartitionPreservationSupported(currentImageVersion string, targetImageVersion string) bool {
return targetImageVersion != R0_IMAGE_VERSION_ID && currentImageVersion != R0_IMAGE_VERSION_ID
}
44 changes: 44 additions & 0 deletions pkg/board/os_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,47 @@ func TestGetOSImageVersion(t *testing.T) {
require.Equal(t, GetOSImageVersion(R0Version), R0_IMAGE_VERSION_ID)
require.Equal(t, GetOSImageVersion(AnotherVersion), "20250101-001")
}

func TestIsUserPartitionPreservationSupported(t *testing.T) {
const R0_IMAGE_VERSION_ID = "20250807-136"
anotherVersionId := "20250101-001"

tests := []struct {
name string
currentVersion string
targetVersion string
isPreservationSupported bool
}{
{
name: "both versions are *not* R0",
currentVersion: anotherVersionId,
targetVersion: "20250101-001",
isPreservationSupported: true,
},
{
name: "current version is R0",
currentVersion: R0_IMAGE_VERSION_ID,
targetVersion: "20250101-001",
isPreservationSupported: false,
},
{
name: "target version is R0",
currentVersion: anotherVersionId,
targetVersion: R0_IMAGE_VERSION_ID,
isPreservationSupported: false,
},
{
name: "both versions are R0",
currentVersion: R0_IMAGE_VERSION_ID,
targetVersion: R0_IMAGE_VERSION_ID,
isPreservationSupported: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
isPreservationSupported := IsUserPartitionPreservationSupported(tt.currentVersion, tt.targetVersion)
require.Equal(t, isPreservationSupported, tt.isPreservationSupported)
})
}
}