func NewEventFromBBS(bbsEvent models.Event) (receptor.Event, error) { switch bbsEvent := bbsEvent.(type) { case *models.ActualLRPCreatedEvent: actualLRP, evacuating := bbsEvent.ActualLrpGroup.Resolve() return receptor.NewActualLRPCreatedEvent(serialization.ActualLRPProtoToResponse(actualLRP, evacuating)), nil case *models.ActualLRPChangedEvent: before, evacuating := bbsEvent.Before.Resolve() after, evacuating := bbsEvent.After.Resolve() return receptor.NewActualLRPChangedEvent( serialization.ActualLRPProtoToResponse(before, evacuating), serialization.ActualLRPProtoToResponse(after, evacuating), ), nil case *models.ActualLRPRemovedEvent: actualLRP, evacuating := bbsEvent.ActualLrpGroup.Resolve() return receptor.NewActualLRPRemovedEvent(serialization.ActualLRPProtoToResponse(actualLRP, evacuating)), nil case *models.DesiredLRPCreatedEvent: return receptor.NewDesiredLRPCreatedEvent(serialization.DesiredLRPProtoToResponse(bbsEvent.DesiredLrp)), nil case *models.DesiredLRPChangedEvent: return receptor.NewDesiredLRPChangedEvent( serialization.DesiredLRPProtoToResponse(bbsEvent.Before), serialization.DesiredLRPProtoToResponse(bbsEvent.After), ), nil case *models.DesiredLRPRemovedEvent: return receptor.NewDesiredLRPRemovedEvent(serialization.DesiredLRPProtoToResponse(bbsEvent.DesiredLrp)), nil } return nil, fmt.Errorf("unknown event type: %#v", bbsEvent) }
func (w *watcher) watchDesired(logger lager.Logger) (chan<- bool, <-chan error) { return w.bbs.WatchForDesiredLRPChanges(logger, func(created models.DesiredLRP) { logger.Debug("handling-desired-create") w.hub.Emit(receptor.NewDesiredLRPCreatedEvent(serialization.DesiredLRPToResponse(created))) }, func(changed models.DesiredLRPChange) { logger.Debug("handling-desired-change") w.hub.Emit(receptor.NewDesiredLRPChangedEvent( serialization.DesiredLRPToResponse(changed.Before), serialization.DesiredLRPToResponse(changed.After), )) }, func(deleted models.DesiredLRP) { logger.Debug("handling-desired-delete") w.hub.Emit(receptor.NewDesiredLRPRemovedEvent(serialization.DesiredLRPToResponse(deleted))) }) }
It("returns the event", func() { event, err := eventSource.Next() Expect(err).NotTo(HaveOccurred()) desiredLRPChangeEvent, ok := event.(receptor.DesiredLRPChangedEvent) Expect(ok).To(BeTrue()) Expect(desiredLRPChangeEvent).To(Equal(expectedEvent)) }) }) Context("when receiving a DesiredLRPRemovedEvent", func() { var expectedEvent receptor.DesiredLRPRemovedEvent BeforeEach(func() { expectedEvent = receptor.NewDesiredLRPRemovedEvent(desiredLRPResponse) payload, err := json.Marshal(expectedEvent) Expect(err).NotTo(HaveOccurred()) fakeRawEventSource.NextReturns( sse.Event{ ID: "sup", Name: string(expectedEvent.EventType()), Data: payload, }, nil, ) }) It("returns the event", func() { event, err := eventSource.Next()