本文整理匯總了Golang中bosh/system/fakes.FakeFileSystem.RemoveAllError方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.RemoveAllError方法的具體用法?Golang FakeFileSystem.RemoveAllError怎麽用?Golang FakeFileSystem.RemoveAllError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.RemoveAllError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
})
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())
})
})
})
}
示例2: init
//.........這裏部分代碼省略.........
Expect(err.Error()).To(ContainSubstring("fake-fetch-error"))
Expect(service.GetSettings()).To(Equal(Settings{}))
})
})
Context("when no settings file exists", func() {
It("returns any error from the fetcher", func() {
err := service.LoadSettings()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-fetch-error"))
Expect(service.GetSettings()).To(Equal(Settings{}))
})
})
})
})
Describe("InvalidateSettings", func() {
It("removes the settings file", func() {
service, fs := buildService(nil)
fs.WriteFile("/setting/path", []byte(`{}`))
err := service.InvalidateSettings()
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists("/setting/path")).To(BeFalse())
})
It("returns err if removing settings file errored", func() {
service, fs := buildService(nil)
fs.RemoveAllError = errors.New("fs-remove-all-error")
err := service.InvalidateSettings()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-remove-all-error"))
})
})
Describe("GetSettings", func() {
var (
loadedSettings Settings
service Service
)
BeforeEach(func() {
loadedSettings = Settings{AgentID: "some-agent-id"}
})
JustBeforeEach(func() {
service, _ = buildService(func() (Settings, error) { return loadedSettings, nil })
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
})
Context("when there is are no dynamic networks", func() {
It("returns settings without modifying any networks", func() {
Expect(service.GetSettings()).To(Equal(loadedSettings))
})
It("does not try to determine default network", func() {
_ = service.GetSettings()
Expect(platform.GetDefaultNetworkCalled).To(BeFalse())
})
示例3:
BeforeEach(func() {
_, _, err := fileBundle.Install(sourcePath)
Expect(err).NotTo(HaveOccurred())
_, _, err = fileBundle.Enable()
Expect(err).NotTo(HaveOccurred())
})
It("does not return error and removes the symlink", func() {
err := fileBundle.Disable()
Expect(err).NotTo(HaveOccurred())
Expect(fs.FileExists(enablePath)).To(BeFalse())
})
It("returns error when bundle cannot be disabled", func() {
fs.RemoveAllError = errors.New("fake-removeall-error")
err := fileBundle.Disable()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-removeall-error"))
})
})
Context("where the enabled path target is a different installed version", func() {
newerInstallPath := "/newer-install-path"
BeforeEach(func() {
_, _, err := fileBundle.Install(sourcePath)
Expect(err).NotTo(HaveOccurred())
_, _, err = fileBundle.Enable()
示例4: init
//.........這裏部分代碼省略.........
})
Context("when writing job configuration fails", func() {
It("returns error", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
})
Context("when reading configuration from config path fails", func() {
It("returns error", func() {
fs.ReadFileError = errors.New("fake-read-error")
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
})
})
})
Describe("RemoveAllJobs", func() {
Context("when jobs directory removal succeeds", func() {
It("does not return error because all jobs are removed from monit", func() {
jobsDir := dirProvider.MonitJobsDir()
jobBasename := "/0000_router.monitrc"
fs.WriteFileString(jobsDir+jobBasename, "fake-added-job")
err := monit.RemoveAllJobs()
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists(jobsDir)).To(BeFalse())
Expect(fs.FileExists(jobsDir + jobBasename)).To(BeFalse())
})
})
Context("when jobs directory removal fails", func() {
It("returns error if removing jobs directory fails", func() {
fs.RemoveAllError = errors.New("fake-remove-all-error")
err := monit.RemoveAllJobs()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-remove-all-error"))
})
})
})
Describe("Unmonitor", func() {
BeforeEach(func() {
client.ServicesInGroupServices = []string{"fake-srv-1", "fake-srv-2", "fake-srv-3"}
client.UnmonitorServiceErrs = []error{nil, nil, nil}
})
Context("when all services succeed to be unmonitored", func() {
It("returns no error because all services got unmonitored", func() {
err := monit.Unmonitor()
Expect(err).ToNot(HaveOccurred())
Expect(client.ServicesInGroupName).To(Equal("vcap"))
Expect(client.UnmonitorServiceNames).To(Equal(
[]string{"fake-srv-1", "fake-srv-2", "fake-srv-3"}))
})
})
Context("when at least one service fails to be unmonitored", func() {
BeforeEach(func() {
client.UnmonitorServiceErrs = []error{
nil, errors.New("fake-unmonitor-error"), nil,
}
})
It("returns first unmonitor error", func() {
err := monit.Unmonitor()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-unmonitor-error"))
})
It("only tries to unmonitor services before the first unmonitor error", func() {
err := monit.Unmonitor()
Expect(err).To(HaveOccurred())
Expect(client.ServicesInGroupName).To(Equal("vcap"))
Expect(client.UnmonitorServiceNames).To(Equal([]string{"fake-srv-1", "fake-srv-2"}))
})
})
Context("when failed retrieving list of services", func() {
It("returns error", func() {
client.ServicesInGroupErr = errors.New("fake-services-error")
err := monit.Unmonitor()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-services-error"))
})
})
})
})
}