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