mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 08:18:32 +00:00
Add String function to oci.Runtime interface
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
f55aac0232
commit
8df5e33ef6
@ -16,10 +16,11 @@
|
||||
|
||||
package oci
|
||||
|
||||
//go:generate moq -stub -out runtime_mock.go . Runtime
|
||||
|
||||
// Runtime is an interface for a runtime shim. The Exec method accepts a list
|
||||
// of command line arguments, and returns an error / nil.
|
||||
//
|
||||
//go:generate moq -rm -stub -out runtime_mock.go . Runtime
|
||||
type Runtime interface {
|
||||
Exec([]string) error
|
||||
String() string
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ var _ Runtime = &RuntimeMock{}
|
||||
// ExecFunc: func(strings []string) error {
|
||||
// panic("mock out the Exec method")
|
||||
// },
|
||||
// StringFunc: func() string {
|
||||
// panic("mock out the String method")
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// // use mockedRuntime in code that requires Runtime
|
||||
@ -30,6 +33,9 @@ type RuntimeMock struct {
|
||||
// ExecFunc mocks the Exec method.
|
||||
ExecFunc func(strings []string) error
|
||||
|
||||
// StringFunc mocks the String method.
|
||||
StringFunc func() string
|
||||
|
||||
// calls tracks calls to the methods.
|
||||
calls struct {
|
||||
// Exec holds details about calls to the Exec method.
|
||||
@ -37,8 +43,12 @@ type RuntimeMock struct {
|
||||
// Strings is the strings argument value.
|
||||
Strings []string
|
||||
}
|
||||
// String holds details about calls to the String method.
|
||||
String []struct {
|
||||
}
|
||||
}
|
||||
lockExec sync.RWMutex
|
||||
lockString sync.RWMutex
|
||||
}
|
||||
|
||||
// Exec calls ExecFunc.
|
||||
@ -75,3 +85,33 @@ func (mock *RuntimeMock) ExecCalls() []struct {
|
||||
mock.lockExec.RUnlock()
|
||||
return calls
|
||||
}
|
||||
|
||||
// String calls StringFunc.
|
||||
func (mock *RuntimeMock) String() string {
|
||||
callInfo := struct {
|
||||
}{}
|
||||
mock.lockString.Lock()
|
||||
mock.calls.String = append(mock.calls.String, callInfo)
|
||||
mock.lockString.Unlock()
|
||||
if mock.StringFunc == nil {
|
||||
var (
|
||||
sOut string
|
||||
)
|
||||
return sOut
|
||||
}
|
||||
return mock.StringFunc()
|
||||
}
|
||||
|
||||
// StringCalls gets all the calls that were made to String.
|
||||
// Check the length with:
|
||||
//
|
||||
// len(mockedRuntime.StringCalls())
|
||||
func (mock *RuntimeMock) StringCalls() []struct {
|
||||
} {
|
||||
var calls []struct {
|
||||
}
|
||||
mock.lockString.RLock()
|
||||
calls = mock.calls.String
|
||||
mock.lockString.RUnlock()
|
||||
return calls
|
||||
}
|
||||
|
@ -83,3 +83,8 @@ func (r *modifyingRuntimeWrapper) modify() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns a string representation of the runtime.
|
||||
func (r *modifyingRuntimeWrapper) String() string {
|
||||
return fmt.Sprintf("modify on-create and forward to %s", r.runtime.String())
|
||||
}
|
||||
|
@ -63,3 +63,8 @@ func (s pathRuntime) Exec(args []string) error {
|
||||
|
||||
return s.execRuntime.Exec(runtimeArgs)
|
||||
}
|
||||
|
||||
// String returns the path to the specified runtime as the string representation.
|
||||
func (s pathRuntime) String() string {
|
||||
return s.path
|
||||
}
|
||||
|
@ -37,3 +37,7 @@ func (r syscallExec) Exec(args []string) error {
|
||||
// err is nil or not.
|
||||
return fmt.Errorf("unexpected return from exec '%v'", args[0])
|
||||
}
|
||||
|
||||
func (r syscallExec) String() string {
|
||||
return "exec"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user