Documentation ¶
Overview ¶
Package nltest provides utilities for netlink testing.
Index ¶
Constants ¶
const PID = 1
PID is the netlink header PID value assigned by nltest.
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
Dial sets up a netlink.Conn for testing using the specified Func. All requests sent from the connection will be passed to the Func. The connection should be closed as usual when it is no longer needed.
func Error ¶
Error returns a netlink error to the caller with the specified error number, in the body of the specified request message.
func Multipart ¶
Multipart sends a slice of netlink.Messages to the caller as a netlink multi-part message. If less than two messages are present, the messages are not altered.
func MustMarshalAttributes ¶
MustMarshalAttributes marshals a slice of netlink.Attributes to their binary format, but panics if any errors occur.
Types ¶
type Func ¶
A Func is a function that can be used to test netlink.Conn interactions. The function can choose to return zero or more netlink messages, or an error if needed.
For a netlink request/response interaction, a request req is populated by netlink.Conn.Send and passed to the function.
For multicast interactions, an empty request req is passed to the function when netlink.Conn.Receive is called.
If a Func returns an error, the error will be returned as-is to the caller. If no messages and io.EOF are returned, no messages and no error will be returned to the caller, simulating a multi-part message with no data.
func CheckRequest ¶
func CheckRequest(types []netlink.HeaderType, flags []netlink.HeaderFlags, fn Func) Func
CheckRequest returns a Func that verifies that each message in an incoming request has the specified netlink header type and flags in the same slice position index, and then passes the request through to fn.
The length of the types and flags slices must match the number of requests passed to the returned Func, or CheckRequest will panic.
As an example:
- types[0] and flags[0] will be checked against reqs[0]
- types[1] and flags[1] will be checked against reqs[1]
- ... and so on
If an element of types or flags is set to the zero value, that check will be skipped for the request message that occurs at the same index.
As an example, if types[0] is 0 and reqs[0].Header.Type is 1, the check will succeed because types[0] was not specified.