예제 #1
0
func createDefaultEmitter(origin, destination string) (emitter.EventEmitter, error) {
	if len(origin) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: origin variable not set")
	}

	if len(destination) == 0 {
		return nil, errors.New("Failed to initialize dropsonde: destination variable not set")
	}

	udpEmitter, err := emitter.NewUdpEmitter(destination)
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	heartbeatResponder, err := emitter.NewHeartbeatResponder(udpEmitter, origin)
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize dropsonde: %v", err.Error())
	}

	go udpEmitter.ListenForHeartbeatRequest(heartbeatResponder.Respond)

	return emitter.NewEventEmitter(heartbeatResponder, origin), nil
}
	. "github.com/onsi/gomega"
)

var _ = Describe("HeartbeatResponder", func() {
	var (
		wrappedEmitter *fake.FakeByteEmitter
		origin         = "testHeartbeatResponder/0"
	)

	BeforeEach(func() {
		wrappedEmitter = fake.NewFakeByteEmitter()
	})

	Describe("NewHeartbeatResponder", func() {
		It("requires non-nil args", func() {
			heartbeatResponder, err := emitter.NewHeartbeatResponder(nil, origin)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(Equal("wrappedEmitter is nil"))
			Expect(heartbeatResponder).To(BeNil())
		})
	})

	Describe("Emit", func() {
		var (
			heartbeatResponder emitter.RespondingByteEmitter
			testData           = []byte("hello")
		)

		BeforeEach(func() {
			heartbeatResponder, _ = emitter.NewHeartbeatResponder(wrappedEmitter, origin)
		})