aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/netlink/netlink_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/netlink/netlink_test.go')
-rw-r--r--internal/netlink/netlink_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/netlink/netlink_test.go b/internal/netlink/netlink_test.go
new file mode 100644
index 00000000..0926e3bd
--- /dev/null
+++ b/internal/netlink/netlink_test.go
@@ -0,0 +1,36 @@
+package netlink
+
+import (
+ "os"
+ "syscall"
+ "testing"
+)
+
+func init() { nlPidOnce.Do(func() {}); nlPid = 1 }
+
+type payloadTestCase struct {
+ name string
+ f func(c *conn)
+ want []byte
+}
+
+// checkPayload runs multiple payloadTestCase against a stub conn and checks
+// the outgoing message written to its buffer page.
+func checkPayload(t *testing.T, testCases []payloadTestCase) {
+ t.Helper()
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+
+ c := conn{
+ pos: syscall.NLMSG_HDRLEN,
+ buf: make([]byte, os.Getpagesize()),
+ }
+ tc.f(&c)
+ if got := c.pending(); string(got) != string(tc.want) {
+ t.Errorf("pending: %#v, want %#v", got, tc.want)
+ }
+ })
+ }
+}