mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-09-29 19:41:15 +02:00
Make USB accessories opt-in for Tart VMs (#502)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package v1_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUSBAccessoriesSpecification(t *testing.T) {
|
||||
var vm v1.VM
|
||||
require.NoError(t, json.Unmarshal([]byte(`{"runtime":"tart"}`), &vm))
|
||||
require.False(t, vm.USBAccessories)
|
||||
require.False(t, vm.Suspendable)
|
||||
require.NoError(t, vm.Validate())
|
||||
|
||||
previous := vm.VMSpec
|
||||
vm.USBAccessories = true
|
||||
require.False(t, v1.SemanticallyEqual(previous, vm.VMSpec))
|
||||
|
||||
encoded, err := json.Marshal(vm.VMSpec)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, string(encoded), `"usbAccessories":true`)
|
||||
|
||||
vm.Runtime = v1.RuntimeVetu
|
||||
require.ErrorContains(t, vm.Validate(), `does not support field "usbAccessories"`)
|
||||
vm.USBAccessories = false
|
||||
require.NoError(t, vm.Validate())
|
||||
}
|
||||
@@ -180,6 +180,9 @@ func (vm *VM) Validate() error {
|
||||
if vm.Suspendable {
|
||||
return unsupportedFieldError("suspendable")
|
||||
}
|
||||
if vm.USBAccessories {
|
||||
return unsupportedFieldError("usbAccessories")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -211,6 +214,7 @@ type VMSpec struct {
|
||||
NetSoftnetAllow []string `json:"netSoftnetAllow,omitempty"`
|
||||
NetSoftnetBlock []string `json:"netSoftnetBlock,omitempty"`
|
||||
Suspendable bool `json:"suspendable,omitempty"`
|
||||
USBAccessories bool `json:"usbAccessories,omitempty"`
|
||||
PowerState PowerState `json:"powerState,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user