mock adapter: Group all replies for one request under one call to MockReply
[govpp.git] / api / api_test.go
index a439986..7cbd9f0 100644 (file)
@@ -196,12 +196,14 @@ func TestMultiRequestReplySwInterfaceTapDump(t *testing.T) {
        defer ctx.teardownTest()
 
        // mock reply
+       msgs := []api.Message{}
        for i := 1; i <= 10; i++ {
-               ctx.mockVpp.MockReply(&tap.SwInterfaceTapDetails{
+               msgs = append(msgs, &tap.SwInterfaceTapDetails{
                        SwIfIndex: uint32(i),
                        DevName:   []byte("dev-name-test"),
                })
        }
+       ctx.mockVpp.MockReply(msgs...)
        ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
 
        reqCtx := ctx.ch.SendMultiRequest(&tap.SwInterfaceTapDump{})
@@ -223,11 +225,13 @@ func TestMultiRequestReplySwInterfaceMemifDump(t *testing.T) {
        defer ctx.teardownTest()
 
        // mock reply
+       msgs := []api.Message{}
        for i := 1; i <= 10; i++ {
-               ctx.mockVpp.MockReply(&memif.MemifDetails{
+               msgs = append(msgs, &memif.MemifDetails{
                        SwIfIndex: uint32(i),
                })
        }
+       ctx.mockVpp.MockReply(msgs...)
        ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
 
        reqCtx := ctx.ch.SendMultiRequest(&memif.MemifDump{})
@@ -344,12 +348,14 @@ func TestSetReplyTimeoutMultiRequest(t *testing.T) {
 
        ctx.ch.SetReplyTimeout(time.Millisecond)
 
+       msgs := []api.Message{}
        for i := 1; i <= 3; i++ {
-               ctx.mockVpp.MockReply(&interfaces.SwInterfaceDetails{
+               msgs = append(msgs, &interfaces.SwInterfaceDetails{
                        SwIfIndex:     uint32(i),
                        InterfaceName: []byte("if-name-test"),
                })
        }
+       ctx.mockVpp.MockReply(msgs...)
        ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
 
        cnt := 0
@@ -409,20 +415,33 @@ func TestMultiRequestDouble(t *testing.T) {
        defer ctx.teardownTest()
 
        // mock reply
+       msgs := []mock.MsgWithContext{}
        for i := 1; i <= 3; i++ {
-               ctx.mockVpp.MockReply(&interfaces.SwInterfaceDetails{
-                       SwIfIndex:     uint32(i),
-                       InterfaceName: []byte("if-name-test"),
+               msgs = append(msgs, mock.MsgWithContext{
+                       Msg: &interfaces.SwInterfaceDetails{
+                               SwIfIndex:     uint32(i),
+                               InterfaceName: []byte("if-name-test"),
+                       },
+                       Multipart: true,
+                       SeqNum:    1,
                })
        }
-       ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
+       msgs = append(msgs, mock.MsgWithContext{Msg: &vpe.ControlPingReply{}, Multipart: true, SeqNum: 1})
+
        for i := 1; i <= 3; i++ {
-               ctx.mockVpp.MockReply(&interfaces.SwInterfaceDetails{
-                       SwIfIndex:     uint32(i),
-                       InterfaceName: []byte("if-name-test"),
-               })
+               msgs = append(msgs,
+                       mock.MsgWithContext{
+                               Msg: &interfaces.SwInterfaceDetails{
+                                       SwIfIndex:     uint32(i),
+                                       InterfaceName: []byte("if-name-test"),
+                               },
+                               Multipart: true,
+                               SeqNum:    2,
+                       })
        }
-       ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
+       msgs = append(msgs, mock.MsgWithContext{Msg: &vpe.ControlPingReply{}, Multipart: true, SeqNum: 2})
+
+       ctx.mockVpp.MockReplyWithContext(msgs...)
 
        cnt := 0
        var sendMultiRequest = func() error {
@@ -457,7 +476,7 @@ func TestReceiveReplyAfterTimeout(t *testing.T) {
        ctx.ch.SetReplyTimeout(time.Millisecond)
 
        // first one request should work
-       ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
+       ctx.mockVpp.MockReplyWithContext(mock.MsgWithContext{Msg: &vpe.ControlPingReply{}, SeqNum: 1})
        err := ctx.ch.SendRequest(&vpe.ControlPing{}).ReceiveReply(&vpe.ControlPingReply{})
        Expect(err).ShouldNot(HaveOccurred())
 
@@ -465,11 +484,11 @@ func TestReceiveReplyAfterTimeout(t *testing.T) {
        Expect(err).Should(HaveOccurred())
        Expect(err.Error()).To(ContainSubstring("timeout"))
 
-       // simulating late reply
-       ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
-
-       // normal reply for next request
-       ctx.mockVpp.MockReply(&tap.TapConnectReply{})
+       ctx.mockVpp.MockReplyWithContext(
+               // simulating late reply
+               mock.MsgWithContext{Msg: &vpe.ControlPingReply{}, SeqNum: 2},
+               // normal reply for next request
+               mock.MsgWithContext{Msg: &tap.TapConnectReply{}, SeqNum: 3})
 
        req := &tap.TapConnect{
                TapName:      []byte("test-tap-name"),
@@ -497,7 +516,7 @@ func TestReceiveReplyAfterTimeoutMultiRequest(t *testing.T) {
        ctx.ch.SetReplyTimeout(time.Millisecond * 100)
 
        // first one request should work
-       ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
+       ctx.mockVpp.MockReplyWithContext(mock.MsgWithContext{Msg: &vpe.ControlPingReply{}, SeqNum: 1})
        err := ctx.ch.SendRequest(&vpe.ControlPing{}).ReceiveReply(&vpe.ControlPingReply{})
        Expect(err).ShouldNot(HaveOccurred())
 
@@ -524,16 +543,22 @@ func TestReceiveReplyAfterTimeoutMultiRequest(t *testing.T) {
        Expect(cnt).To(BeEquivalentTo(0))
 
        // simulating late replies
+       msgs := []mock.MsgWithContext{}
        for i := 1; i <= 3; i++ {
-               ctx.mockVpp.MockReply(&interfaces.SwInterfaceDetails{
-                       SwIfIndex:     uint32(i),
-                       InterfaceName: []byte("if-name-test"),
+               msgs = append(msgs, mock.MsgWithContext{
+                       Msg: &interfaces.SwInterfaceDetails{
+                               SwIfIndex:     uint32(i),
+                               InterfaceName: []byte("if-name-test"),
+                       },
+                       Multipart: true,
+                       SeqNum:    2,
                })
        }
-       ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
+       msgs = append(msgs, mock.MsgWithContext{Msg: &vpe.ControlPingReply{}, Multipart: true, SeqNum: 2})
+       ctx.mockVpp.MockReplyWithContext(msgs...)
 
        // normal reply for next request
-       ctx.mockVpp.MockReply(&tap.TapConnectReply{})
+       ctx.mockVpp.MockReplyWithContext(mock.MsgWithContext{Msg: &tap.TapConnectReply{}, SeqNum: 3})
 
        req := &tap.TapConnect{
                TapName:      []byte("test-tap-name"),