本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/platform/fakes.FakePlatform.CleanIPMacAddressCacheErr方法的典型用法代码示例。如果您正苦于以下问题:Golang FakePlatform.CleanIPMacAddressCacheErr方法的具体用法?Golang FakePlatform.CleanIPMacAddressCacheErr怎么用?Golang FakePlatform.CleanIPMacAddressCacheErr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-agent/platform/fakes.FakePlatform
的用法示例。
在下文中一共展示了FakePlatform.CleanIPMacAddressCacheErr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
Describe("natsHandler", func() {
var (
settingsService *fakesettings.FakeSettingsService
client *fakeyagnats.FakeYagnats
logger boshlog.Logger
handler boshhandler.Handler
platform *fakeplatform.FakePlatform
loggerOutBuf *bytes.Buffer
loggerErrBuf *bytes.Buffer
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{
Settings: boshsettings.Settings{
AgentID: "my-agent-id",
Mbus: "nats://fake-username:[email protected]:1234",
},
}
loggerOutBuf = bytes.NewBufferString("")
loggerErrBuf = bytes.NewBufferString("")
logger = boshlog.NewWriterLogger(boshlog.LevelError, loggerOutBuf, loggerErrBuf)
client = fakeyagnats.New()
platform = fakeplatform.NewFakePlatform()
handler = NewNatsHandler(settingsService, client, logger, platform)
})
Describe("Start", func() {
It("starts", func() {
var receivedRequest boshhandler.Request
handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
receivedRequest = req
return boshhandler.NewValueResponse("expected value")
})
defer handler.Stop()
Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())
Expect(client.SubscriptionCount()).To(Equal(1))
subscriptions := client.Subscriptions("agent.my-agent-id")
Expect(len(subscriptions)).To(Equal(1))
expectedPayload := []byte(`{"method":"ping","arguments":["foo","bar"], "reply_to": "reply to me!"}`)
subscription := subscriptions[0]
subscription.Callback(&yagnats.Message{
Subject: "agent.my-agent-id",
Payload: expectedPayload,
})
Expect(receivedRequest).To(Equal(boshhandler.Request{
ReplyTo: "reply to me!",
Method: "ping",
Payload: expectedPayload,
}))
Expect(client.PublishedMessageCount()).To(Equal(1))
messages := client.PublishedMessages("reply to me!")
Expect(len(messages)).To(Equal(1))
Expect(messages[0].Payload).To(Equal([]byte(`{"value":"expected value"}`)))
})
It("cleans up ip-mac address cache for nats configured with ip address", func() {
handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
return nil
})
defer handler.Stop()
Expect(platform.CleanedIPMacAddressCache).To(Equal("127.0.0.1"))
Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())
})
It("does not try to clean up ip-mac address cache for nats configured with hostname", func() {
settingsService.Settings.Mbus = "nats://fake-username:[email protected]:1234"
handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
return nil
})
defer handler.Stop()
Expect(platform.CleanedIPMacAddressCache).To(BeEmpty())
Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())
})
It("logs error and proceeds if it fails to clean up ip-mac address cache for nats", func() {
platform.CleanIPMacAddressCacheErr = errors.New("failed to run")
handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
return nil
})
defer handler.Stop()
Expect(platform.CleanedIPMacAddressCache).To(Equal("127.0.0.1"))
Expect(loggerErrBuf).To(ContainSubstring("ERROR - Cleaning ip-mac address cache for: 127.0.0.1"))
Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())
})
It("does not respond if the response is nil", func() {
err := handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
return nil
//.........这里部分代码省略.........