}) It("calls the callback with the new subscriber count", func() { Eventually(counts).Should(Receive(Equal(2))) }) }) Context("when all subscribers are dropped", func() { BeforeEach(func() { Eventually(counts).Should(Receive()) err := eventSource.Close() Expect(err).NotTo(HaveOccurred()) // emit event so hub sees closed source and drops subscription hub.Emit(eventfakes.FakeEvent{}) }) It("calls the callback with a zero count", func() { Eventually(counts).Should(Receive(BeZero())) }) }) Context("when the hub is closed", func() { BeforeEach(func() { Eventually(counts).Should(Receive()) err := hub.Close() Expect(err).NotTo(HaveOccurred()) })
Context("when failing to subscribe to the event hub", func() { BeforeEach(func() { hub.Close() }) It("returns an internal server error", func() { Expect(response.StatusCode).To(Equal(http.StatusInternalServerError)) }) }) Context("when successfully subscribing to the event hub", func() { It("emits events from the hub to the connection", func() { reader := sse.NewReadCloser(response.Body) hub.Emit(&eventfakes.FakeEvent{"A"}) encodedPayload := base64.StdEncoding.EncodeToString([]byte("A")) Expect(reader.Next()).To(Equal(sse.Event{ ID: "0", Name: "fake", Data: []byte(encodedPayload), })) hub.Emit(&eventfakes.FakeEvent{"B"}) encodedPayload = base64.StdEncoding.EncodeToString([]byte("B")) Expect(reader.Next()).To(Equal(sse.Event{ ID: "1", Name: "fake", Data: []byte(encodedPayload),
Context("when failing to subscribe to the event hub", func() { BeforeEach(func() { hub.Close() }) It("returns an internal server error", func() { Expect(response.StatusCode).To(Equal(http.StatusInternalServerError)) }) }) Context("when successfully subscribing to the event hub", func() { It("emits events from the hub to the connection", func() { reader := sse.NewReadCloser(response.Body) hub.Emit(&eventfakes.FakeEvent{Token: "A"}) encodedPayload := base64.StdEncoding.EncodeToString([]byte("A")) Expect(reader.Next()).To(Equal(sse.Event{ ID: "0", Name: "fake", Data: []byte(encodedPayload), })) hub.Emit(&eventfakes.FakeEvent{Token: "B"}) encodedPayload = base64.StdEncoding.EncodeToString([]byte("B")) Expect(reader.Next()).To(Equal(sse.Event{ ID: "1", Name: "fake", Data: []byte(encodedPayload),