本文整理匯總了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)
示例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)
示例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",
})