本文整理匯總了Golang中github.com/pivotal-golang/lager/lagertest.TestLogger.LogMessages方法的典型用法代碼示例。如果您正苦於以下問題:Golang TestLogger.LogMessages方法的具體用法?Golang TestLogger.LogMessages怎麽用?Golang TestLogger.LogMessages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pivotal-golang/lager/lagertest.TestLogger
的用法示例。
在下文中一共展示了TestLogger.LogMessages方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Eventually(fakeDB.SetEncryptionKeyLabelCallCount).Should(Equal(1))
_, newLabel := fakeDB.SetEncryptionKeyLabelArgsForCall(0)
Expect(newLabel).To(Equal("label"))
})
})
Context("when encrypting fails", func() {
BeforeEach(func() {
fakeDB.PerformEncryptionReturns(errors.New("something is broken"))
})
It("does not fail and logs the error", func() {
Eventually(encryptorProcess.Ready()).Should(BeClosed())
Eventually(logger.LogMessages).Should(ContainElement("test.encryptor.encryption-finished"))
Expect(logger.LogMessages()).To(ContainElement("test.encryptor.encryption-failed"))
})
It("does not change the key in the db", func() {
Consistently(fakeDB.SetEncryptionKeyLabelCallCount).Should(Equal(0))
})
})
Context("when fetching the current encryption key fails", func() {
BeforeEach(func() {
fakeDB.EncryptionKeyLabelReturns("", errors.New("can't fetch"))
})
It("fails early", func() {
var err error
Eventually(encryptorProcess.Wait()).Should(Receive(&err))
示例2:
Expect(err).ToNot(HaveOccurred())
info, err := container.Info()
Expect(err).ToNot(HaveOccurred())
Expect(info.MappedPorts).To(Equal([]garden.PortMapping{
{HostPort: 1234, ContainerPort: 5678},
{HostPort: 1235, ContainerPort: 5679},
}))
})
It("should log before and after", func() {
_, err := container.Info()
Expect(err).ToNot(HaveOccurred())
Expect(logger.LogMessages()).To(ContainElement(ContainSubstring("info-starting")))
Expect(logger.LogMessages()).To(ContainElement(ContainSubstring("info-ended")))
})
Context("with running processes", func() {
JustBeforeEach(func() {
p1 := new(wfakes.FakeProcess)
p1.IDReturns("1")
p2 := new(wfakes.FakeProcess)
p2.IDReturns("2")
p3 := new(wfakes.FakeProcess)
p3.IDReturns("3")
fakeProcessTracker.ActiveProcessesReturns([]garden.Process{p1, p2, p3})
示例3:
credentialsGenerator.GenerateReturns(rabbitbroker.Credentials{
Username: "test-user",
Password: "test-password",
})
})
It("returns no error", func() {
_, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
Expect(err).NotTo(HaveOccurred())
})
It("logs a message stating that it is provisioning", func() {
_, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
Expect(err).NotTo(HaveOccurred())
Expect(logger.LogMessages()).To(ContainElement(ContainSubstring("Asked to provision a service: my-service-id")))
})
It("returns a dashboard url", func() {
provisionedSpec, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
Expect(err).NotTo(HaveOccurred())
Expect(provisionedSpec.DashboardURL).To(MatchRegexp(`https://%s/#/login/[a-zA-Z0-9\-]+/[a-zA-Z0-9\-]+`, config.Rabbitmq.ManagementDomain))
})
It("checks whether the host exist", func() {
_, err := broker.Provision("my-service-id", brokerapi.ProvisionDetails{}, false)
Expect(client.GetVhostCallCount()).To(Equal(1))
Expect(client.GetVhostArgsForCall(0)).To(Equal("my-service-id"))
Expect(err).NotTo(HaveOccurred())
})
示例4:
Properties: garden.Properties{"a": "b"},
})
Expect(err).ToNot(HaveOccurred())
_, err = linuxBackend.Create(garden.ContainerSpec{
Handle: "container-2",
Properties: garden.Properties{"a": "b"},
})
Expect(err).ToNot(HaveOccurred())
_, err = linuxBackend.Containers(
garden.Properties{"a": "b"},
)
Expect(err).ToNot(HaveOccurred())
Expect(logger.LogMessages()).To(ConsistOf("test.backend.containers.started", "test.backend.containers.matched", "test.backend.containers.matched", "test.backend.containers.ending"))
logs := logger.Logs()
Expect(logs[3].Data["handles"]).To(ConsistOf("container-1", "container-2"))
})
It("should log the entry and exit when there are no containers", func() {
_, err := linuxBackend.Containers(
garden.Properties{"a": "b", "e": "f"},
)
Expect(err).ToNot(HaveOccurred())
Expect(logger.LogMessages()).To(ConsistOf("test.backend.containers.started", "test.backend.containers.ending"))
})
})
})