本文整理匯總了Golang中bosh/agent/task/fakes.FakeService.StartedTasks方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeService.StartedTasks方法的具體用法?Golang FakeService.StartedTasks怎麽用?Golang FakeService.StartedTasks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/agent/task/fakes.FakeService
的用法示例。
在下文中一共展示了FakeService.StartedTasks方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
State: boshtask.TaskStateFailed,
Error: errors.New("fake-task-error"),
}
taskValue, err := action.Run("fake-task-id")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Task fake-task-id result: fake-task-error"))
Expect(taskValue).To(BeNil())
})
It("returns a successful task", func() {
taskService.StartedTasks["fake-task-id"] = boshtask.Task{
ID: "fake-task-id",
State: boshtask.TaskStateDone,
Value: "some-task-value",
}
taskValue, err := action.Run("fake-task-id")
Expect(err).ToNot(HaveOccurred())
Expect(taskValue).To(Equal("some-task-value"))
})
It("returns error when task is not found", func() {
taskService.StartedTasks = map[string]boshtask.Task{}
_, err := action.Run("fake-task-id")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Task with id fake-task-id could not be found"))
})
})
示例2: init
func init() {
Describe("GetTask", func() {
var (
taskService *faketask.FakeService
action GetTaskAction
)
BeforeEach(func() {
taskService = faketask.NewFakeService()
action = NewGetTask(taskService)
})
It("is synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("returns a running task", func() {
taskService.StartedTasks["fake-task-id"] = boshtask.Task{
ID: "fake-task-id",
State: boshtask.TaskStateRunning,
}
taskValue, err := action.Run("fake-task-id")
Expect(err).ToNot(HaveOccurred())
boshassert.MatchesJSONString(GinkgoT(), taskValue, `{"agent_task_id":"fake-task-id","state":"running"}`)
})
It("returns a failed task", func() {
taskService.StartedTasks["fake-task-id"] = boshtask.Task{
ID: "fake-task-id",
State: boshtask.TaskStateFailed,
Error: errors.New("fake-task-error"),
}
taskValue, err := action.Run("fake-task-id")
Expect(err).To(HaveOccurred())
Expect("fake-task-error").To(Equal(err.Error()))
boshassert.MatchesJSONString(GinkgoT(), taskValue, `null`)
})
It("returns a successful task", func() {
taskService.StartedTasks["fake-task-id"] = boshtask.Task{
ID: "fake-task-id",
State: boshtask.TaskStateDone,
Value: "some-task-value",
}
taskValue, err := action.Run("fake-task-id")
Expect(err).ToNot(HaveOccurred())
boshassert.MatchesJSONString(GinkgoT(), taskValue, `"some-task-value"`)
})
It("returns error when task is not found", func() {
taskService.StartedTasks = map[string]boshtask.Task{}
_, err := action.Run("fake-task-id")
Expect(err).To(HaveOccurred())
Expect("Task with id fake-task-id could not be found").To(Equal(err.Error()))
})
})
}