github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/engine/transform_test.go (about) 1 package engine 2 3 import ( 4 "testing" 5 6 "github.com/mitchellh/mapstructure" 7 resourcetypes "github.com/projecteru2/core/resource/types" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 type virtualizationResource struct { 12 CPU map[string]int64 `json:"cpu_map" mapstructure:"cpu_map"` // for cpu binding 13 Quota float64 `json:"cpu" mapstructure:"cpu"` // for cpu quota 14 Memory int64 `json:"memory" mapstructure:"memory"` // for memory binding 15 Storage int64 `json:"storage" mapstructure:"storage"` 16 NUMANode string `json:"numa_node" mapstructure:"numa_node"` // numa node 17 Volumes []string `json:"volumes" mapstructure:"volumes"` 18 VolumePlan map[string]map[string]int64 `json:"volume_plan" mapstructure:"volume_plan"` // literal VolumePlan 19 VolumeChanged bool `json:"volume_changed" mapstructure:"volume_changed"` // indicate whether new volumes contained in realloc request 20 IOPSOptions map[string]string `json:"iops_options" mapstructure:"IOPS_options"` // format: {device_name: "read-IOPS:write-IOPS:read-bps:write-bps"} 21 Remap bool `json:"remap" mapstructure:"remap"` 22 } 23 24 func TestMakeVirtualizationResource(t *testing.T) { 25 engineParams := resourcetypes.Resources{ 26 "cpumem": { 27 "cpu_map": map[string]int64{"1": 100}, 28 "cpu": 100.0, 29 "memory": 10000, 30 }, 31 } 32 33 dst := &virtualizationResource{} 34 35 err := MakeVirtualizationResource(engineParams, dst, func(p resourcetypes.Resources, d *virtualizationResource) error { 36 return mapstructure.Decode(p["cpumem"], d) 37 }) 38 assert.NoError(t, err) 39 assert.Equal(t, dst.Quota, 100.0) 40 assert.Len(t, dst.CPU, 1) 41 err = MakeVirtualizationResource(engineParams, dst, func(p resourcetypes.Resources, d *virtualizationResource) error { 42 return mapstructure.Decode(p["storage"], d) 43 }) 44 assert.NoError(t, err) 45 }