本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/settings/fakes.FakeSettingsService類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeSettingsService類的具體用法?Golang FakeSettingsService怎麽用?Golang FakeSettingsService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeSettingsService類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
Describe("bootstrap", func() {
Describe("Run", func() {
var (
platform *fakeplatform.FakePlatform
dirProvider boshdir.Provider
settingsSource *fakeinf.FakeSettingsSource
settingsService *fakesettings.FakeSettingsService
)
BeforeEach(func() {
platform = fakeplatform.NewFakePlatform()
dirProvider = boshdir.NewProvider("/var/vcap")
settingsSource = &fakeinf.FakeSettingsSource{}
settingsService = &fakesettings.FakeSettingsService{}
})
bootstrap := func() error {
logger := boshlog.NewLogger(boshlog.LevelNone)
return NewBootstrap(platform, dirProvider, settingsService, logger).Run()
}
It("sets up runtime configuration", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupRuntimeConfigurationWasInvoked).To(BeTrue())
})
Describe("SSH tunnel setup for registry", func() {
It("returns error without configuring ssh on the platform if getting public key fails", func() {
settingsService.PublicKeyErr = errors.New("fake-get-public-key-err")
err := bootstrap()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-public-key-err"))
Expect(platform.SetupSSHCalled).To(BeFalse())
})
Context("when public key is not empty", func() {
BeforeEach(func() {
settingsService.PublicKey = "fake-public-key"
})
It("gets the public key and sets up ssh via the platform", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupSSHPublicKey).To(Equal("fake-public-key"))
Expect(platform.SetupSSHUsername).To(Equal("vcap"))
})
It("returns error if configuring ssh on the platform fails", func() {
platform.SetupSSHErr = errors.New("fake-setup-ssh-err")
err := bootstrap()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-setup-ssh-err"))
})
})
Context("when public key key is empty", func() {
BeforeEach(func() {
settingsSource.PublicKey = ""
})
It("gets the public key and does not setup SSH", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupSSHCalled).To(BeFalse())
})
})
})
It("sets up hostname", func() {
settingsService.Settings.AgentID = "foo-bar-baz-123"
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupHostnameHostname).To(Equal("foo-bar-baz-123"))
})
It("fetches initial settings", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(settingsService.SettingsWereLoaded).To(BeTrue())
})
It("returns error from loading initial settings", func() {
settingsService.LoadSettingsError = errors.New("fake-load-error")
err := bootstrap()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-load-error"))
})
It("sets up networking", func() {
//.........這裏部分代碼省略.........
示例2:
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/action"
fakeplatform "github.com/cloudfoundry/bosh-agent/platform/fakes"
fakesettings "github.com/cloudfoundry/bosh-agent/settings/fakes"
)
var _ = Describe("prepareConfigureNetworks", func() {
var (
action PrepareConfigureNetworksAction
platform *fakeplatform.FakePlatform
settingsService *fakesettings.FakeSettingsService
)
BeforeEach(func() {
platform = fakeplatform.NewFakePlatform()
settingsService = &fakesettings.FakeSettingsService{}
action = NewPrepareConfigureNetworks(platform, settingsService)
})
AssertActionIsNotAsynchronous(action)
AssertActionIsNotPersistent(action)
AssertActionIsLoggable(action)
AssertActionIsNotResumable(action)
AssertActionIsNotCancelable(action)
示例3: 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"))
//.........這裏部分代碼省略.........
示例4: init
func init() {
Describe("prepareNetworkChange", func() {
var (
action PrepareNetworkChangeAction
fs *fakesys.FakeFileSystem
settingsService *fakesettings.FakeSettingsService
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
settingsService = &fakesettings.FakeSettingsService{}
action = NewPrepareNetworkChange(fs, settingsService, fakeactions.NewFakeAgentKiller())
})
It("is synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("invalidates settings so that load settings cannot fall back on old settings", func() {
resp, err := action.Run()
Expect(err).NotTo(HaveOccurred())
Expect(resp).To(Equal("ok"))
Expect(settingsService.SettingsWereInvalidated).To(BeTrue())
})
Context("when settings invalidation succeeds", func() {
Context("when the network rules file can be removed", func() {
It("removes the network rules file", func() {
fs.WriteFile("/etc/udev/rules.d/70-persistent-net.rules", []byte{})
resp, err := action.Run()
Expect(err).NotTo(HaveOccurred())
Expect(resp).To(Equal("ok"))
Expect(fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules")).To(BeFalse())
})
})
Context("when the network rules file cannot be removed", func() {
BeforeEach(func() {
fs.RemoveAllError = errors.New("fake-remove-all-error")
})
It("returns error from removing the network rules file", func() {
resp, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-remove-all-error"))
Expect(resp).To(BeNil())
})
})
})
Context("when settings invalidation fails", func() {
BeforeEach(func() {
settingsService.InvalidateSettingsError = errors.New("fake-invalidate-error")
})
It("returns error early if settings err invalidating", func() {
resp, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-invalidate-error"))
Expect(resp).To(BeNil())
})
It("does not remove the network rules file", func() {
fs.WriteFile("/etc/udev/rules.d/70-persistent-net.rules", []byte{})
action.Run()
Expect(fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules")).To(BeTrue())
})
})
})
}
示例5: 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))
//.........這裏部分代碼省略.........
示例6:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/agent/action"
fakeplatform "github.com/cloudfoundry/bosh-agent/platform/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
boshdirs "github.com/cloudfoundry/bosh-agent/settings/directories"
fakesettings "github.com/cloudfoundry/bosh-agent/settings/fakes"
boshassert "github.com/cloudfoundry/bosh-utils/assert"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
var _ = Describe("MountDiskAction", func() {
var (
settingsService *fakesettings.FakeSettingsService
platform *fakeplatform.FakePlatform
action MountDiskAction
logger boshlog.Logger
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{}
platform = fakeplatform.NewFakePlatform()
dirProvider := boshdirs.NewProvider("/fake-base-dir")
logger = boshlog.NewLogger(boshlog.LevelNone)
action = NewMountDisk(settingsService, platform, dirProvider, logger)
})
AssertActionIsAsynchronous(action)
AssertActionIsNotPersistent(action)
AssertActionIsLoggable(action)
示例7:
"errors"
. "github.com/cloudfoundry/bosh-agent/agent/action"
"github.com/cloudfoundry/bosh-agent/platform/cert/fakes"
fakeplatform "github.com/cloudfoundry/bosh-agent/platform/fakes"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
fakesettings "github.com/cloudfoundry/bosh-agent/settings/fakes"
"github.com/cloudfoundry/bosh-utils/logger"
"path/filepath"
)
var _ = Describe("UpdateSettings", func() {
var (
action UpdateSettingsAction
certManager *fakes.FakeManager
settingsService *fakesettings.FakeSettingsService
log logger.Logger
platform *fakeplatform.FakePlatform
newUpdateSettings boshsettings.UpdateSettings
)
BeforeEach(func() {
log = logger.NewLogger(logger.LevelNone)
certManager = new(fakes.FakeManager)
settingsService = &fakesettings.FakeSettingsService{}
platform = fakeplatform.NewFakePlatform()
action = NewUpdateSettings(settingsService, platform, certManager, log)
newUpdateSettings = boshsettings.UpdateSettings{}
})
AssertActionIsAsynchronous(action)
AssertActionIsNotPersistent(action)