本文整理汇总了Golang中github.com/pivotal-golang/lager/lagertest.TestSink.Logs方法的典型用法代码示例。如果您正苦于以下问题:Golang TestSink.Logs方法的具体用法?Golang TestSink.Logs怎么用?Golang TestSink.Logs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pivotal-golang/lager/lagertest.TestSink
的用法示例。
在下文中一共展示了TestSink.Logs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
var logData = lager.Data{
"foo": "bar",
"a-number": 7,
}
BeforeEach(func() {
logger = lager.NewLogger(component)
testSink = lagertest.NewTestSink()
logger.RegisterSink(testSink)
})
var TestCommonLogFeatures = func(level lager.LogLevel) {
var log lager.LogFormat
BeforeEach(func() {
log = testSink.Logs()[0]
})
It("writes a log to the sink", func() {
Ω(testSink.Logs()).Should(HaveLen(1))
})
It("records the source component", func() {
Ω(log.Source).Should(Equal(component))
})
It("outputs a properly-formatted message", func() {
Ω(log.Message).Should(Equal(fmt.Sprintf("%s.%s", component, action)))
})
It("has a timestamp", func() {
示例2:
})
AfterEach(func() {
ts.Close()
})
It("doesn't output the authorization information", func() {
req, err := http.NewRequest("GET", ts.URL, nil)
req.Header.Add("Authorization", "this-is-a-secret")
req.Header.Add("authorization", "this-is-a-secret2")
req.Header.Add("AUTHORIZATION", "this-is-a-secret3")
req.Header.Add("auThoRizaTion", "this-is-a-secret4")
resp, err := client.Do(req)
Expect(err).NotTo(HaveOccurred())
output, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("Dummy handler"))
headers := testSink.Logs()[0].Data["request-headers"]
Expect(headers).ToNot(HaveKey("Authorization"))
Expect(headers).ToNot(HaveKey("authorization"))
Expect(headers).ToNot(HaveKey("AUTHORIZATION"))
Expect(headers).ToNot(HaveKey("auThoRizaTion"))
})
})