Skip to content

Latest commit

 

History

History
23 lines (14 loc) · 1.18 KB

Developer.md

File metadata and controls

23 lines (14 loc) · 1.18 KB

Developer Readme

Using Mockery

Mockery (https://github.com/vektra/mockery) is used to auto-generate mock files for golang interfaces. The advantage of using Mockery is that there will be no need to manually write boilerplate code for mocking interfaces.

Reading the readme file in Mockery is recommended to understand how to get started with Mockery.

For each package, there may be a "mocks" folder with mock files generated by Mockery. To generate the mock for a particular interface the following command format should be used at the root project directory:

docker run -v "$PWD":/src -w /src vektra/mockery --recursive=true --name=<Interface Name> --output=./pkg/<Package name where the interface is defined>/mocks/ --filename=<Interface Name>_mock.go --exported

An example for mocking the "pciUtils" interface in the "sriov" package is as follows:

docker run -v "$PWD":/src -w /src vektra/mockery --recursive=true --name=pciUtils --output=./pkg/sriov/mocks/ --filename=pci_utils_mock.go --exported

This will create the "mocks" directory if not present and will auto-generate the mock file "pci_utils_mock.go" for the "pciUtils" interface.