Repository: kubernetes/kubernetes
File: pkg/scheduler/testing/wrappers.go (Go)

Code before:

// Devices sets the devices field of the inner object.
func (wrapper *ResourceSliceWrapper) Devices(names ...string) *ResourceSliceWrapper {
	for _, name := range names {
		wrapper.Spec.Devices = append(wrapper.Spec.Devices, resourceapi.Device{Name: name})
	}
	return wrapper
}

type NodeName string

// Device extends the devices field of the inner object.
// The device must have a name and may have arbitrary additional fields.
func (wrapper *ResourceSliceWrapper) Device(name string, otherFields ...any) *ResourceSliceWrapper {
	device := resourceapi.Device{Name: name}
	for _, field := range otherFields {
		switch typedField := field.(type) {
		case map[resourceapi.QualifiedName]resourceapi.DeviceAttribute:
			device.Attributes = typedField
		case map[resourceapi.QualifiedName]resourceapi.DeviceCapacity:
			device.Capacity = typedField
		case resourceapi.DeviceTaint:
			device.Taints = append(device.Taints, typedField)
		case NodeName:
			nodeName := string(typedField)
			device.NodeName = &nodeName
		case *v1.NodeSelector:
			device.NodeSelector = typedField
		default:
			panic(fmt.Sprintf("expected a type which matches a field in BasicDevice, got %T", field))
		}
	}
	wrapper.Spec.Devices = append(wrapper.Spec.Devices, device)
	return wrapper
}

func (wrapper *ResourceSliceWrapper) ResourceSliceCount(count int) *ResourceSliceWrapper {
	wrapper.Spec.Pool.ResourceSliceCount = int64(count)
	return wrapper
}

// StorageClassWrapper wraps a StorageClass inside.
type StorageClassWrapper struct{ storagev1.StorageClass }

// MakeStorageClass creates a StorageClass wrapper.
func MakeStorageClass() *StorageClassWrapper {
	return &StorageClassWrapper{}
}

// Obj returns the inner StorageClass.
func (s *StorageClassWrapper) Obj() *storagev1.StorageClass {

Review comment (suggestion):
```suggestion
			device.NodeName = (string *)(&nodeName)
```

Code after:

// Devices sets the devices field of the inner object.
func (wrapper *ResourceSliceWrapper) Devices(names ...string) *ResourceSliceWrapper {
	for _, name := range names {
		wrapper.Spec.Devices = append(wrapper.Spec.Devices, resourceapi.Device{Name: name})
	}
	return wrapper
}

type NodeName string

// Device extends the devices field of the inner object.
// The device must have a name and may have arbitrary additional fields.
func (wrapper *ResourceSliceWrapper) Device(name string, otherFields ...any) *ResourceSliceWrapper {
	device := resourceapi.Device{Name: name}
	for _, field := range otherFields {
		switch typedField := field.(type) {
		case map[resourceapi.QualifiedName]resourceapi.DeviceAttribute:
			device.Attributes = typedField
		case map[resourceapi.QualifiedName]resourceapi.DeviceCapacity:
			device.Capacity = typedField
		case resourceapi.DeviceTaint:
			device.Taints = append(device.Taints, typedField)
		case NodeName:
			device.NodeName = (*string)(&typedField)
		case *v1.NodeSelector:
			device.NodeSelector = typedField
		default:
			panic(fmt.Sprintf("expected a type which matches a field in BasicDevice, got %T", field))
		}
	}
	wrapper.Spec.Devices = append(wrapper.Spec.Devices, device)
	return wrapper
}

func (wrapper *ResourceSliceWrapper) ResourceSliceCount(count int) *ResourceSliceWrapper {
	wrapper.Spec.Pool.ResourceSliceCount = int64(count)
	return wrapper
}

// StorageClassWrapper wraps a StorageClass inside.
type StorageClassWrapper struct{ storagev1.StorageClass }

// MakeStorageClass creates a StorageClass wrapper.
func MakeStorageClass() *StorageClassWrapper {
	return &StorageClassWrapper{}
}

// Obj returns the inner StorageClass.
func (s *StorageClassWrapper) Obj() *storagev1.StorageClass {
	return &s.StorageClass