Binary API generator improvements
[govpp.git] / core / connection_test.go
index 929f468..453bbce 100644 (file)
 package core_test
 
 import (
+       "git.fd.io/govpp.git/examples/binapi/interface_types"
        "testing"
 
+       . "github.com/onsi/gomega"
+
        "git.fd.io/govpp.git/adapter/mock"
        "git.fd.io/govpp.git/api"
        "git.fd.io/govpp.git/codec"
        "git.fd.io/govpp.git/core"
-       "git.fd.io/govpp.git/examples/bin_api/interfaces"
-       "git.fd.io/govpp.git/examples/bin_api/vpe"
-       . "github.com/onsi/gomega"
+       "git.fd.io/govpp.git/examples/binapi/interfaces"
+       "git.fd.io/govpp.git/examples/binapi/vpe"
 )
 
 type testCtx struct {
@@ -78,7 +80,7 @@ func TestAsyncConnection(t *testing.T) {
        defer ctx.teardownTest()
 
        ctx.conn.Disconnect()
-       conn, statusChan, err := core.AsyncConnect(ctx.mockVpp)
+       conn, statusChan, err := core.AsyncConnect(ctx.mockVpp, core.DefaultMaxReconnectAttempts, core.DefaultReconnectInterval)
        ctx.conn = conn
 
        Expect(err).ShouldNot(HaveOccurred())
@@ -91,17 +93,17 @@ func TestAsyncConnection(t *testing.T) {
 func TestCodec(t *testing.T) {
        RegisterTestingT(t)
 
-       msgCodec := &codec.MsgCodec{}
+       var msgCodec = codec.DefaultCodec
 
        // request
-       data, err := msgCodec.EncodeMsg(&interfaces.CreateLoopback{MacAddress: []byte{1, 2, 3, 4, 5, 6}}, 11)
+       data, err := msgCodec.EncodeMsg(&interfaces.CreateLoopback{MacAddress: interfaces.MacAddress{1, 2, 3, 4, 5, 6}}, 11)
        Expect(err).ShouldNot(HaveOccurred())
        Expect(data).ShouldNot(BeEmpty())
 
        msg1 := &interfaces.CreateLoopback{}
        err = msgCodec.DecodeMsg(data, msg1)
        Expect(err).ShouldNot(HaveOccurred())
-       Expect(msg1.MacAddress).To(BeEquivalentTo([]byte{1, 2, 3, 4, 5, 6}))
+       Expect(msg1.MacAddress).To(BeEquivalentTo(interfaces.MacAddress{1, 2, 3, 4, 5, 6}))
 
        // reply
        data, err = msgCodec.EncodeMsg(&vpe.ControlPingReply{Retval: 55}, 22)
@@ -117,7 +119,7 @@ func TestCodec(t *testing.T) {
 func TestCodecNegative(t *testing.T) {
        RegisterTestingT(t)
 
-       msgCodec := &codec.MsgCodec{}
+       var msgCodec = codec.DefaultCodec
 
        // nil message for encoding
        data, err := msgCodec.EncodeMsg(nil, 15)
@@ -133,7 +135,7 @@ func TestCodecNegative(t *testing.T) {
        // nil data for decoding
        err = msgCodec.DecodeMsg(nil, &vpe.ControlPingReply{})
        Expect(err).Should(HaveOccurred())
-       Expect(err.Error()).To(ContainSubstring("EOF"))
+       Expect(err.Error()).To(ContainSubstring("panic"))
 }
 
 func TestSimpleRequestsWithSequenceNumbers(t *testing.T) {
@@ -160,7 +162,7 @@ func TestMultiRequestsWithSequenceNumbers(t *testing.T) {
 
        var msgs []api.Message
        for i := 0; i < 10; i++ {
-               msgs = append(msgs, &interfaces.SwInterfaceDetails{SwIfIndex: uint32(i)})
+               msgs = append(msgs, &interfaces.SwInterfaceDetails{SwIfIndex: interface_types.InterfaceIndex(i)})
        }
        ctx.mockVpp.MockReply(msgs...)
        ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
@@ -279,7 +281,7 @@ func TestMultiRequestsWithErrors(t *testing.T) {
        }
        for i := 0; i < 10; i++ {
                msgs = append(msgs, mock.MsgWithContext{
-                       Msg:       &interfaces.SwInterfaceDetails{SwIfIndex: uint32(i)},
+                       Msg:       &interfaces.SwInterfaceDetails{SwIfIndex: interface_types.InterfaceIndex(i)},
                        SeqNum:    1,
                        Multipart: true,
                })