当前位置: 首页>>代码示例>>Golang>>正文


Golang MockByteArrayWriter.Data方法代码示例

本文整理汇总了Golang中metron/writers/mocks.MockByteArrayWriter.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang MockByteArrayWriter.Data方法的具体用法?Golang MockByteArrayWriter.Data怎么用?Golang MockByteArrayWriter.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在metron/writers/mocks.MockByteArrayWriter的用法示例。


在下文中一共展示了MockByteArrayWriter.Data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1:

		AfterEach(func() {
			reader.Stop()
			<-readerStopped
		})

		It("sends data recieved on UDP socket to its writer", func() {
			expectedData := "Some Data"
			otherData := "More stuff"

			connection, err := net.Dial("udp", address)

			_, err = connection.Write([]byte(expectedData))
			Expect(err).NotTo(HaveOccurred())

			Eventually(writer.Data).Should(HaveLen(1))
			data := string(writer.Data()[0])
			Expect(data).To(Equal(expectedData))

			_, err = connection.Write([]byte(otherData))
			Expect(err).NotTo(HaveOccurred())

			Eventually(writer.Data).Should(HaveLen(2))

			data = string(writer.Data()[1])
			Expect(data).To(Equal(otherData))
		})

		It("emits metrics related to data sent in on udp connection", func(done Done) {
			expectedData := "Some Data"
			otherData := "More stuff"
			connection, err := net.Dial("udp", address)
开发者ID:jvshahid,项目名称:loggregator,代码行数:31,代码来源:network_reader_test.go

示例2:

		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)

		marshaller.Write(envelope)

		Expect(writer.Data()).Should(HaveLen(1))
		outputMessage := writer.Data()[0]
		Expect(outputMessage).To(Equal(message))
	})

	Context("metrics", func() {
		It("emits the correct metrics context", func() {
			Expect(marshaller.Emit().Name).To(Equal("eventMarshaller"))
		})

		It("emits a marshal error counter", func() {
			envelope := &events.Envelope{}

			marshaller.Write(envelope)
			testhelpers.EventuallyExpectMetric(marshaller, "marshalErrors", 1)
		})
开发者ID:rakutentech,项目名称:loggregator,代码行数:31,代码来源:event_marshaller_test.go


注:本文中的metron/writers/mocks.MockByteArrayWriter.Data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。