Пример #1
0
func convertMessage(legacyEnvelope *logmessage.LogEnvelope) *events.Envelope {
	legacyMessage := legacyEnvelope.GetLogMessage()
	return &events.Envelope{
		Origin:    proto.String(legacyDropsondeOrigin),
		EventType: events.Envelope_LogMessage.Enum(),
		LogMessage: &events.LogMessage{
			Message:        legacyMessage.Message,
			MessageType:    (*events.LogMessage_MessageType)(legacyMessage.MessageType),
			Timestamp:      legacyMessage.Timestamp,
			AppId:          legacyMessage.AppId,
			SourceType:     legacyMessage.SourceName,
			SourceInstance: legacyMessage.SourceId,
		},
	}
}
			err := proto.Unmarshal(bytes, &envelope)
			Expect(err).ToNot(HaveOccurred())
			Expect(envelope.GetEventType()).To(Equal(events.Envelope_ValueMetric))
		})
	})

	Context("The LogGenerator", func() {
		It("generates a log message envelope", func() {
			generator := messagegenerator.NewLogMessageGenerator()
			bytes := generator.Generate()
			var envelope events.Envelope
			err := proto.Unmarshal(bytes, &envelope)
			Expect(err).ToNot(HaveOccurred())
			Expect(envelope.GetLogMessage()).ToNot(BeNil())
			Expect(envelope.GetLogMessage().GetMessage()).To(BeEquivalentTo("test message"))
		})
	})

	Context("The LegacyLogGenerator", func() {
		It("generates a legacy log message envelope", func() {
			generator := messagegenerator.NewLegacyLogGenerator()
			bytes := generator.Generate()
			var envelope logmessage.LogEnvelope
			err := proto.Unmarshal(bytes, &envelope)
			Expect(err).ToNot(HaveOccurred())
			Expect(envelope.GetLogMessage()).ToNot(BeNil())
			Expect(envelope.GetLogMessage().GetMessage()).To(BeEquivalentTo("test message"))
		})
	})
})