本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/infrastructure/fakes.FakeSettingsSource类的典型用法代码示例。如果您正苦于以下问题:Golang FakeSettingsSource类的具体用法?Golang FakeSettingsSource怎么用?Golang FakeSettingsSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeSettingsSource类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
Describe("settingsService", func() {
var (
fs *fakesys.FakeFileSystem
fakeDefaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
fakeSettingsSource *fakes.FakeSettingsSource
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
fakeDefaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
fakeSettingsSource = &fakes.FakeSettingsSource{}
})
buildService := func() (Service, *fakesys.FakeFileSystem) {
logger := boshlog.NewLogger(boshlog.LevelNone)
service := NewService(fs, "/setting/path.json", fakeSettingsSource, fakeDefaultNetworkResolver, logger)
return service, fs
}
Describe("LoadSettings", func() {
var (
fetchedSettings Settings
fetcherFuncErr error
service Service
)
BeforeEach(func() {
fetchedSettings = Settings{}
fetcherFuncErr = nil
})
JustBeforeEach(func() {
fakeSettingsSource.SettingsValue = fetchedSettings
fakeSettingsSource.SettingsErr = fetcherFuncErr
service, fs = buildService()
})
Context("when settings fetcher succeeds fetching settings", func() {
BeforeEach(func() {
fetchedSettings = Settings{AgentID: "some-new-agent-id"}
})
Context("when settings contain at most one dynamic network", func() {
BeforeEach(func() {
fetchedSettings.Networks = Networks{
"fake-net-1": Network{Type: NetworkTypeDynamic},
}
})
It("updates the service with settings from the fetcher", func() {
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
Expect(service.GetSettings().AgentID).To(Equal("some-new-agent-id"))
})
It("persists settings to the settings file", func() {
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
json, err := json.Marshal(fetchedSettings)
Expect(err).NotTo(HaveOccurred())
fileContent, err := fs.ReadFile("/setting/path.json")
Expect(err).NotTo(HaveOccurred())
Expect(fileContent).To(Equal(json))
})
It("returns any error from writing to the setting file", func() {
fs.WriteFileError = errors.New("fs-write-file-error")
err := service.LoadSettings()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-write-file-error"))
})
})
})
Context("when settings fetcher fails fetching settings", func() {
BeforeEach(func() {
fetcherFuncErr = errors.New("fake-fetch-error")
})
Context("when a settings file exists", func() {
Context("when settings contain at most one dynamic network", func() {
BeforeEach(func() {
fs.WriteFile("/setting/path.json", []byte(`{
"agent_id":"some-agent-id",
"networks": {"fake-net-1": {"type": "dynamic"}}
}`))
fakeDefaultNetworkResolver.GetDefaultNetworkNetwork = Network{
IP: "fake-resolved-ip",
Netmask: "fake-resolved-netmask",
Gateway: "fake-resolved-gateway",
}
})
It("returns settings from the settings file with resolved network", func() {
err := service.LoadSettings()
//.........这里部分代码省略.........
示例2: 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() {
//.........这里部分代码省略.........
示例3:
var _ = Describe("MultiSettingsSource", func() {
var (
source boshsettings.Source
)
Context("when there are no sources", func() {
It("returns an error when there are no sources", func() {
_, err := NewMultiSettingsSource([]boshsettings.Source{}...)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("MultiSettingsSource requires to have at least one source"))
})
})
Context("when there is at least one source", func() {
var (
source1 fakeinf.FakeSettingsSource
source2 fakeinf.FakeSettingsSource
)
BeforeEach(func() {
source1 = fakeinf.FakeSettingsSource{
PublicKey: "fake-public-key-1",
PublicKeyErr: errors.New("fake-public-key-err-1"),
SettingsValue: boshsettings.Settings{AgentID: "fake-settings-1"},
SettingsErr: errors.New("fake-settings-err-1"),
}
source2 = fakeinf.FakeSettingsSource{
PublicKey: "fake-public-key-2",
PublicKeyErr: errors.New("fake-public-key-err-2"),