"github.com/cloudfoundry/dropsonde/factories"
	"github.com/cloudfoundry/dropsonde/metric_sender/fake"
	"github.com/cloudfoundry/dropsonde/metricbatcher"
	"github.com/cloudfoundry/dropsonde/metrics"
	"github.com/cloudfoundry/loggregatorlib/cfcomponent/instrumentation/testhelpers"
	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"time"
)

var _ = Describe("EventMarshaller", func() {
	var (
		marshaller *eventmarshaller.EventMarshaller
		writer     *mocks.MockByteArrayWriter
	)

	BeforeEach(func() {
		writer = &mocks.MockByteArrayWriter{}
		marshaller = eventmarshaller.New(writer, loggertesthelper.Logger())

	})

	It("marshals envelopes into bytes", func() {
		envelope := &events.Envelope{
			Origin:     proto.String("fake-origin-1"),
			EventType:  events.Envelope_LogMessage.Enum(),
			LogMessage: factories.NewLogMessage(events.LogMessage_OUT, "message", "appid", "sourceType"),
		}
		message, _ := proto.Marshal(envelope)
	. "github.com/apoydence/eachers"
	"github.com/apoydence/eachers/testhelpers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry/dropsonde/metricbatcher"
	"github.com/cloudfoundry/gosteno"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"
)

var _ = Describe("EventMarshaller", func() {
	var (
		marshaller      *eventmarshaller.EventMarshaller
		mockBatcher     *mockEventBatcher
		mockChainWriter *mockBatchChainByteWriter
		mockChainer     *mockBatchCounterChainer
	)

	BeforeEach(func() {
		mockBatcher = newMockEventBatcher()
		mockChainWriter = newMockBatchChainByteWriter()
		mockChainer = newMockBatchCounterChainer()
		testhelpers.AlwaysReturn(mockBatcher.BatchCounterOutput, mockChainer)
		testhelpers.AlwaysReturn(mockChainer.SetTagOutput, mockChainer)
	})

	JustBeforeEach(func() {
		logger := gosteno.NewLogger("TestLogger")
		marshaller = eventmarshaller.New(mockBatcher, logger)
		marshaller.SetWriter(mockChainWriter)
Esempio n. 3
0
	"github.com/cloudfoundry/dropsonde/factories"
	"github.com/cloudfoundry/dropsonde/metric_sender/fake"
	"github.com/cloudfoundry/dropsonde/metricbatcher"
	"github.com/cloudfoundry/dropsonde/metrics"
	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("EventMarshaller", func() {
	var (
		fakeMetricSender *fake.FakeMetricSender
		marshaller       *eventmarshaller.EventMarshaller
		writer           *mocks.MockByteArrayWriter
	)

	BeforeEach(func() {
		fakeMetricSender = fake.NewFakeMetricSender()
		batcher := metricbatcher.New(fakeMetricSender, 1*time.Millisecond)
		metrics.Initialize(fakeMetricSender, batcher)

		writer = &mocks.MockByteArrayWriter{}
		marshaller = eventmarshaller.New(writer, loggertesthelper.Logger())
	})

	Context("with a valid envelope", func() {
		var message []byte
	. "github.com/apoydence/eachers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry/dropsonde/metric_sender/fake"
	"github.com/cloudfoundry/dropsonde/metricbatcher"
	"github.com/cloudfoundry/dropsonde/metrics"
	"github.com/cloudfoundry/gosteno"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"
)

var _ = Describe("EventMarhsaller", func() {
	var (
		marshaller *eventmarshaller.EventMarshaller
		sender     *fake.FakeMetricSender
		writer     *mockByteWriter
	)

	BeforeEach(func() {
		writer = newMockByteWriter()
		sender = fake.NewFakeMetricSender()
		metrics.Initialize(sender, metricbatcher.New(sender, time.Millisecond*10))
	})

	JustBeforeEach(func() {
		logger := gosteno.NewLogger("TestLogger")
		marshaller = eventmarshaller.New(logger)
		marshaller.SetWriter(writer)
	})