func stubAllocFunc(r *pluginapi.AllocateRequest, devs map[string]pluginapi.Device) (*pluginapi.AllocateResponse, error) {
	var responses pluginapi.AllocateResponse
	for _, req := range r.ContainerRequests {
		response := &pluginapi.ContainerAllocateResponse{}
		for _, requestID := range req.DevicesIDs {
			dev, ok := devs[requestID]
			if !ok {
				return nil, fmt.Errorf("invalid allocation request with non-existing device %s", requestID)
			}

			if dev.Health != pluginapi.Healthy {
				return nil, fmt.Errorf("invalid allocation request with unhealthy device: %s", requestID)
			}

			// create fake device file
			fpath := filepath.Join("/tmp", dev.ID)

			// clean first
			if err := os.RemoveAll(fpath); err != nil {
				return nil, fmt.Errorf("failed to clean fake device file from previous run: %s", err)
			}

			f, err := os.Create(fpath)
			if err != nil && !os.IsExist(err) {
				return nil, fmt.Errorf("failed to create fake device file: %s", err)
			}

			f.Close()

			response.Mounts = append(response.Mounts, &pluginapi.Mount{
				ContainerPath: fpath,
				HostPath:      fpath,
			})
		}
		responses.ContainerResponses = append(responses.ContainerResponses, response)
	}

	return &responses, nil
}
// stubAllocFunc creates and returns allocation response for the input allocate request
stubAllocFunc creates and returns allocation response for the input allocate request
// stubAllocFunc creates and returns allocation response for the input allocate request
func stubAllocFunc(r *pluginapi.AllocateRequest, devs map[string]pluginapi.Device) (*pluginapi.AllocateResponse, error) {
	var responses pluginapi.AllocateResponse
	for _, req := range r.ContainerRequests {
		response := &pluginapi.ContainerAllocateResponse{}
		for _, requestID := range req.DevicesIDs {
			dev, ok := devs[requestID]
			if !ok {
				return nil, fmt.Errorf("invalid allocation request with non-existing device %s", requestID)
			}
			if dev.Health != pluginapi.Healthy {
				return nil, fmt.Errorf("invalid allocation request with unhealthy device: %s", requestID)
			}
			fpath := filepath.Join("/tmp", dev.ID)
			if err := os.RemoveAll(fpath); err != nil {
				return nil, fmt.Errorf("failed to clean fake device file from previous run: %s", err)
			}
			f, err := os.Create(fpath)
			if err != nil && !os.IsExist(err) {
				return nil, fmt.Errorf("failed to create fake device file: %s", err)
			}
			f.Close()
			response.Mounts = append(response.Mounts, &pluginapi.Mount{
				ContainerPath: fpath,
				HostPath:      fpath,
			})
		}
		responses.ContainerResponses = append(responses.ContainerResponses, response)
	}
	return &responses, nil
}
func stubAllocFunc ( r * pluginapi . AllocateRequest , devs map [ string ] pluginapi . Device ) ( * pluginapi . AllocateResponse , error ) { var responses pluginapi . AllocateResponse for _ , req := range r . ContainerRequests { response := & pluginapi . ContainerAllocateResponse { } for _ , requestID := range req . DevicesIDs { dev , ok := devs [ requestID ] if ! ok { return nil , fmt . Errorf ( " " , requestID ) } if dev . Health != pluginapi . Healthy { return nil , fmt . Errorf ( " " , requestID ) } fpath := filepath . Join ( " " , dev . ID ) if err := os . RemoveAll ( fpath ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } f , err := os . Create ( fpath ) if err != nil && ! os . IsExist ( err ) { return nil , fmt . Errorf ( " " , err ) } f . Close ( ) response . Mounts = append ( response . Mounts , & pluginapi . Mount { ContainerPath : fpath , HostPath : fpath , } ) } responses . ContainerResponses = append ( responses . ContainerResponses , response ) } return & responses , nil }
stubAllocFunc creates and returns allocation response for the input allocate request
stubAllocFunc creates and returns allocation response for the input allocate request
// create fake device file // clean first