-
-
Notifications
You must be signed in to change notification settings - Fork 75
feat: add ASIF support (macOS 26.0) #196
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package vz_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/Code-Hex/vz/v3" | ||
| ) | ||
|
|
||
| func TestCreateSparseDiskImage_FileCreated(t *testing.T) { | ||
| if vz.Available(26) { | ||
| t.Skip("CreateSparseDiskImage is supported from macOS 26") | ||
| } | ||
|
|
||
| dir := t.TempDir() | ||
| path := filepath.Join(dir, "sparse_disk.img") | ||
|
|
||
| ctx := context.Background() | ||
| size := int64(1024 * 1024 * 1024) // 1 GiB | ||
|
|
||
| err := vz.CreateSparseDiskImage(ctx, path, size) | ||
| if err != nil { | ||
| t.Fatalf("failed to create sparse disk image: %v", err) | ||
| } | ||
|
|
||
| if _, err := os.Stat(path); os.IsNotExist(err) { | ||
| t.Fatal("disk image file was not created") | ||
| } | ||
| } | ||
|
|
||
| func TestCreateSparseDiskImage_ASIFFormat(t *testing.T) { | ||
| if vz.Available(26) { | ||
| t.Skip("CreateSparseDiskImage is supported from macOS 26") | ||
| } | ||
|
|
||
| dir := t.TempDir() | ||
| path := filepath.Join(dir, "sparse_disk.img") | ||
|
|
||
| ctx := context.Background() | ||
| size := int64(1024 * 1024 * 1024) // 1 GiB | ||
|
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. Occupying 1 GB for testing is not good - can't you do something like 1 KB, 1 MB? 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. The image is supposed to be sparse, so I’d expect it will use a few MBs on disk at most. 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. @cfergeau thats right, de "real" disk size the image claims is negligible, given its empty 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. @nagypeterjob I see Thanks! |
||
|
|
||
| err := vz.CreateSparseDiskImage(ctx, path, size) | ||
| if err != nil { | ||
| t.Fatalf("failed to create sparse disk image: %v", err) | ||
| } | ||
|
|
||
| // Check if the format is ASIF using diskutil | ||
| cmd := exec.Command("diskutil", "image", "info", path) | ||
| output, err := cmd.Output() | ||
| if err != nil { | ||
| t.Fatalf("failed to get disk image info: %v", err) | ||
| } | ||
|
|
||
| outputStr := string(output) | ||
| lines := strings.Split(outputStr, "\n") | ||
|
|
||
| foundASIF := false | ||
| // Check if ASIF is mentioned in the first line | ||
| if len(lines) != 0 && strings.Contains(lines[0], "ASIF") { | ||
| foundASIF = true | ||
| } | ||
|
|
||
| if !foundASIF { | ||
| t.Errorf("disk image is not in ASIF format. Output: %v", lines[:1]) | ||
| } | ||
| } | ||
|
|
||
| func TestCreateSparseDiskImage_CorrectSize(t *testing.T) { | ||
| if vz.Available(26) { | ||
| t.Skip("CreateSparseDiskImage is supported from macOS 26") | ||
| } | ||
|
|
||
| dir := t.TempDir() | ||
| path := filepath.Join(dir, "sparse_disk.img") | ||
|
|
||
| ctx := context.Background() | ||
| desiredSize := int64(2 * 1024 * 1024 * 1024) // 2 GiB | ||
|
|
||
| err := vz.CreateSparseDiskImage(ctx, path, desiredSize) | ||
| if err != nil { | ||
| t.Fatalf("failed to create sparse disk image: %v", err) | ||
| } | ||
|
|
||
| cmd := exec.Command("diskutil", "image", "info", path) | ||
| output, err := cmd.Output() | ||
| if err != nil { | ||
| t.Fatalf("failed to get disk image info: %v", err) | ||
| } | ||
|
|
||
| var sizeStr string | ||
| for _, line := range strings.Split(string(output), "\n") { | ||
| if strings.Contains(line, "Total Bytes") { | ||
|
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. We need to get the total "logical" size from the |
||
| components := strings.Split(strings.TrimSpace(line), ":") | ||
| if len(components) > 1 { | ||
| sizeStr = strings.TrimSpace(components[1]) | ||
| break | ||
| } | ||
| } | ||
| } | ||
| actualSize, err := strconv.ParseInt(sizeStr, 10, 64) | ||
| if err != nil { | ||
| t.Fatalf("failed to parse string to int: %v", err) | ||
| } | ||
|
|
||
| if desiredSize != actualSize { | ||
| t.Fatalf("actual disk size (%d) doesn't equal to desired size (%d)", actualSize, desiredSize) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nagypeterjob Could you add test for this function?
A simple test to verify these points is sufficient:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will do it in a day or two 🙇🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There you go @Code-Hex, let me know if you need any changes 🙇🏻