-func TestSimpleRequest(t *testing.T) {
- ctx := setupTest(t, false)
- defer ctx.teardownTest()
-
- ctx.mockVpp.MockReply(&vpe.ControlPingReply{Retval: -5})
-
- req := &vpe.ControlPing{}
- reply := &vpe.ControlPingReply{}
-
- // send the request and receive a reply
- ctx.ch.GetRequestChannel() <- &api.VppRequest{Message: req}
- vppReply := <-ctx.ch.GetReplyChannel()
-
- Expect(vppReply).ShouldNot(BeNil())
- Expect(vppReply.Error).ShouldNot(HaveOccurred())
-
- // decode the message
- err := ctx.ch.GetMessageDecoder().DecodeMsg(vppReply.Data, reply)
- Expect(err).ShouldNot(HaveOccurred())
-
- Expect(reply.Retval).To(BeEquivalentTo(-5))
-}
-
-func TestMultiRequest(t *testing.T) {
- ctx := setupTest(t, false)
- defer ctx.teardownTest()
-
- msgs := []api.Message{}
- for m := 0; m < 10; m++ {
- msgs = append(msgs, &interfaces.SwInterfaceDetails{})
- }
- ctx.mockVpp.MockReply(msgs...)
- ctx.mockVpp.MockReply(&vpe.ControlPingReply{})
-
- // send multipart request
- ctx.ch.GetRequestChannel() <- &api.VppRequest{Message: &interfaces.SwInterfaceDump{}, Multipart: true}
-
- cnt := 0
- for {
- // receive a reply
- vppReply := <-ctx.ch.GetReplyChannel()
- if vppReply.LastReplyReceived {
- break // break out of the loop
- }
- Expect(vppReply.Error).ShouldNot(HaveOccurred())
-
- // decode the message
- reply := &interfaces.SwInterfaceDetails{}
- err := ctx.ch.GetMessageDecoder().DecodeMsg(vppReply.Data, reply)
- Expect(err).ShouldNot(HaveOccurred())
- cnt++
- }
-
- Expect(cnt).To(BeEquivalentTo(10))
-}
-
-func TestNotifications(t *testing.T) {
- ctx := setupTest(t, false)
- defer ctx.teardownTest()
-
- // subscribe for notification
- notifChan := make(chan api.Message, 1)
- subscription := &api.NotifSubscription{
- NotifChan: notifChan,
- MsgFactory: interfaces.NewSwInterfaceSetFlags,
- }
- ctx.ch.GetNotificationChannel() <- &api.NotifSubscribeRequest{
- Subscription: subscription,
- Subscribe: true,
- }
- err := <-ctx.ch.GetNotificationReplyChannel()
- Expect(err).ShouldNot(HaveOccurred())
-
- // mock the notification and force its delivery
- ctx.mockVpp.MockReply(&interfaces.SwInterfaceSetFlags{
- SwIfIndex: 3,
- AdminUpDown: 1,
- })
- ctx.mockVpp.SendMsg(0, []byte{0})
-
- // receive the notification
- notif := (<-notifChan).(*interfaces.SwInterfaceSetFlags)
-
- Expect(notif.SwIfIndex).To(BeEquivalentTo(3))
-
- // unsubscribe notification
- ctx.ch.GetNotificationChannel() <- &api.NotifSubscribeRequest{
- Subscription: subscription,
- Subscribe: false,
- }
- err = <-ctx.ch.GetNotificationReplyChannel()
- Expect(err).ShouldNot(HaveOccurred())
-}
-