mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-30 00:11:59 +00:00
fd135f1a8b
This adds a Relative function to the Locator interface and uses this to determine the host and container paths for located files (and devices). This ensures that the root (e.g. the nvidia driver root) is stripped from the container path. Signed-off-by: Evan Lezar <elezar@nvidia.com>
125 lines
2.7 KiB
Go
125 lines
2.7 KiB
Go
// Code generated by moq; DO NOT EDIT.
|
|
// github.com/matryer/moq
|
|
|
|
package lookup
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// Ensure, that LocatorMock does implement Locator.
|
|
// If this is not the case, regenerate this file with moq.
|
|
var _ Locator = &LocatorMock{}
|
|
|
|
// LocatorMock is a mock implementation of Locator.
|
|
//
|
|
// func TestSomethingThatUsesLocator(t *testing.T) {
|
|
//
|
|
// // make and configure a mocked Locator
|
|
// mockedLocator := &LocatorMock{
|
|
// LocateFunc: func(s string) ([]string, error) {
|
|
// panic("mock out the Locate method")
|
|
// },
|
|
// RelativeFunc: func(s string) (string, error) {
|
|
// panic("mock out the Relative method")
|
|
// },
|
|
// }
|
|
//
|
|
// // use mockedLocator in code that requires Locator
|
|
// // and then make assertions.
|
|
//
|
|
// }
|
|
type LocatorMock struct {
|
|
// LocateFunc mocks the Locate method.
|
|
LocateFunc func(s string) ([]string, error)
|
|
|
|
// RelativeFunc mocks the Relative method.
|
|
RelativeFunc func(s string) (string, error)
|
|
|
|
// calls tracks calls to the methods.
|
|
calls struct {
|
|
// Locate holds details about calls to the Locate method.
|
|
Locate []struct {
|
|
// S is the s argument value.
|
|
S string
|
|
}
|
|
// Relative holds details about calls to the Relative method.
|
|
Relative []struct {
|
|
// S is the s argument value.
|
|
S string
|
|
}
|
|
}
|
|
lockLocate sync.RWMutex
|
|
lockRelative sync.RWMutex
|
|
}
|
|
|
|
// Locate calls LocateFunc.
|
|
func (mock *LocatorMock) Locate(s string) ([]string, error) {
|
|
callInfo := struct {
|
|
S string
|
|
}{
|
|
S: s,
|
|
}
|
|
mock.lockLocate.Lock()
|
|
mock.calls.Locate = append(mock.calls.Locate, callInfo)
|
|
mock.lockLocate.Unlock()
|
|
if mock.LocateFunc == nil {
|
|
var (
|
|
stringsOut []string
|
|
errOut error
|
|
)
|
|
return stringsOut, errOut
|
|
}
|
|
return mock.LocateFunc(s)
|
|
}
|
|
|
|
// LocateCalls gets all the calls that were made to Locate.
|
|
// Check the length with:
|
|
// len(mockedLocator.LocateCalls())
|
|
func (mock *LocatorMock) LocateCalls() []struct {
|
|
S string
|
|
} {
|
|
var calls []struct {
|
|
S string
|
|
}
|
|
mock.lockLocate.RLock()
|
|
calls = mock.calls.Locate
|
|
mock.lockLocate.RUnlock()
|
|
return calls
|
|
}
|
|
|
|
// Relative calls RelativeFunc.
|
|
func (mock *LocatorMock) Relative(s string) (string, error) {
|
|
callInfo := struct {
|
|
S string
|
|
}{
|
|
S: s,
|
|
}
|
|
mock.lockRelative.Lock()
|
|
mock.calls.Relative = append(mock.calls.Relative, callInfo)
|
|
mock.lockRelative.Unlock()
|
|
if mock.RelativeFunc == nil {
|
|
var (
|
|
sOut string
|
|
errOut error
|
|
)
|
|
return sOut, errOut
|
|
}
|
|
return mock.RelativeFunc(s)
|
|
}
|
|
|
|
// RelativeCalls gets all the calls that were made to Relative.
|
|
// Check the length with:
|
|
// len(mockedLocator.RelativeCalls())
|
|
func (mock *LocatorMock) RelativeCalls() []struct {
|
|
S string
|
|
} {
|
|
var calls []struct {
|
|
S string
|
|
}
|
|
mock.lockRelative.RLock()
|
|
calls = mock.calls.Relative
|
|
mock.lockRelative.RUnlock()
|
|
return calls
|
|
}
|