當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。