本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/agent/applier/fakes.FakeApplier类的典型用法代码示例。如果您正苦于以下问题:Golang FakeApplier类的具体用法?Golang FakeApplier怎么用?Golang FakeApplier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeApplier类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
Describe("Start", func() {
var (
jobSupervisor *fakejobsuper.FakeJobSupervisor
applier *fakeappl.FakeApplier
specService *fakeas.FakeV1Service
action StartAction
)
BeforeEach(func() {
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
applier = fakeappl.NewFakeApplier()
specService = fakeas.NewFakeV1Service()
action = NewStart(jobSupervisor, applier, specService)
})
It("is synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("returns started", func() {
started, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(started).To(Equal("started"))
})
It("starts monitor services", func() {
_, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(jobSupervisor.Started).To(BeTrue())
})
It("configures jobs", func() {
_, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(applier.Configured).To(BeTrue())
})
It("apply errs if a job fails configuring", func() {
applier.ConfiguredError = errors.New("fake error")
_, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Configuring jobs"))
})
})
}
示例2: init
func init() {
Describe("ApplyAction", func() {
var (
applier *fakeappl.FakeApplier
specService *fakeas.FakeV1Service
settingsService *fakesettings.FakeSettingsService
dirProvider boshdir.Provider
action ApplyAction
fs boshsys.FileSystem
)
BeforeEach(func() {
applier = fakeappl.NewFakeApplier()
specService = fakeas.NewFakeV1Service()
settingsService = &fakesettings.FakeSettingsService{}
dirProvider = boshdir.NewProvider("/var/vcap")
fs = fakesys.NewFakeFileSystem()
action = NewApply(applier, specService, settingsService, dirProvider.InstanceDir(), fs)
})
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.PopulateDHCPNetworksSpec).To(Equal(desiredApplySpec))
Expect(specService.PopulateDHCPNetworksSettings).To(Equal(settings))
})
Context("when resolving dynamic networks succeeds", func() {
BeforeEach(func() {
specService.PopulateDHCPNetworksResultSpec = 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("desired spec has id, instance name, deployment name, and az", func() {
BeforeEach(func() {
desiredApplySpec = boshas.V1ApplySpec{ConfigurationHash: "fake-desired-config-hash", NodeID: "node-id01-123f-r2344", AvailabilityZone: "ex-az", Deployment: "deployment-name", Name: "instance-name"}
specService.PopulateDHCPNetworksResultSpec = desiredApplySpec
})
It("returns 'applied' and writes the id, instance name, deployment name, and az to files in the instance directory", func() {
value, err := action.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal("applied"))
instanceDir := dirProvider.InstanceDir()
id, err := fs.ReadFileString(path.Join(instanceDir, "id"))
Expect(err).ToNot(HaveOccurred())
Expect(id).To(Equal(desiredApplySpec.NodeID))
az, err := fs.ReadFileString(path.Join(instanceDir, "az"))
Expect(err).ToNot(HaveOccurred())
Expect(az).To(Equal(desiredApplySpec.AvailabilityZone))
instanceName, err := fs.ReadFileString(path.Join(instanceDir, "name"))
//.........这里部分代码省略.........
示例3: 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))
//.........这里部分代码省略.........
示例4:
package action_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/action"
boshas "github.com/cloudfoundry/bosh-agent/agent/applier/applyspec"
fakeappl "github.com/cloudfoundry/bosh-agent/agent/applier/fakes"
)
var _ = Describe("PrepareAction", func() {
var (
applier *fakeappl.FakeApplier
action PrepareAction
)
BeforeEach(func() {
applier = fakeappl.NewFakeApplier()
action = NewPrepare(applier)
})
AssertActionIsAsynchronous(action)
AssertActionIsNotPersistent(action)
AssertActionIsLoggable(action)
AssertActionIsNotResumable(action)
AssertActionIsNotCancelable(action)
Describe("Run", func() {
示例5: init
func init() {
Describe("Start", func() {
var (
jobSupervisor *fakejobsuper.FakeJobSupervisor
applier *fakeappl.FakeApplier
specService *fakeas.FakeV1Service
platform *fakeplatform.FakePlatform
settingsService *fakesettings.FakeSettingsService
logger boshlog.Logger
dualDCSupport *nimbus.DualDCSupport
action StartAction
)
BeforeEach(func() {
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
applier = fakeappl.NewFakeApplier()
specService = fakeas.NewFakeV1Service()
action = NewStart(jobSupervisor, applier, specService, dualDCSupport, platform)
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
settingsService = &fakesettings.FakeSettingsService{}
dualDCSupport = nimbus.NewDualDCSupport(
platform.GetRunner(),
platform.GetFs(),
platform.GetDirProvider(),
specService,
settingsService,
logger,
)
action = NewStart(jobSupervisor, applier, specService, dualDCSupport, platform)
})
It("is synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("returns started", func() {
started, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(started).To(Equal("started"))
})
It("starts monitor services", func() {
_, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(jobSupervisor.Started).To(BeTrue())
})
It("configures jobs", func() {
_, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(applier.Configured).To(BeTrue())
})
It("apply errs if a job fails configuring", func() {
applier.ConfiguredError = errors.New("fake error")
_, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Configuring jobs"))
})
})
}