log.SetOutput(logWriter) hbEmitter, _ := emitter.NewHeartbeatEmitter(wrappedEmitter, origin) Eventually(func() int { return len(wrappedEmitter.GetMessages()) }).Should(BeNumerically(">=", 2)) loggedText := string(logWriter.Bytes()) expectedText := "fake error" Expect(loggedText).To(ContainSubstring(expectedText)) hbEmitter.Close() }) }) Describe("Emit", func() { var ( hbEmitter emitter.ByteEmitter testData = []byte("hello") ) BeforeEach(func() { hbEmitter, _ = emitter.NewHeartbeatEmitter(wrappedEmitter, origin) }) It("delegates to the wrapped emitter", func() { hbEmitter.Emit(testData) messages := wrappedEmitter.GetMessages() Expect(messages).To(HaveLen(1)) Expect(messages[0]).To(Equal(testData)) }) It("increments the heartbeat counter", func() {
Describe("Close()", func() { It("closes the UDP connection", func() { udpEmitter, _ := emitter.NewUdpEmitter("localhost:42420") udpEmitter.Close() err := udpEmitter.Emit(testData) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal("use of closed network connection")) }) }) Describe("Emit()", func() { var udpEmitter emitter.ByteEmitter Context("when the agent is listening", func() { var agentListener net.PacketConn BeforeEach(func() { var err error agentListener, err = net.ListenPacket("udp4", "") Expect(err).ToNot(HaveOccurred()) udpEmitter, err = emitter.NewUdpEmitter(agentListener.LocalAddr().String()) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() {