File: bridge_linux_test.go

package info (click to toggle)
golang-github-vishvananda-netlink 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 1,648 kB
  • sloc: makefile: 25
file content (35 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package nl

import (
	"bytes"
	"crypto/rand"
	"encoding/binary"
	"testing"
)

func (msg *BridgeVlanInfo) write(b []byte) {
	native := NativeEndian()
	native.PutUint16(b[0:2], msg.Flags)
	native.PutUint16(b[2:4], msg.Vid)
}

func (msg *BridgeVlanInfo) serializeSafe() []byte {
	length := SizeofBridgeVlanInfo
	b := make([]byte, length)
	msg.write(b)
	return b
}

func deserializeBridgeVlanInfoSafe(b []byte) *BridgeVlanInfo {
	var msg = BridgeVlanInfo{}
	binary.Read(bytes.NewReader(b[0:SizeofBridgeVlanInfo]), NativeEndian(), &msg)
	return &msg
}

func TestBridgeVlanInfoDeserializeSerialize(t *testing.T) {
	var orig = make([]byte, SizeofBridgeVlanInfo)
	rand.Read(orig)
	safemsg := deserializeBridgeVlanInfoSafe(orig)
	msg := DeserializeBridgeVlanInfo(orig)
	testDeserializeSerialize(t, orig, safemsg, msg)
}