本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/agent/task/fakes.FakeService類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeService類的具體用法?Golang FakeService怎麽用?Golang FakeService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeService類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/action"
boshtask "github.com/cloudfoundry/bosh-agent/agent/task"
faketask "github.com/cloudfoundry/bosh-agent/agent/task/fakes"
boshassert "github.com/cloudfoundry/bosh-utils/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())
})
示例2: init
func init() {
Describe("actionDispatcher", func() {
var (
logger *fakes.FakeLogger
taskService *faketask.FakeService
taskManager *faketask.FakeManager
actionFactory *fakeaction.FakeFactory
actionRunner *fakeaction.FakeRunner
dispatcher ActionDispatcher
)
BeforeEach(func() {
logger = &fakes.FakeLogger{}
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("Action Payload Logging", func() {
var (
action *fakeaction.TestAction
req boshhandler.Request
)
Context("action is loggable", func() {
BeforeEach(func() {
req = boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
action = &fakeaction.TestAction{Loggable: true}
actionFactory.RegisterAction("fake-action", action)
dispatcher.Dispatch(req)
})
It("logs the payload", func() {
Expect(logger.DebugWithDetailsCallCount()).To(Equal(1))
_, message, args := logger.DebugWithDetailsArgsForCall(0)
Expect(message).To(Equal("Payload"))
Expect(args[0]).To(Equal(req.Payload))
})
})
Context("action is not loggable", func() {
BeforeEach(func() {
req = boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
action = &fakeaction.TestAction{Loggable: false}
actionFactory.RegisterAction("fake-action", action)
dispatcher.Dispatch(req)
})
It("does not log the payload", func() {
Expect(logger.DebugWithDetailsCallCount()).To(Equal(0))
})
})
})
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}
//.........這裏部分代碼省略.........