This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
forked from Code-Hex/vz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osversion_arm64_test.go
137 lines (129 loc) · 3.46 KB
/
osversion_arm64_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//go:build darwin && arm64
// +build darwin,arm64
package vz
import (
"context"
"errors"
"os"
"path/filepath"
"sync"
"testing"
)
func TestAvailableVersionArm64(t *testing.T) {
majorMinorVersionOnce = &nopDoer{}
defer func() {
majorMinorVersion = 0
majorMinorVersionOnce = &sync.Once{}
}()
t.Run("macOS 12", func(t *testing.T) {
majorMinorVersion = 11
cases := map[string]func() error{
"NewMacOSBootLoader": func() error {
_, err := NewMacOSBootLoader()
return err
},
"NewMacGraphicsDeviceConfiguration": func() error {
_, err := NewMacGraphicsDeviceConfiguration()
return err
},
"NewMacGraphicsDisplayConfiguration": func() error {
_, err := NewMacGraphicsDisplayConfiguration(0, 0, 0)
return err
},
"NewMacPlatformConfiguration": func() error {
_, err := NewMacPlatformConfiguration()
return err
},
"NewMacHardwareModelWithData": func() error {
_, err := NewMacHardwareModelWithData(nil)
return err
},
"NewMacMachineIdentifierWithData": func() error {
_, err := NewMacMachineIdentifierWithData(nil)
return err
},
"NewMacMachineIdentifier": func() error {
_, err := NewMacMachineIdentifier()
return err
},
"NewMacAuxiliaryStorage": func() error {
_, err := NewMacAuxiliaryStorage("")
return err
},
"FetchLatestSupportedMacOSRestoreImage": func() error {
_, err := FetchLatestSupportedMacOSRestoreImage(context.Background(), "")
return err
},
"LoadMacOSRestoreImageFromPath": func() error {
_, err := LoadMacOSRestoreImageFromPath("")
return err
},
"NewMacOSInstaller": func() error {
_, err := NewMacOSInstaller(nil, "")
return err
},
}
for name, fn := range cases {
err := fn()
if !errors.Is(err, ErrUnsupportedOSVersion) {
t.Fatalf("unexpected error %v in %s", err, name)
}
}
})
t.Run("macOS 13", func(t *testing.T) {
if macOSBuildTargetAvailable(13) != nil {
t.Skip("disabled build target for macOS 13")
}
majorMinorVersion = 12.3
cases := map[string]func() error{
"WithStartUpFromMacOSRecovery": func() error {
return (*VirtualMachine)(nil).Start(WithStartUpFromMacOSRecovery(true))
},
"MacOSGuestAutomountTag": func() error {
_, err := MacOSGuestAutomountTag()
return err
},
}
for name, fn := range cases {
err := fn()
if !errors.Is(err, ErrUnsupportedOSVersion) {
t.Fatalf("unexpected error %v in %s", err, name)
}
}
})
t.Run("macOS 14", func(t *testing.T) {
if macOSBuildTargetAvailable(14) != nil {
t.Skip("disabled build target for macOS 13")
}
dir := t.TempDir()
filename := filepath.Join(dir, "tmpfile.txt")
f, err := os.Create(filename)
if err != nil {
t.Fatal(err)
}
defer f.Close()
majorMinorVersion = 13
cases := map[string]func() error{
"NewLinuxRosettaUnixSocketCachingOptions": func() error {
_, err := NewLinuxRosettaUnixSocketCachingOptions(filename)
return err
},
"NewLinuxRosettaAbstractSocketCachingOptions": func() error {
_, err := NewLinuxRosettaAbstractSocketCachingOptions("datagram")
return err
},
"SaveMachineStateToPath": func() error {
return (*VirtualMachine)(nil).SaveMachineStateToPath(filename)
},
"RestoreMachineStateFromURL": func() error {
return (*VirtualMachine)(nil).RestoreMachineStateFromURL(filename)
},
}
for name, fn := range cases {
err := fn()
if !errors.Is(err, ErrUnsupportedOSVersion) {
t.Fatalf("unexpected error %v in %s", err, name)
}
}
})
}