本文整理汇总了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",
})