當前位置: 首頁>>代碼示例>>Golang>>正文


Golang fakes.FakeService類代碼示例

本文整理匯總了Golang中bosh/agent/task/fakes.FakeService的典型用法代碼示例。如果您正苦於以下問題:Golang FakeService類的具體用法?Golang FakeService怎麽用?Golang FakeService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FakeService類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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()))
		})
	})
}
開發者ID:punalpatel,項目名稱:bosh,代碼行數:65,代碼來源:get_task_test.go

示例2:

import (
	"errors"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "bosh/agent/action"
	boshtask "bosh/agent/task"
	faketask "bosh/agent/task/fakes"
	boshassert "bosh/assert"
)

var _ = 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())
	})
開發者ID:amulyas,項目名稱:bosh-cloudstack-cpi,代碼行數:30,代碼來源:get_task_test.go

示例3: 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())

//.........這裏部分代碼省略.........
開發者ID:velankanisys,項目名稱:bosh,代碼行數:101,代碼來源:action_dispatcher_test.go


注:本文中的bosh/agent/task/fakes.FakeService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。