7 "git.fd.io/govpp.git/api"
8 "git.fd.io/govpp.git/codec"
9 "git.fd.io/govpp.git/examples/binapi/ip"
10 "git.fd.io/govpp.git/examples/binapi/vpe"
15 Label []byte `struc:"[16]byte"`
19 func (*MyMsg) GetMessageName() string {
22 func (*MyMsg) GetCrcString() string {
25 func (*MyMsg) GetMessageType() api.MessageType {
26 return api.OtherMessage
29 func TestEncode(t *testing.T) {
37 msg: &MyMsg{Index: 1, Label: []byte("Abcdef"), Port: 1000},
39 expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
41 {name: "show version",
42 msg: &vpe.ShowVersion{},
44 expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
47 msg: &ip.IPRouteAddDel{
58 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},
62 BsidAddr: sr.IP6Address{},
67 Sids: sr.Srv6SidList{},
70 expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
73 for _, test := range tests {
74 t.Run(test.name, func(t *testing.T) {
75 c := codec.DefaultCodec
77 data, err := c.EncodeMsg(test.msg, test.msgID)
79 t.Fatalf("expected nil error, got: %v", err)
81 if !bytes.Equal(data, test.expData) {
82 t.Fatalf("expected data: % 0X, got: % 0X", test.expData, data)
88 func TestEncodePanic(t *testing.T) {
89 c := codec.DefaultCodec
91 msg := &MyMsg{Index: 1, Label: []byte("thisIsLongerThan16Bytes"), Port: 1000}
93 _, err := c.EncodeMsg(msg, 100)
95 t.Fatalf("expected non-nil error, got: %v", err)