本文整理匯總了Golang中bosh/agent/applier/applyspec/fakes.FakeV1Service類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeV1Service類的具體用法?Golang FakeV1Service怎麽用?Golang FakeV1Service使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeV1Service類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
Describe("Agent", func() {
var (
agent Agent
logger boshlog.Logger
handler *fakembus.FakeHandler
platform *fakeplatform.FakePlatform
actionDispatcher *FakeActionDispatcher
alertBuilder *fakealert.FakeAlertBuilder
alertSender AlertSender
jobSupervisor *fakejobsuper.FakeJobSupervisor
specService *fakeas.FakeV1Service
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelDebug)
handler = &fakembus.FakeHandler{}
platform = fakeplatform.NewFakePlatform()
actionDispatcher = &FakeActionDispatcher{}
alertBuilder = fakealert.NewFakeAlertBuilder()
alertSender = NewAlertSender(handler, alertBuilder)
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
agent = New(logger, handler, platform, actionDispatcher, alertSender, jobSupervisor, specService, 5*time.Millisecond)
})
Describe("Run", func() {
It("lets dispatcher handle requests arriving via handler", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
expectedResp := boshhandler.NewValueResponse("pong")
actionDispatcher.DispatchResp = expectedResp
req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
resp := handler.RunFunc(req)
Expect(actionDispatcher.DispatchReq).To(Equal(req))
Expect(resp).To(Equal(expectedResp))
})
It("resumes persistent actions *before* dispatching new requests", func() {
resumedBeforeStartingToDispatch := false
handler.RunCallBack = func() {
resumedBeforeStartingToDispatch = actionDispatcher.ResumedPreviouslyDispatchedTasks
}
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(resumedBeforeStartingToDispatch).To(BeTrue())
})
Context("when heartbeats can be sent", func() {
BeforeEach(func() {
handler.KeepOnRunning()
})
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() {
// 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
//.........這裏部分代碼省略.........
示例2:
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "bosh/agent/action"
boshas "bosh/agent/applier/applyspec"
fakeas "bosh/agent/applier/applyspec/fakes"
boshsys "bosh/system"
fakesys "bosh/system/fakes"
)
var _ = Describe("RunErrand", func() {
var (
specService *fakeas.FakeV1Service
cmdRunner *fakesys.FakeCmdRunner
action RunErrandAction
)
BeforeEach(func() {
specService = fakeas.NewFakeV1Service()
cmdRunner = fakesys.NewFakeCmdRunner()
action = NewRunErrand(specService, "/fake-jobs-dir", cmdRunner)
})
It("is asynchronous", func() {
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
示例3: init
func init() {
Describe("Agent", func() {
var (
agent Agent
logger boshlog.Logger
handler *fakembus.FakeHandler
platform *fakeplatform.FakePlatform
actionDispatcher *FakeActionDispatcher
alertBuilder *fakealert.FakeAlertBuilder
jobSupervisor *fakejobsuper.FakeJobSupervisor
specService *fakeas.FakeV1Service
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LEVEL_NONE)
handler = &fakembus.FakeHandler{}
platform = fakeplatform.NewFakePlatform()
actionDispatcher = &FakeActionDispatcher{}
alertBuilder = fakealert.NewFakeAlertBuilder()
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
agent = New(logger, handler, platform, actionDispatcher, alertBuilder, jobSupervisor, specService, 5*time.Millisecond)
})
Describe("Run", func() {
It("sets the dispatcher as message handler", func() {
actionDispatcher.DispatchResp = boshhandler.NewValueResponse("pong")
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(handler.ReceivedRun).To(BeTrue())
req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
resp := handler.Func(req)
Expect(req).To(Equal(actionDispatcher.DispatchReq))
Expect(actionDispatcher.DispatchResp).To(Equal(resp))
})
It("resumes persistent actions *before* dispatching new requests", func() {
resumedBefore := false
handler.RunFunc = func() {
resumedBefore = actionDispatcher.ResumedPreviouslyDispatchedTasks
}
err := agent.Run()
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))
})
})
//.........這裏部分代碼省略.........
示例4: init
func init() {
Describe("ApplyAction", func() {
var (
applier *fakeappl.FakeApplier
specService *fakeas.FakeV1Service
settingsService *fakesettings.FakeSettingsService
action ApplyAction
)
BeforeEach(func() {
applier = fakeappl.NewFakeApplier()
specService = fakeas.NewFakeV1Service()
settingsService = &fakesettings.FakeSettingsService{}
action = NewApply(applier, specService, settingsService)
})
It("apply should be asynchronous", func() {
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
Describe("Run", func() {
settings := boshsettings.Settings{AgentID: "fake-agent-id"}
BeforeEach(func() {
settingsService.Settings = settings
})
Context("when desired spec has configuration hash", func() {
currentApplySpec := boshas.V1ApplySpec{ConfigurationHash: "fake-current-config-hash"}
desiredApplySpec := boshas.V1ApplySpec{ConfigurationHash: "fake-desired-config-hash"}
populatedDesiredApplySpec := boshas.V1ApplySpec{
ConfigurationHash: "fake-populated-desired-config-hash",
}
Context("when current spec can be retrieved", func() {
BeforeEach(func() {
specService.Spec = currentApplySpec
})
It("populates dynamic networks in desired spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(specService.PopulateDynamicNetworksSpec).To(Equal(desiredApplySpec))
Expect(specService.PopulateDynamicNetworksSettings).To(Equal(settings))
})
Context("when resolving dynamic networks succeeds", func() {
BeforeEach(func() {
specService.PopulateDynamicNetworksResultSpec = populatedDesiredApplySpec
})
It("runs applier with populated desired spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(applier.Applied).To(BeTrue())
Expect(applier.ApplyCurrentApplySpec).To(Equal(currentApplySpec))
Expect(applier.ApplyDesiredApplySpec).To(Equal(populatedDesiredApplySpec))
})
Context("when applier succeeds applying desired spec", func() {
Context("when saving desires spec as current spec succeeds", func() {
It("returns 'applied' after setting populated desired spec as current spec", func() {
value, err := action.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal("applied"))
Expect(specService.Spec).To(Equal(populatedDesiredApplySpec))
})
})
Context("when saving populated desires spec as current spec fails", func() {
It("returns error because agent was not able to remember that is converged to desired spec", func() {
specService.SetErr = errors.New("fake-set-error")
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-set-error"))
})
})
})
Context("when applier fails applying desired spec", func() {
BeforeEach(func() {
applier.ApplyError = errors.New("fake-apply-error")
})
It("returns error", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-apply-error"))
})
It("does not save desired spec as current spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(specService.Spec).To(Equal(currentApplySpec))
//.........這裏部分代碼省略.........
示例5: init
func init() {
Describe("DrainAction", func() {
var (
notifier *fakenotif.FakeNotifier
specService *fakeas.FakeV1Service
drainScriptProvider *fakedrain.FakeDrainScriptProvider
jobSupervisor *fakejobsuper.FakeJobSupervisor
action DrainAction
)
BeforeEach(func() {
notifier = fakenotif.NewFakeNotifier()
specService = fakeas.NewFakeV1Service()
drainScriptProvider = fakedrain.NewFakeDrainScriptProvider()
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
action = NewDrain(notifier, specService, drainScriptProvider, jobSupervisor)
})
BeforeEach(func() {
drainScriptProvider.NewDrainScriptDrainScript.ExistsBool = true
})
It("is asynchronous", func() {
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
Context("when drain update is requested", func() {
act := func() (int, error) { return action.Run(DrainTypeUpdate, boshas.V1ApplySpec{}) }
Context("when current agent has a job spec template", func() {
var currentSpec boshas.V1ApplySpec
BeforeEach(func() {
currentSpec = boshas.V1ApplySpec{}
currentSpec.JobSpec.Template = "foo"
specService.Spec = currentSpec
})
It("unmonitors services so that drain scripts can kill processes on their own", func() {
value, err := act()
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal(1))
Expect(jobSupervisor.Unmonitored).To(BeTrue())
})
Context("when unmonitoring services succeeds", func() {
It("does not notify of job shutdown", func() {
value, err := act()
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal(1))
Expect(notifier.NotifiedShutdown).To(BeFalse())
})
Context("when new apply spec is provided", func() {
newSpec := boshas.V1ApplySpec{
PackageSpecs: map[string]boshas.PackageSpec{
"foo": boshas.PackageSpec{
Name: "foo",
Sha1: "foo-sha1-new",
},
},
}
Context("when drain script exists", func() {
It("runs drain script with job_shutdown param", func() {
value, err := action.Run(DrainTypeUpdate, newSpec)
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal(1))
Expect(drainScriptProvider.NewDrainScriptTemplateName).To(Equal("foo"))
Expect(drainScriptProvider.NewDrainScriptDrainScript.DidRun).To(BeTrue())
params := drainScriptProvider.NewDrainScriptDrainScript.RunParams
Expect(params).To(Equal(boshdrain.NewUpdateDrainParams(currentSpec, newSpec)))
})
Context("when drain script runs and errs", func() {
It("returns error", func() {
drainScriptProvider.NewDrainScriptDrainScript.RunError = errors.New("fake-drain-run-error")
value, err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-drain-run-error"))
Expect(value).To(Equal(0))
})
})
})
Context("when drain script does not exist", func() {
It("returns 0", func() {
drainScriptProvider.NewDrainScriptDrainScript.ExistsBool = false
value, err := act()
Expect(err).ToNot(HaveOccurred())
//.........這裏部分代碼省略.........
示例6:
fakeas "bosh/agent/applier/applyspec/fakes"
boshassert "bosh/assert"
fakejobsuper "bosh/jobsupervisor/fakes"
boshntp "bosh/platform/ntp"
fakentp "bosh/platform/ntp/fakes"
boshvitals "bosh/platform/vitals"
fakevitals "bosh/platform/vitals/fakes"
boshsettings "bosh/settings"
fakesettings "bosh/settings/fakes"
)
var _ = Describe("GetState", func() {
var (
settings *fakesettings.FakeSettingsService
specService *fakeas.FakeV1Service
jobSupervisor *fakejobsuper.FakeJobSupervisor
vitalsService *fakevitals.FakeService
action GetStateAction
)
BeforeEach(func() {
settings = &fakesettings.FakeSettingsService{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
vitalsService = fakevitals.NewFakeService()
action = NewGetState(settings, specService, jobSupervisor, vitalsService, &fakentp.FakeService{
GetOffsetNTPOffset: boshntp.NTPInfo{
Offset: "0.34958",
Timestamp: "12 Oct 17:37:58",
},
})