7 "github.com/lunixbochs/struc"
9 "git.fd.io/govpp.git/api"
10 "git.fd.io/govpp.git/codec"
11 "git.fd.io/govpp.git/examples/binapi/ip"
12 "git.fd.io/govpp.git/examples/binapi/sr"
13 "git.fd.io/govpp.git/examples/binapi/vpe"
18 Label []byte `struc:"[16]byte"`
22 func (*MyMsg) GetMessageName() string {
25 func (*MyMsg) GetCrcString() string {
28 func (*MyMsg) GetMessageType() api.MessageType {
29 return api.OtherMessage
32 func TestEncode(t *testing.T) {
40 msg: &MyMsg{Index: 1, Label: []byte("Abcdef"), Port: 1000},
42 expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
44 {name: "show version",
45 msg: &vpe.ShowVersion{},
47 expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
50 msg: &ip.IPRouteAddDel{
70 LabelStack: [16]ip.FibMplsLabel{
83 expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
87 BsidAddr: sr.IP6Address{},
92 Sids: sr.Srv6SidList{},
95 expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
98 for _, test := range tests {
99 t.Run(test.name, func(t *testing.T) {
100 c := &codec.MsgCodec{}
101 //c := &codec.NewCodec{}
103 data, err := c.EncodeMsg(test.msg, test.msgID)
105 t.Fatalf("expected nil error, got: %v", err)
107 if !bytes.Equal(data, test.expData) {
108 t.Fatalf("expected data: % 0X, got: % 0X", test.expData, data)
114 func TestEncodePanic(t *testing.T) {
115 c := &codec.MsgCodec{}
117 msg := &MyMsg{Index: 1, Label: []byte("thisIsLongerThan16Bytes"), Port: 1000}
119 _, err := c.EncodeMsg(msg, 100)
121 t.Fatalf("expected non-nil error, got: %v", err)
125 func TestEncodeSr(t *testing.T) {
126 msg := sr.Srv6SidList{
131 buf := new(bytes.Buffer)
133 if err := struc.Pack(buf, msg); err != nil {