summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2017-12-04 09:54:13 +0100
committerOndrej Fabry <ofabry@cisco.com>2017-12-04 09:54:13 +0100
commitde8e6592e23a3819266cea5e9999c7c21fdd826f (patch)
treeb0b3eaf9cc92e36ef1944cb1a4eb09df8ec3cf6b /api
parentacf57209ccbd67fa96644abe5aef65f58264c112 (diff)
Fix events for mock adapter
Change-Id: Iee5fa6282e845ed2aef76c9246a9068f3765139c Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'api')
-rw-r--r--api/api_test.go47
1 files changed, 45 insertions, 2 deletions
diff --git a/api/api_test.go b/api/api_test.go
index 2a342f6..64c513c 100644
--- a/api/api_test.go
+++ b/api/api_test.go
@@ -263,16 +263,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()