本文整理匯總了Golang中bosh/agent/applier/applyspec/fakes.FakeV1Service.GetErr方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeV1Service.GetErr方法的具體用法?Golang FakeV1Service.GetErr怎麽用?Golang FakeV1Service.GetErr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/agent/applier/applyspec/fakes.FakeV1Service
的用法示例。
在下文中一共展示了FakeV1Service.GetErr方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
//.........這裏部分代碼省略.........
Job: &expectedJobName,
Index: &expectedJobIndex,
JobState: "fake-state",
Vitals: boshvitals.Vitals{Load: []string{"a", "b", "c"}},
}
It("sends initial heartbeat", func() {
// Configure periodic heartbeat every 5 hours
// so that we are sure that we will not receive it
agent = New(logger, handler, platform, actionDispatcher, alertSender, jobSupervisor, specService, 5*time.Hour)
// Immediately exit after sending initial heartbeat
handler.SendToHealthManagerErr = errors.New("stop")
err := agent.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("stop"))
Expect(handler.HMRequests()).To(Equal([]fakembus.HMRequest{
fakembus.HMRequest{Topic: "heartbeat", Payload: expectedHb},
}))
})
It("sends periodic heartbeats", func() {
sentRequests := 0
handler.SendToHealthManagerCallBack = func(_ fakembus.HMRequest) {
sentRequests++
if sentRequests == 3 {
handler.SendToHealthManagerErr = errors.New("stop")
}
}
err := agent.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("stop"))
Expect(handler.HMRequests()).To(Equal([]fakembus.HMRequest{
fakembus.HMRequest{Topic: "heartbeat", Payload: expectedHb},
fakembus.HMRequest{Topic: "heartbeat", Payload: expectedHb},
fakembus.HMRequest{Topic: "heartbeat", Payload: expectedHb},
}))
})
})
Context("when the agent fails to get job spec for a heartbeat", func() {
BeforeEach(func() {
specService.GetErr = errors.New("fake-spec-service-error")
handler.KeepOnRunning()
})
It("returns the error", func() {
err := agent.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-spec-service-error"))
})
})
Context("when the agent fails to get vitals for a heartbeat", func() {
BeforeEach(func() {
platform.FakeVitalsService.GetErr = errors.New("fake-vitals-service-error")
handler.KeepOnRunning()
})
It("returns the error", func() {
err := agent.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-vitals-service-error"))
})
})
It("sends job failure alerts to health manager", func() {
handler.KeepOnRunning()
failureAlert := boshalert.MonitAlert{ID: "fake-monit-alert"}
jobSupervisor.JobFailureAlert = &failureAlert
builtAlert := boshalert.Alert{ID: "fake-built-alert"}
alertBuilder.BuildAlert = builtAlert
// Immediately exit from Run() after alert is sent
handler.SendToHealthManagerCallBack = func(hmRequest fakembus.HMRequest) {
if hmRequest.Topic == "alert" {
handler.SendToHealthManagerErr = errors.New("stop")
}
}
err := agent.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("stop"))
Expect(alertBuilder.BuildInput).To(Equal(failureAlert))
// Check for inclusion because heartbeats might have been received
Expect(handler.HMRequests()).To(ContainElement(
fakembus.HMRequest{Topic: "alert", Payload: builtAlert},
))
})
})
})
}
示例2: init
//.........這裏部分代碼省略.........
Expect(err).ToNot(HaveOccurred())
Expect(resumedBefore).To(BeTrue())
})
Context("when heartbeats can be sent", func() {
BeforeEach(func() {
jobName := "fake-job"
jobIndex := 1
specService.Spec = boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{Name: &jobName},
Index: &jobIndex,
}
jobSupervisor.StatusStatus = "fake-state"
platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
Load: []string{"a", "b", "c"},
}
})
expectedJobName := "fake-job"
expectedJobIndex := 1
expectedHb := boshmbus.Heartbeat{
Job: &expectedJobName,
Index: &expectedJobIndex,
JobState: "fake-state",
Vitals: boshvitals.Vitals{Load: []string{"a", "b", "c"}},
}
It("sends initial heartbeat", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(handler.InitialHeartbeatSent).To(BeTrue())
Expect(handler.TickHeartbeatsSent).To(BeFalse())
Expect(handler.SendToHealthManagerTopic).To(Equal("heartbeat"))
Expect(handler.SendToHealthManagerPayload.(boshmbus.Heartbeat)).To(Equal(expectedHb))
})
It("sends periodic heartbeats", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(handler.TickHeartbeatsSent).To(BeFalse())
time.Sleep(5 * time.Millisecond)
Expect(handler.TickHeartbeatsSent).To(BeTrue())
Expect(handler.SendToHealthManagerTopic).To(Equal("heartbeat"))
Expect(handler.SendToHealthManagerPayload.(boshmbus.Heartbeat)).To(Equal(expectedHb))
})
})
Context("when the agent fails to get job spec for a heartbeat", func() {
BeforeEach(func() {
block := make(chan error)
handler.RunFunc = func() { <-block }
specService.GetErr = errors.New("fake-spec-service-error")
})
It("returns the error", func() {
err := agent.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-spec-service-error"))
})
})
Context("when the agent fails to get vitals for a heartbeat", func() {
BeforeEach(func() {
block := make(chan error)
handler.RunFunc = func() { <-block }
platform.FakeVitalsService.GetErr = errors.New("fake-vitals-service-error")
})
It("returns the error", func() {
err := agent.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-vitals-service-error"))
})
})
It("sets the callback for job failures monitoring", func() {
builtAlert := boshalert.Alert{Id: "some built alert id"}
alertBuilder.BuildAlert = builtAlert
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(handler.SendToHealthManagerTopic).ToNot(Equal("alert"))
failureAlert := boshalert.MonitAlert{Id: "some random id"}
jobSupervisor.OnJobFailure(failureAlert)
Expect(failureAlert).To(Equal(alertBuilder.BuildInput))
Expect(handler.SendToHealthManagerTopic).To(Equal("alert"))
Expect(builtAlert).To(Equal(handler.SendToHealthManagerPayload))
})
})
})
}
示例3:
_, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("At least one job template is required to run an errand"))
})
It("does not run errand script", func() {
_, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(len(cmdRunner.RunComplexCommands)).To(Equal(0))
})
})
})
Context("when apply spec could not be retrieved", func() {
BeforeEach(func() {
specService.GetErr = errors.New("fake-get-error")
})
It("returns error stating that job template is required", func() {
_, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("does not run errand script", func() {
_, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(len(cmdRunner.RunComplexCommands)).To(Equal(0))
})
})
})
示例4: init
//.........這裏部分代碼省略.........
Expect(specService.Spec).To(Equal(currentApplySpec))
})
})
})
Context("when resolving dynamic networks fails", func() {
BeforeEach(func() {
specService.PopulateDynamicNetworksErr = errors.New("fake-populate-dynamic-networks-err")
})
It("returns error", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-populate-dynamic-networks-err"))
})
It("does not apply desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(applier.Applied).To(BeFalse())
})
It("does not save desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(specService.Spec).To(Equal(currentApplySpec))
})
})
})
Context("when current spec cannot be retrieved", func() {
BeforeEach(func() {
specService.Spec = currentApplySpec
specService.GetErr = errors.New("fake-get-error")
})
It("returns error and does not apply desired spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("does not run applier with desired spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(applier.Applied).To(BeFalse())
})
It("does not save desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(specService.Spec).To(Equal(currentApplySpec))
})
})
})
Context("when desired spec does not have a configuration hash", func() {
desiredApplySpec := boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{
Template: "fake-job-template",
},
}
populatedDesiredApplySpec := boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{
Template: "fake-populated-job-template",