本文整理匯總了Golang中bosh/agent/task/fakes.FakeService.CreateTaskErr方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeService.CreateTaskErr方法的具體用法?Golang FakeService.CreateTaskErr怎麽用?Golang FakeService.CreateTaskErr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/agent/task/fakes.FakeService
的用法示例。
在下文中一共展示了FakeService.CreateTaskErr方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
Describe("actionDispatcher", func() {
var (
logger boshlog.Logger
taskService *faketask.FakeService
taskManager *faketask.FakeManager
actionFactory *fakeaction.FakeFactory
actionRunner *fakeaction.FakeRunner
dispatcher ActionDispatcher
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LEVEL_NONE)
taskService = faketask.NewFakeService()
taskManager = faketask.NewFakeManager()
actionFactory = fakeaction.NewFakeFactory()
actionRunner = &fakeaction.FakeRunner{}
dispatcher = NewActionDispatcher(logger, taskService, taskManager, actionFactory, actionRunner)
})
It("responds with exception when the method is unknown", func() {
actionFactory.RegisterActionErr("fake-action", errors.New("fake-create-error"))
req := boshhandler.NewRequest("fake-reply", "fake-action", []byte{})
resp := dispatcher.Dispatch(req)
boshassert.MatchesJsonString(GinkgoT(), resp, `{"exception":{"message":"unknown message fake-action"}}`)
})
Context("when action is synchronous", func() {
var (
req boshhandler.Request
)
BeforeEach(func() {
req = boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
actionFactory.RegisterAction("fake-action", &fakeaction.TestAction{Asynchronous: false})
})
It("handles synchronous action", func() {
actionRunner.RunValue = "fake-value"
resp := dispatcher.Dispatch(req)
Expect(req.GetPayload()).To(Equal(actionRunner.RunPayload))
Expect(boshhandler.NewValueResponse("fake-value")).To(Equal(resp))
})
It("handles synchronous action when err", func() {
actionRunner.RunErr = errors.New("fake-run-error")
resp := dispatcher.Dispatch(req)
expectedJson := fmt.Sprintf("{\"exception\":{\"message\":\"Action Failed %s: fake-run-error\"}}", req.Method)
boshassert.MatchesJsonString(GinkgoT(), resp, expectedJson)
})
})
Context("when action is asynchronous", func() {
var (
req boshhandler.Request
action *fakeaction.TestAction
)
BeforeEach(func() {
req = boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
action = &fakeaction.TestAction{Asynchronous: true}
actionFactory.RegisterAction("fake-action", action)
})
Context("when action is not persistent", func() {
BeforeEach(func() {
action.Persistent = false
})
It("responds with task id and state", func() {
resp := dispatcher.Dispatch(req)
boshassert.MatchesJsonString(GinkgoT(), resp,
`{"value":{"agent_task_id":"fake-generated-task-id","state":"running"}}`)
})
It("starts running created task", func() {
dispatcher.Dispatch(req)
Expect(len(taskService.StartedTasks)).To(Equal(1))
Expect(taskService.StartedTasks["fake-generated-task-id"]).ToNot(BeNil())
})
It("returns create task error", func() {
taskService.CreateTaskErr = errors.New("fake-create-task-error")
resp := dispatcher.Dispatch(req)
respJson, err := json.Marshal(resp)
Expect(err).ToNot(HaveOccurred())
Expect(string(respJson)).To(ContainSubstring("fake-create-task-error"))
})
It("return run value to the task", func() {
actionRunner.RunValue = "fake-value"
dispatcher.Dispatch(req)
value, err := taskService.StartedTasks["fake-generated-task-id"].TaskFunc()
Expect(value).To(Equal("fake-value"))
Expect(err).ToNot(HaveOccurred())
//.........這裏部分代碼省略.........