本文整理汇总了Golang中github.com/cloudfoundry/gosteno.TestingSink.Records方法的典型用法代码示例。如果您正苦于以下问题:Golang TestingSink.Records方法的具体用法?Golang TestingSink.Records怎么用?Golang TestingSink.Records使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/gosteno.TestingSink
的用法示例。
在下文中一共展示了TestingSink.Records方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
Context("at initialization", func() {
It("connects to the store", func() {
elector.NewElector("name", fakeStore, 1*time.Millisecond, logger)
Expect(fakeStore.DidConnect).To(BeTrue())
})
Context("when store connection fails", func() {
BeforeEach(func() {
fakeStore.ConnectErr = errors.New("connection error")
})
It("logs an error", func() {
go elector.NewElector("name", fakeStore, 100*time.Millisecond, logger)
Eventually(func() int { return len(testingSink.Records()) }).Should(BeNumerically(">=", 1))
var messages []string
for _, record := range testingSink.Records() {
messages = append(messages, record.Message)
}
Expect(messages).To(ContainElement("Elector: Unable to connect to store: 'connection error'"))
})
It("reconnects on an interval", func() {
go elector.NewElector("name", fakeStore, 10*time.Millisecond, logger)
Eventually(func() int { return len(testingSink.Records()) }).Should(BeNumerically(">=", 2))
})
})
})
示例2: startComponent
It("can handle an empty reply in the subject", func() {
component.Varz.Type = "TestType"
component.Logger = logger
err := component.Start()
Expect(err).ToNot(HaveOccurred())
err = component.Register(mbusClient)
Expect(err).ToNot(HaveOccurred())
err = mbusClient.PublishRequest("vcap.component.discover", "", []byte(""))
Expect(err).ToNot(HaveOccurred())
Eventually(func() bool {
found := false
for _, r := range sink.Records() {
if strings.Contains(r.Message, "Received message with empty reply on subject") {
found = true
}
}
return found
}).Should(BeTrue())
err = mbusClient.PublishRequest("vcap.component.discover", "reply", []byte("hi"))
Expect(err).ToNot(HaveOccurred())
})
})
})
func startComponent(component *VcapComponent) {
err := component.Start()
示例3:
Eventually(client.RoutesCallCount, "2s").Should(Equal(1))
clock.Increment(cfg.PruneStaleDropletsInterval + 100*time.Millisecond)
Eventually(client.RoutesCallCount, "2s").Should(Equal(2))
})
})
Context("when token fetcher returns error", func() {
BeforeEach(func() {
tokenFetcher.FetchTokenReturns(nil, errors.New("Unauthorized"))
})
It("logs the error", func() {
currentTokenFetchErrors := sender.GetCounter(TokenFetchErrors)
Eventually(func() int {
return len(sink.Records())
}).Should(BeNumerically(">=", 1))
Expect(sink.Records()).ToNot(BeNil())
Expect(sink.Records()[0].Message).To(Equal("Unauthorized"))
Eventually(tokenFetcher.FetchTokenCallCount).Should(BeNumerically(">=", 2))
Expect(client.SubscribeToEventsCallCount()).Should(Equal(0))
Expect(client.RoutesCallCount()).Should(Equal(0))
Eventually(func() uint64 {
return sender.GetCounter(TokenFetchErrors)
}).Should(BeNumerically(">", currentTokenFetchErrors))
})
})
示例4:
received <- struct{}{}
return []db.Route{}, nil
}
fetcher.StartFetchCycle()
Eventually(received).Should(Receive())
Eventually(received).Should(Receive())
})
It("logs the error", func() {
tokenFetcher.FetchTokenReturns(nil, errors.New("Unauthorized"))
fetcher.StartFetchCycle()
Eventually(func() int {
return len(sink.Records())
}).Should(BeNumerically(">=", 1))
Expect(sink.Records()).ToNot(BeNil())
Expect(sink.Records()[0].Message).To(Equal("Unauthorized"))
})
})
Describe(".StartEventCycle", func() {
Context("when fetching the auth token fails", func() {
It("logs the failure and tries again", func() {
received := make(chan struct{})
tokenFetcher.FetchTokenStub = func() (*token_fetcher.Token, error) {
received <- struct{}{}
return nil, errors.New("failed to get the token")