|
5 | 5 | "runtime"
|
6 | 6 | "testing"
|
7 | 7 |
|
| 8 | + "github.com/sirupsen/logrus" |
8 | 9 | "gotest.tools/v3/assert"
|
9 | 10 | )
|
10 | 11 |
|
@@ -186,3 +187,109 @@ func TestValidateParamIsUsed(t *testing.T) {
|
186 | 187 | assert.Error(t, err, "field `param` key \"rootFul\" is not used in any provision, probe, copyToHost, or portForward")
|
187 | 188 | }
|
188 | 189 | }
|
| 190 | + |
| 191 | +func TestValidateRosetta(t *testing.T) { |
| 192 | + images := `images: [{"location": "/"}]` |
| 193 | + |
| 194 | + invalidRosetta := ` |
| 195 | +rosetta: |
| 196 | + enabled: true |
| 197 | +vmType: "qemu" |
| 198 | +` |
| 199 | + y, err := Load([]byte(invalidRosetta+"\n"+images), "lima.yaml") |
| 200 | + assert.NilError(t, err) |
| 201 | + |
| 202 | + err = Validate(y, false) |
| 203 | + assert.Error(t, err, "field `rosetta.enabled` can only be enabled for VMType \"vz\"; got \"qemu\"") |
| 204 | + |
| 205 | + validRosetta := ` |
| 206 | +rosetta: |
| 207 | + enabled: true |
| 208 | +vmType: "vz" |
| 209 | +` |
| 210 | + y, err = Load([]byte(validRosetta+"\n"+images), "lima.yaml") |
| 211 | + assert.NilError(t, err) |
| 212 | + |
| 213 | + err = Validate(y, false) |
| 214 | + assert.NilError(t, err) |
| 215 | + |
| 216 | + rosettaDisabled := ` |
| 217 | +rosetta: |
| 218 | + enabled: false |
| 219 | +vmType: "qemu" |
| 220 | +` |
| 221 | + y, err = Load([]byte(rosettaDisabled+"\n"+images), "lima.yaml") |
| 222 | + assert.NilError(t, err) |
| 223 | + |
| 224 | + err = Validate(y, false) |
| 225 | + assert.NilError(t, err) |
| 226 | +} |
| 227 | + |
| 228 | +func TestValidateNestedVirtualization(t *testing.T) { |
| 229 | + images := `images: [{"location": "/"}]` |
| 230 | + |
| 231 | + validYAML := ` |
| 232 | +nestedVirtualization: true |
| 233 | +vmType: vz |
| 234 | +` + images |
| 235 | + |
| 236 | + y, err := Load([]byte(validYAML), "lima.yaml") |
| 237 | + assert.NilError(t, err) |
| 238 | + |
| 239 | + err = Validate(y, false) |
| 240 | + assert.NilError(t, err) |
| 241 | + |
| 242 | + invalidYAML := ` |
| 243 | +nestedVirtualization: true |
| 244 | +vmType: qemu |
| 245 | +` + images |
| 246 | + |
| 247 | + y, err = Load([]byte(invalidYAML), "lima.yaml") |
| 248 | + assert.NilError(t, err) |
| 249 | + |
| 250 | + err = Validate(y, false) |
| 251 | + assert.Error(t, err, "field `nestedVirtualization` can only be enabled for VMType \"vz\"; got \"qemu\"") |
| 252 | +} |
| 253 | + |
| 254 | +func TestValidateMountTypeOS(t *testing.T) { |
| 255 | + images := `images: [{"location": "/"}]` |
| 256 | + |
| 257 | + inValidMountTypeLinux := ` |
| 258 | +mountType: "rMountType" |
| 259 | +` |
| 260 | + y, err := Load([]byte(inValidMountTypeLinux+"\n"+images), "lima.yaml") |
| 261 | + assert.NilError(t, err) |
| 262 | + |
| 263 | + err = Validate(y, true) |
| 264 | + logrus.Info("inValidMountTypeLinux: from within test ", inValidMountTypeLinux) |
| 265 | + assert.Error(t, err, "field `mountType` must be \"reverse-sshfs\" or \"9p\" or \"virtiofs\", or \"wsl2\", got \"rMountType\"") |
| 266 | + |
| 267 | + validMountTypeLinux := ` |
| 268 | +mountType: "virtiofs" |
| 269 | +` |
| 270 | + y, err = Load([]byte(validMountTypeLinux+"\n"+images), "lima.yaml") |
| 271 | + assert.NilError(t, err) |
| 272 | + |
| 273 | + err = Validate(y, true) |
| 274 | + assert.Error(t, err, "field `mountType` requires vmType 'vz' on macOS (darwin); got qemu") |
| 275 | + |
| 276 | + validMountTypeMac := ` |
| 277 | +mountType: "virtiofs" |
| 278 | +vmType: "vz" |
| 279 | +` |
| 280 | + y, err = Load([]byte(validMountTypeMac+"\n"+images), "lima.yaml") |
| 281 | + assert.NilError(t, err) |
| 282 | + |
| 283 | + err = Validate(y, false) |
| 284 | + assert.NilError(t, err) |
| 285 | + |
| 286 | + invalidMountTypeMac := ` |
| 287 | +mountType: "virtiofs" |
| 288 | +vmType: "qemu" |
| 289 | +` |
| 290 | + y, err = Load([]byte(invalidMountTypeMac+"\n"+images), "lima.yaml") |
| 291 | + assert.NilError(t, err) |
| 292 | + |
| 293 | + err = Validate(y, false) |
| 294 | + assert.Error(t, err, "field `mountType` requires vmType 'vz' on macOS (darwin); got qemu") |
| 295 | +} |
0 commit comments