Improve binapi generator
[govpp.git] / codec / msg_codec_test.go
index c950fd8..c0f94da 100644 (file)
@@ -2,13 +2,14 @@ package codec_test
 
 import (
        "bytes"
-       "git.fd.io/govpp.git/examples/binapi/ip_types"
        "testing"
 
        "git.fd.io/govpp.git/api"
+       "git.fd.io/govpp.git/binapi/ip"
+       "git.fd.io/govpp.git/binapi/ip_types"
+       "git.fd.io/govpp.git/binapi/sr"
+       "git.fd.io/govpp.git/binapi/vpe"
        "git.fd.io/govpp.git/codec"
-       "git.fd.io/govpp.git/examples/binapi/ip"
-       "git.fd.io/govpp.git/examples/binapi/vpe"
 )
 
 type MyMsg struct {
@@ -58,18 +59,20 @@ func TestEncode(t *testing.T) {
                        msgID:   743,
                        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},
                },
-               /*{name: "sr",
+               {name: "sr",
                        msg: &sr.SrPolicyAdd{
-                               BsidAddr: sr.IP6Address{},
-                               Weight:   0,
+                               BsidAddr: ip_types.IP6Address{},
+                               Weight:   3,
                                IsEncap:  false,
-                               IsSpray:  false,
-                               FibTable: 0,
-                               Sids:     sr.Srv6SidList{},
+                               IsSpray:  true,
+                               FibTable: 5,
+                               Sids:     sr.Srv6SidList{Weight: 2},
                        },
-                       msgID:   99,
-                       expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8},
-               },*/
+                       msgID: 99,
+                       expData: []byte{
+                               0x00, 0x63, 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, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x02, 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, 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, 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, 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, 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, 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, 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, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+               },
        }
        for _, test := range tests {
                t.Run(test.name, func(t *testing.T) {
@@ -80,7 +83,7 @@ func TestEncode(t *testing.T) {
                                t.Fatalf("expected nil error, got: %v", err)
                        }
                        if !bytes.Equal(data, test.expData) {
-                               t.Fatalf("expected data: % 0X, got: % 0X", test.expData, data)
+                               t.Fatalf("expected data:\n% 0X, got:\n% 0X", test.expData, data)
                        }
                })
        }
@@ -95,4 +98,5 @@ func TestEncodePanic(t *testing.T) {
        if err == nil {
                t.Fatalf("expected non-nil error, got: %v", err)
        }
+       t.Logf("err: %v", err)
 }