mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-31 05:40:42 +00:00 
			
		
		
		
	Add a simple endpoint test for GetPreferredAllocation()
More extensive tests that exercise the allocation logic are to follow.
This commit is contained in:
		| @@ -159,6 +159,40 @@ func TestAllocate(t *testing.T) { | ||||
| 	require.Equal(t, resp, respOut) | ||||
| } | ||||
|  | ||||
| func TestGetPreferredAllocation(t *testing.T) { | ||||
| 	socket := path.Join("/tmp", esocketName) | ||||
| 	callbackCount := 0 | ||||
| 	callbackChan := make(chan int) | ||||
| 	p, e := esetup(t, []*pluginapi.Device{}, socket, "mock", func(n string, d []pluginapi.Device) { | ||||
| 		callbackCount++ | ||||
| 		callbackChan <- callbackCount | ||||
| 	}) | ||||
| 	defer ecleanup(t, p, e) | ||||
|  | ||||
| 	resp := &pluginapi.PreferredAllocationResponse{ | ||||
| 		ContainerResponses: []*pluginapi.ContainerPreferredAllocationResponse{ | ||||
| 			{DeviceIDs: []string{"device0", "device1", "device2"}}, | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	p.SetGetPreferredAllocFunc(func(r *pluginapi.PreferredAllocationRequest, devs map[string]pluginapi.Device) (*pluginapi.PreferredAllocationResponse, error) { | ||||
| 		return resp, nil | ||||
| 	}) | ||||
|  | ||||
| 	go e.run() | ||||
| 	// Wait for the callback to be issued. | ||||
| 	select { | ||||
| 	case <-callbackChan: | ||||
| 		break | ||||
| 	case <-time.After(time.Second): | ||||
| 		t.FailNow() | ||||
| 	} | ||||
|  | ||||
| 	respOut, err := e.getPreferredAllocation([]string{}, []string{}, -1) | ||||
| 	require.NoError(t, err) | ||||
| 	require.Equal(t, resp, respOut) | ||||
| } | ||||
|  | ||||
| func esetup(t *testing.T, devs []*pluginapi.Device, socket, resourceName string, callback monitorCallback) (*Stub, *endpointImpl) { | ||||
| 	p := NewDevicePluginStub(devs, socket, resourceName, false, false) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user