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


Golang FakeFile.Read方法代码示例

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


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

示例1:

			accessLogger := NewFileAndLoggregatorAccessLogger(logger, "", fakeAccessFile, os.Stdout)

			go accessLogger.Run()
			accessLogger.Log(*CreateAccessLogRecord())

			os.Stdout = oldStdout
			var stdoutPayload []byte
			Eventually(func() int {
				stdoutPayload, _ = ioutil.ReadFile(fname)
				return len(stdoutPayload)
			}).ShouldNot(Equal(0))
			Expect(string(stdoutPayload)).To(MatchRegexp("^.*foo.bar.*\n"))

			var payload []byte
			Eventually(func() int {
				n, _ := fakeAccessFile.Read(&payload)
				return n
			}).ShouldNot(Equal(0))
			Expect(string(payload)).To(MatchRegexp("^.*foo.bar.*\n"))

			accessLogger.Stop()
		})
	})

	Measure("Log write speed", func(b Benchmarker) {
		w := nullWriter{}

		b.Time("writeTime", func() {
			for i := 0; i < 500; i++ {
				r := CreateAccessLogRecord()
				r.WriteTo(w)
开发者ID:shashankmjain,项目名称:gorouter,代码行数:31,代码来源:file_and_loggregator_access_logger_test.go

示例2:

			accessLogger.Stop()
		})

	})

	Context("with a file", func() {
		It("writes to the log file", func() {
			var fakeFile = new(test_util.FakeFile)

			accessLogger := NewFileAndLoggregatorAccessLogger(fakeFile, nil)
			go accessLogger.Run()
			accessLogger.Log(*CreateAccessLogRecord())

			var payload []byte
			Eventually(func() int {
				n, _ := fakeFile.Read(&payload)
				return n
			}).ShouldNot(Equal(0))
			Ω(string(payload)).To(MatchRegexp("^.*foo.bar.*\n"))

			accessLogger.Stop()
		})
	})

	Context("with valid hostnames", func() {
		It("creates an emitter", func() {
			e, err := NewEmitter("localhost:9843", "secret", 42)
			Ω(err).ToNot(HaveOccurred())
			Ω(e).ToNot(BeNil())

			e, err = NewEmitter("10.10.16.14:9843", "secret", 42)
开发者ID:KeyOfSpectator,项目名称:gorouter,代码行数:31,代码来源:file_and_loggregator_access_logger_test.go

示例3:

		})
		defer ln.Close()

		x := dialProxy(proxyServer)

		x.WriteLines([]string{
			"GET / HTTP/1.0",
			"Host: test",
		})

		x.CheckLine("HTTP/1.0 200 OK")

		var payload []byte
		Eventually(func() int {
			accessLogFile.Read(&payload)
			return len(payload)
		}).ShouldNot(BeZero())
		Ω(string(payload)).To(MatchRegexp("^test.*\n"))
		//make sure the record includes all the data
		//since the building of the log record happens throughout the life of the request
		Ω(string(payload)).To(MatchRegexp(".*200.*\n"))
	})

	It("Logs a request when it exits early", func() {
		x := dialProxy(proxyServer)

		x.WriteLines([]string{
			"GET / HTTP/0.9",
			"Host: test",
		})
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:30,代码来源:proxy_test.go


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