Flatten contexts in receiver_test.go
@@ -23,15 +23,25 @@ var _ = Describe("Receiver", func() {
BeforeEach(func() {
spyConverter = &SpyEnvelopeConverter{}
- spySubscriber = &SpySubscriber{}
+ spySubscriber = &SpySubscriber{
+ recv: func() ([]byte, error) {
+ return []byte("something"), nil
+ },
+ }
receiver = ingress.NewReceiver(spyConverter, ingress.NewRequestConverter(), spySubscriber)
})
- Context("when the subscriber does not return an error", func() {
- BeforeEach(func() {
- spySubscriber.recv = func() ([]byte, error) {
- return []byte("something"), nil
- }
+ It("streams converted data", func() {
+ expectedEnv := &v2.Envelope{Timestamp: 1}
+ spyConverter.envelope = expectedEnv
+
+ req := &v2.EgressRequest{}
+ receiver, err := receiver.Receive(context.Background(), req)
+ Expect(err).ToNot(HaveOccurred())
+
+ env, err := receiver()
+ Expect(err).ToNot(HaveOccurred())
+ Expect(env).To(Equal(expectedEnv))
})
It("subscribes to data", func() {
@@ -77,28 +87,10 @@ var _ = Describe("Receiver", func() {
Expect(err).To(HaveOccurred())
})
- It("streams the converted data", func() {
- expectedEnv := &v2.Envelope{Timestamp: 1}
- spyConverter.envelope = expectedEnv
-
- req := &v2.EgressRequest{}
- receiver, err := receiver.Receive(context.Background(), req)
- Expect(err).ToNot(HaveOccurred())
-
- env, err := receiver()
- Expect(err).ToNot(HaveOccurred())
- Expect(env).To(Equal(expectedEnv))
- })
- })
-
- Context("when the subscriber receiver errors", func() {
- BeforeEach(func() {
+ It("returns an error via the receiver", func() {
spySubscriber.recv = func() ([]byte, error) {
return nil, fmt.Errorf("some-error")
}
- })
-
- It("returns an error via the receiver", func() {
req := &v2.EgressRequest{}
receiver, err := receiver.Receive(context.Background(), req)
Expect(err).ToNot(HaveOccurred())
@@ -106,19 +98,13 @@ var _ = Describe("Receiver", func() {
_, err = receiver()
Expect(err).To(HaveOccurred())
})
- })
- Context("when the subscriber returns an error", func() {
- BeforeEach(func() {
+ It("returns an error when the subscriber fails", func() {
spySubscriber.err = errors.New("some error")
- })
-
- It("returns an error", func() {
req := &v2.EgressRequest{}
_, err := receiver.Receive(context.Background(), req)
Expect(err).To(HaveOccurred())
})
- })
})
