mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-23 00:38:26 +00:00
95394e0fc8
This change adds basic functionality to process the /proc/devices file to extract device majors. Signed-off-by: Evan Lezar <elezar@nvidia.com>
126 lines
2.5 KiB
Go
126 lines
2.5 KiB
Go
// Code generated by moq; DO NOT EDIT.
|
|
// github.com/matryer/moq
|
|
|
|
package devices
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// Ensure, that DevicesMock does implement Devices.
|
|
// If this is not the case, regenerate this file with moq.
|
|
var _ Devices = &DevicesMock{}
|
|
|
|
// DevicesMock is a mock implementation of Devices.
|
|
//
|
|
// func TestSomethingThatUsesDevices(t *testing.T) {
|
|
//
|
|
// // make and configure a mocked Devices
|
|
// mockedDevices := &DevicesMock{
|
|
// ExistsFunc: func(name Name) bool {
|
|
// panic("mock out the Exists method")
|
|
// },
|
|
// GetFunc: func(name Name) (Major, bool) {
|
|
// panic("mock out the Get method")
|
|
// },
|
|
// }
|
|
//
|
|
// // use mockedDevices in code that requires Devices
|
|
// // and then make assertions.
|
|
//
|
|
// }
|
|
type DevicesMock struct {
|
|
// ExistsFunc mocks the Exists method.
|
|
ExistsFunc func(name Name) bool
|
|
|
|
// GetFunc mocks the Get method.
|
|
GetFunc func(name Name) (Major, bool)
|
|
|
|
// calls tracks calls to the methods.
|
|
calls struct {
|
|
// Exists holds details about calls to the Exists method.
|
|
Exists []struct {
|
|
// Name is the name argument value.
|
|
Name Name
|
|
}
|
|
// Get holds details about calls to the Get method.
|
|
Get []struct {
|
|
// Name is the name argument value.
|
|
Name Name
|
|
}
|
|
}
|
|
lockExists sync.RWMutex
|
|
lockGet sync.RWMutex
|
|
}
|
|
|
|
// Exists calls ExistsFunc.
|
|
func (mock *DevicesMock) Exists(name Name) bool {
|
|
callInfo := struct {
|
|
Name Name
|
|
}{
|
|
Name: name,
|
|
}
|
|
mock.lockExists.Lock()
|
|
mock.calls.Exists = append(mock.calls.Exists, callInfo)
|
|
mock.lockExists.Unlock()
|
|
if mock.ExistsFunc == nil {
|
|
var (
|
|
bOut bool
|
|
)
|
|
return bOut
|
|
}
|
|
return mock.ExistsFunc(name)
|
|
}
|
|
|
|
// ExistsCalls gets all the calls that were made to Exists.
|
|
// Check the length with:
|
|
//
|
|
// len(mockedDevices.ExistsCalls())
|
|
func (mock *DevicesMock) ExistsCalls() []struct {
|
|
Name Name
|
|
} {
|
|
var calls []struct {
|
|
Name Name
|
|
}
|
|
mock.lockExists.RLock()
|
|
calls = mock.calls.Exists
|
|
mock.lockExists.RUnlock()
|
|
return calls
|
|
}
|
|
|
|
// Get calls GetFunc.
|
|
func (mock *DevicesMock) Get(name Name) (Major, bool) {
|
|
callInfo := struct {
|
|
Name Name
|
|
}{
|
|
Name: name,
|
|
}
|
|
mock.lockGet.Lock()
|
|
mock.calls.Get = append(mock.calls.Get, callInfo)
|
|
mock.lockGet.Unlock()
|
|
if mock.GetFunc == nil {
|
|
var (
|
|
majorOut Major
|
|
bOut bool
|
|
)
|
|
return majorOut, bOut
|
|
}
|
|
return mock.GetFunc(name)
|
|
}
|
|
|
|
// GetCalls gets all the calls that were made to Get.
|
|
// Check the length with:
|
|
//
|
|
// len(mockedDevices.GetCalls())
|
|
func (mock *DevicesMock) GetCalls() []struct {
|
|
Name Name
|
|
} {
|
|
var calls []struct {
|
|
Name Name
|
|
}
|
|
mock.lockGet.RLock()
|
|
calls = mock.calls.Get
|
|
mock.lockGet.RUnlock()
|
|
return calls
|
|
}
|