5 "git.fd.io/govpp.git/examples/binapi/ip_types"
8 "git.fd.io/govpp.git/api"
9 "git.fd.io/govpp.git/codec"
10 "git.fd.io/govpp.git/examples/binapi/ip"
11 "git.fd.io/govpp.git/examples/binapi/vpe"
16 Label []byte `struc:"[16]byte"`
20 func (*MyMsg) GetMessageName() string {
23 func (*MyMsg) GetCrcString() string {
26 func (*MyMsg) GetMessageType() api.MessageType {
27 return api.OtherMessage
30 func TestEncode(t *testing.T) {
38 msg: &MyMsg{Index: 1, Label: []byte("Abcdef"), Port: 1000},
40 expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
42 {name: "show version",
43 msg: &vpe.ShowVersion{},
45 expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
48 msg: &ip.IPRouteAddDel{
54 Prefix: ip_types.Prefix{},
59 expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
63 BsidAddr: sr.IP6Address{},
68 Sids: sr.Srv6SidList{},
71 expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
74 for _, test := range tests {
75 t.Run(test.name, func(t *testing.T) {
76 c := codec.DefaultCodec
78 data, err := c.EncodeMsg(test.msg, test.msgID)
80 t.Fatalf("expected nil error, got: %v", err)
82 if !bytes.Equal(data, test.expData) {
83 t.Fatalf("expected data: % 0X, got: % 0X", test.expData, data)
89 func TestEncodePanic(t *testing.T) {
90 c := codec.DefaultCodec
92 msg := &MyMsg{Index: 1, Label: []byte("thisIsLongerThan16Bytes"), Port: 1000}
94 _, err := c.EncodeMsg(msg, 100)
96 t.Fatalf("expected non-nil error, got: %v", err)