devices

package
v1.19.0-rc.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertCharDevice

func AssertCharDevice(path string) error

AssertCharDevice checks whether the specified path is a char device and returns an error if this is not the case.

func SetAllForTest

func SetAllForTest() func()

func SetAssertCharDeviceForTest

func SetAssertCharDeviceForTest(testFunc func(string) error) func()

func SetDeviceFromPathForTest

func SetDeviceFromPathForTest(testFunc func(string, string) (*Device, error)) func()

func SetInterfaceForTests

func SetInterfaceForTests(m Interface) func()

Types

type Device

type Device config.Device

func DeviceFromPath

func DeviceFromPath(path string, permissions string) (*Device, error)

DeviceFromPath is a wrapper for libcontainer/devices.DeviceFromPath. It allows for overriding functionality during tests.

type Interface

type Interface interface {
	DeviceFromPath(string, string) (*Device, error)
	AssertCharDevice(string) error
}

type InterfaceMock

type InterfaceMock struct {
	// AssertCharDeviceFunc mocks the AssertCharDevice method.
	AssertCharDeviceFunc func(s string) error

	// DeviceFromPathFunc mocks the DeviceFromPath method.
	DeviceFromPathFunc func(s1 string, s2 string) (*Device, error)
	// contains filtered or unexported fields
}

InterfaceMock is a mock implementation of Interface.

func TestSomethingThatUsesInterface(t *testing.T) {

	// make and configure a mocked Interface
	mockedInterface := &InterfaceMock{
		AssertCharDeviceFunc: func(s string) error {
			panic("mock out the AssertCharDevice method")
		},
		DeviceFromPathFunc: func(s1 string, s2 string) (*Device, error) {
			panic("mock out the DeviceFromPath method")
		},
	}

	// use mockedInterface in code that requires Interface
	// and then make assertions.

}

func (*InterfaceMock) AssertCharDevice

func (mock *InterfaceMock) AssertCharDevice(s string) error

AssertCharDevice calls AssertCharDeviceFunc.

func (*InterfaceMock) AssertCharDeviceCalls

func (mock *InterfaceMock) AssertCharDeviceCalls() []struct {
	S string
}

AssertCharDeviceCalls gets all the calls that were made to AssertCharDevice. Check the length with:

len(mockedInterface.AssertCharDeviceCalls())

func (*InterfaceMock) DeviceFromPath

func (mock *InterfaceMock) DeviceFromPath(s1 string, s2 string) (*Device, error)

DeviceFromPath calls DeviceFromPathFunc.

func (*InterfaceMock) DeviceFromPathCalls

func (mock *InterfaceMock) DeviceFromPathCalls() []struct {
	S1 string
	S2 string
}

DeviceFromPathCalls gets all the calls that were made to DeviceFromPath. Check the length with:

len(mockedInterface.DeviceFromPathCalls())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL