devices

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 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 IsOverrideApplied

func IsOverrideApplied() bool

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()

func SetIsOverrideAppliedForTest

func SetIsOverrideAppliedForTest(testFunc func() bool) 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
	IsOverrideApplied() bool
}

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)

	// IsOverrideAppliedFunc mocks the IsOverrideApplied method.
	IsOverrideAppliedFunc func() bool
	// 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")
		},
		IsOverrideAppliedFunc: func() bool {
			panic("mock out the IsOverrideApplied 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())

func (*InterfaceMock) IsOverrideApplied

func (mock *InterfaceMock) IsOverrideApplied() bool

IsOverrideApplied calls IsOverrideAppliedFunc.

func (*InterfaceMock) IsOverrideAppliedCalls

func (mock *InterfaceMock) IsOverrideAppliedCalls() []struct {
}

IsOverrideAppliedCalls gets all the calls that were made to IsOverrideApplied. Check the length with:

len(mockedInterface.IsOverrideAppliedCalls())

Jump to

Keyboard shortcuts

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