X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=api%2Fapi_test.go;h=3e77f48e005aaea87ed608a61b853484d04155f4;hb=8c63ab9ebee218b7e1c5fcf17594d76348b9f726;hp=2a342f69312f0ae98d2f05d6795d2e0b21b77d8f;hpb=13ab652c89a8bf5b16017156f8fb388e1889a8e1;p=govpp.git diff --git a/api/api_test.go b/api/api_test.go index 2a342f6..3e77f48 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -18,7 +18,6 @@ import ( "testing" "time" - "git.fd.io/govpp.git" "git.fd.io/govpp.git/adapter/mock" "git.fd.io/govpp.git/api" "git.fd.io/govpp.git/core" @@ -39,12 +38,12 @@ type testCtx struct { func setupTest(t *testing.T) *testCtx { RegisterTestingT(t) - ctx := &testCtx{} - ctx.mockVpp = &mock.VppAdapter{} - govpp.SetAdapter(ctx.mockVpp) + ctx := &testCtx{ + mockVpp: &mock.VppAdapter{}, + } var err error - ctx.conn, err = govpp.Connect() + ctx.conn, err = core.Connect(ctx.mockVpp) Expect(err).ShouldNot(HaveOccurred()) ctx.ch, err = ctx.conn.NewAPIChannel() @@ -263,16 +262,59 @@ func TestNotifications(t *testing.T) { ctx.mockVpp.SendMsg(0, []byte("")) // receive the notification - notif := (<-notifChan).(*interfaces.SwInterfaceSetFlags) + var notif *interfaces.SwInterfaceSetFlags + Eventually(func() *interfaces.SwInterfaceSetFlags { + select { + case n := <-notifChan: + notif = n.(*interfaces.SwInterfaceSetFlags) + return notif + default: + return nil + } + }).ShouldNot(BeNil()) // verify the received notifications - Expect(notif).ShouldNot(BeNil()) Expect(notif.SwIfIndex).To(BeEquivalentTo(3), "Incorrect SwIfIndex value for SwInterfaceSetFlags") Expect(notif.AdminUpDown).To(BeEquivalentTo(1), "Incorrect AdminUpDown value for SwInterfaceSetFlags") ctx.ch.UnsubscribeNotification(subs) } +func TestNotificationEvent(t *testing.T) { + ctx := setupTest(t) + defer ctx.teardownTest() + + // subscribe for notification + notifChan := make(chan api.Message, 1) + subs, err := ctx.ch.SubscribeNotification(notifChan, interfaces.NewSwInterfaceEvent) + Expect(err).ShouldNot(HaveOccurred()) + + // mock the notification and force its delivery + ctx.mockVpp.MockReply(&interfaces.SwInterfaceEvent{ + SwIfIndex: 2, + LinkUpDown: 1, + }) + ctx.mockVpp.SendMsg(0, []byte("")) + + // receive the notification + var notif *interfaces.SwInterfaceEvent + Eventually(func() *interfaces.SwInterfaceEvent { + select { + case n := <-notifChan: + notif = n.(*interfaces.SwInterfaceEvent) + return notif + default: + return nil + } + }).ShouldNot(BeNil()) + + // verify the received notifications + Expect(notif.SwIfIndex).To(BeEquivalentTo(2), "Incorrect SwIfIndex value for SwInterfaceSetFlags") + Expect(notif.LinkUpDown).To(BeEquivalentTo(1), "Incorrect LinkUpDown value for SwInterfaceSetFlags") + + ctx.ch.UnsubscribeNotification(subs) +} + func TestCheckMessageCompatibility(t *testing.T) { ctx := setupTest(t) defer ctx.teardownTest()