X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=codec%2Fmsg_codec_test.go;h=46a61547a9c9d34efba5bfe6b9aefe1d953958bb;hb=HEAD;hp=bf0695d9f797a73f61c2e5796ba1f811b30130be;hpb=94620e85f0bdbb054af07ce3670fadc1f76cfdf0;p=govpp.git diff --git a/codec/msg_codec_test.go b/codec/msg_codec_test.go index bf0695d..46a6154 100644 --- a/codec/msg_codec_test.go +++ b/codec/msg_codec_test.go @@ -4,13 +4,12 @@ import ( "bytes" "testing" - "github.com/lunixbochs/struc" - - "git.fd.io/govpp.git/api" - "git.fd.io/govpp.git/codec" - "git.fd.io/govpp.git/examples/binapi/ip" - "git.fd.io/govpp.git/examples/binapi/sr" - "git.fd.io/govpp.git/examples/binapi/vpe" + "go.fd.io/govpp/api" + "go.fd.io/govpp/binapi/ip" + "go.fd.io/govpp/binapi/ip_types" + "go.fd.io/govpp/binapi/sr" + "go.fd.io/govpp/binapi/vpe" + "go.fd.io/govpp/codec" ) type MyMsg struct { @@ -36,11 +35,11 @@ func TestEncode(t *testing.T) { msgID uint16 expData []byte }{ - /*{name: "basic", + {name: "basic", msg: &MyMsg{Index: 1, Label: []byte("Abcdef"), Port: 1000}, msgID: 100, expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8}, - },*/ + }, {name: "show version", msg: &vpe.ShowVersion{}, msgID: 743, @@ -53,66 +52,45 @@ func TestEncode(t *testing.T) { Route: ip.IPRoute{ TableID: 0, StatsIndex: 0, - Prefix: ip.Prefix{}, + Prefix: ip_types.Prefix{}, NPaths: 0, - Paths: []ip.FibPath{ - { - SwIfIndex: 0, - TableID: 0, - RpfID: 0, - Weight: 0, - Preference: 0, - Type: 0, - Flags: 0, - Proto: 0, - Nh: ip.FibPathNh{}, - NLabels: 5, - LabelStack: [16]ip.FibMplsLabel{ - { - IsUniform: 1, - Label: 2, - TTL: 3, - Exp: 4, - }, - }, - }, - }, }, }, msgID: 743, - expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + 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) { - c := &codec.MsgCodec{} - //c := &codec.NewCodec{} + c := codec.DefaultCodec data, err := c.EncodeMsg(test.msg, test.msgID) if err != nil { 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) } }) } } func TestEncodePanic(t *testing.T) { - c := &codec.MsgCodec{} + c := codec.DefaultCodec msg := &MyMsg{Index: 1, Label: []byte("thisIsLongerThan16Bytes"), Port: 1000} @@ -120,17 +98,5 @@ func TestEncodePanic(t *testing.T) { if err == nil { t.Fatalf("expected non-nil error, got: %v", err) } -} - -func TestEncodeSr(t *testing.T) { - msg := sr.Srv6SidList{ - NumSids: 0, - Weight: 0, - //Sids: nil, - } - buf := new(bytes.Buffer) - - if err := struc.Pack(buf, msg); err != nil { - t.Fatal(err) - } + t.Logf("err: %v", err) }