Exemple #1
0
func streamEvents(eventSource events.EventSource) chan models.Event {
	eventChannel := make(chan models.Event)

	go func() {
		for {
			event, err := eventSource.Next()
			if err != nil {
				close(eventChannel)
				return
			}
			eventChannel <- event
		}
	}()

	return eventChannel
}
Exemple #2
0
					payload, err := proto.Marshal(expectedEvent)
					Expect(err).NotTo(HaveOccurred())
					payload = []byte(base64.StdEncoding.EncodeToString(payload))

					fakeRawEventSource.NextReturns(
						sse.Event{
							ID:   "hi",
							Name: string(expectedEvent.EventType()),
							Data: payload,
						},
						nil,
					)
				})

				It("returns the event", func() {
					event, err := eventSource.Next()
					Expect(err).NotTo(HaveOccurred())

					desiredLRPCreateEvent, ok := event.(*models.DesiredLRPCreatedEvent)
					Expect(ok).To(BeTrue())
					Expect(desiredLRPCreateEvent).To(Equal(expectedEvent))
				})
			})

			Context("when receiving a DesiredLRPChangedEvent", func() {
				var expectedEvent *models.DesiredLRPChangedEvent

				BeforeEach(func() {
					expectedEvent = models.NewDesiredLRPChangedEvent(desiredLRP, desiredLRP)
					payload, err := proto.Marshal(expectedEvent)
					Expect(err).NotTo(HaveOccurred())