func (s *WebReceiverAppSuite) TestPostNotificationSuccess(c *C) { resp, err := s.postNotification("Channel1", "abc", "subject", "content", "tag1,tag2", "normal") c.Assert(err, IsNil) c.Assert(resp.StatusCode, Equals, http.StatusAccepted) timedout := testhelpers.BlockUntilSatisfiedOrTimeout(func() bool { return len(s.notifier.Logs) >= 1 }, 5*time.Second) c.Assert(timedout, Equals, false) var notifications []*sqlite_backend.Notification _, err = s.backend.Select(¬ifications, "SELECT * FROM notifications WHERE Channel = ?", "Channel1") c.Assert(err, IsNil) c.Assert(notifications, HasLen, 1) c.Assert(notifications[0].Subject, Equals, "subject") c.Assert(notifications[0].Content, Equals, "content") c.Assert(notifications[0].Tags, DeepEquals, []string{"tag1", "tag2"}) c.Assert(notifications[0].Priority, Equals, backend.NormalPriority) c.Assert(notifications[0].Channel, Equals, "Channel1") c.Assert(notifications[0].Origin, Equals, "abc_client") c.Assert(notifications[0].Delivered, Equals, true) c.Assert(s.notifier.Logs, HasLen, 1) c.Assert(s.notifier.Logs[0].Notifications, HasLen, 1) c.Assert(s.notifier.Logs[0].Notifications[0].Subject, Equals, "subject") c.Assert(s.notifier.Logs[0].Subscriber.UniqueName, Equals, "jimmy") }
func (s *SQLiteNotificationBackendSuite) TestQueueNotificationSendImmediately(c *C) { notification := s.notification notification.Channel = "Channel1" err := s.backend.QueueNotification(notification) c.Assert(err, IsNil) timedout := testhelpers.BlockUntilSatisfiedOrTimeout(func() bool { return len(s.notifier.Logs) >= 1 }, testQueueNotificationSendTimeout) c.Assert(timedout, Equals, false) c.Assert(s.notifier.Logs, HasLen, 1) c.Assert(s.notifier.Logs[0].Notifications, HasLen, 1) s.checkNotificationEquality(c, s.notifier.Logs[0].Notifications[0], notification) c.Assert(s.notifier.Logs[0].Subscriber, DeepEquals, s.jimmy) notifications := []*Notification{} _, err = s.backend.Select(¬ifications, "SELECT * FROM notifications WHERE Channel = ?", notification.Channel) c.Assert(err, IsNil) c.Assert(notifications, HasLen, 1) s.checkNotificationEquality(c, notifications[0].Notification, notification) c.Assert(notifications[0].Delivered, Equals, true) }
func (s *SQLiteNotificationBackendSuite) TestDeliverNotificationsDelivers(c *C) { notification := s.notification notification.Channel = "Channel2" localNotification := &Notification{ Notification: notification, Delivered: false, } localNotification2 := &Notification{ Notification: notification, Delivered: true, } err := s.backend.DbMap.Insert(localNotification, localNotification2) c.Assert(err, IsNil) currentTime, err := time.Parse(time.RFC3339, "2015-09-05T23:59:59Z") c.Assert(err, IsNil) s.backend.deliverNotificationsLogIfError(currentTime) timedout := testhelpers.BlockUntilSatisfiedOrTimeout(func() bool { return len(s.notifier.Logs) >= 2 }, testBackgroundTaskTimeout) c.Assert(timedout, Equals, false) c.Assert(s.notifier.Logs, HasLen, 2) c.Assert(s.notifier.Logs[0].Notifications, HasLen, 1) s.checkNotificationEquality(c, s.notifier.Logs[0].Notifications[0], notification) c.Assert(s.notifier.Logs[1].Notifications, HasLen, 1) s.checkNotificationEquality(c, s.notifier.Logs[1].Notifications[0], notification) subscribersMatched := 0 for _, subscriber := range []backend.Subscriber{s.bob, s.jimmy} { for _, log := range s.notifier.Logs { if log.Subscriber.Name == subscriber.Name { subscribersMatched++ } } } c.Assert(subscribersMatched, Equals, 2) c.Assert(logrusTestHook.Logs[logrus.WarnLevel], HasLen, 0) c.Assert(logrusTestHook.Logs[logrus.ErrorLevel], HasLen, 0) }
func (s *SQLiteNotificationBackendSuite) TestQueueUrgentNotificationSendImmediately(c *C) { notification := s.notification notification.Channel = "Channel2" notification.Priority = backend.UrgentPriority err := s.backend.QueueNotification(notification) c.Assert(err, IsNil) timedout := testhelpers.BlockUntilSatisfiedOrTimeout(func() bool { return len(s.notifier.Logs) >= 2 }, testQueueNotificationSendTimeout) c.Assert(timedout, Equals, false) c.Assert(s.notifier.Logs, HasLen, 2) c.Assert(s.notifier.Logs[0].Notifications, HasLen, 1) s.checkNotificationEquality(c, s.notifier.Logs[0].Notifications[0], notification) c.Assert(s.notifier.Logs[1].Notifications, HasLen, 1) s.checkNotificationEquality(c, s.notifier.Logs[1].Notifications[0], notification) subscribersMatched := 0 for _, subscriber := range []backend.Subscriber{s.bob, s.jimmy} { for _, log := range s.notifier.Logs { if log.Subscriber.Name == subscriber.Name { subscribersMatched++ } } } c.Assert(subscribersMatched, Equals, 2) notifications := []*Notification{} _, err = s.backend.Select(¬ifications, "SELECT * FROM notifications WHERE Channel = ?", notification.Channel) c.Assert(err, IsNil) c.Assert(notifications, HasLen, 1) s.checkNotificationEquality(c, notifications[0].Notification, notification) c.Assert(notifications[0].Delivered, Equals, true) }