"github.com/cloudfoundry/dropsonde/emitter/fake"
	"github.com/cloudfoundry/dropsonde/events"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

func getHeartbeatEvent(ie emitter.InstrumentedEmitter) *events.Heartbeat {
	return ie.GetHeartbeatEvent().(*events.Heartbeat)
}

var _ = Describe("InstrumentedEmitter", func() {
	var fakeEmitter *fake.FakeByteEmitter
	var instrumentedEmitter emitter.InstrumentedEmitter

	BeforeEach(func() {
		fakeEmitter = fake.NewFakeByteEmitter()
		instrumentedEmitter, _ = emitter.NewInstrumentedEmitter(fakeEmitter)
	})

	Describe("Delegators", func() {

		It("delegates Close() to the concreteEmitter", func() {
			instrumentedEmitter.Close()
			Eventually(fakeEmitter.IsClosed).Should(BeTrue())
		})
	})

	Describe("Emit()", func() {
		var testData = []byte("hello")

		It("calls the concrete emitter", func() {
Ejemplo n.º 2
0
import (
	"github.com/cloudfoundry/dropsonde/emitter"
	"github.com/cloudfoundry/dropsonde/emitter/fake"
	"github.com/cloudfoundry/dropsonde/events"
	"github.com/cloudfoundry/dropsonde/factories"
	"github.com/gogo/protobuf/proto"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("EventEmitter", func() {
	Describe("Emit", func() {
		Context("without an origin", func() {
			It("returns an error", func() {
				innerEmitter := fake.NewFakeByteEmitter()
				eventEmitter := emitter.NewEventEmitter(innerEmitter, "")

				testEvent := factories.NewHeartbeat(1, 2, 3)
				err := eventEmitter.Emit(testEvent)

				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("Wrap: "))
			})
		})

		It("marshals events and delegates to the inner emitter", func() {
			innerEmitter := fake.NewFakeByteEmitter()
			origin := "fake-origin"
			eventEmitter := emitter.NewEventEmitter(innerEmitter, origin)
Ejemplo n.º 3
0
	"github.com/cloudfoundry/dropsonde/events"
	"github.com/cloudfoundry/dropsonde/factories"
	"github.com/gogo/protobuf/proto"

	. "github.com/onsi/ginkgo"
	. "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")