本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.RemoveAll方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.RemoveAll方法的具體用法?Golang FakeFileSystem.RemoveAll怎麽用?Golang FakeFileSystem.RemoveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.RemoveAll方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
blobstore := NewExternalBlobstore("fake-provider", options, fs, runner, uuidGen, configPath)
err := blobstore.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("not found in PATH"))
})
})
Describe("Get", func() {
It("external get", func() {
tempFile, err := fs.TempFile("bosh-blobstore-external-TestGet")
Expect(err).ToNot(HaveOccurred())
fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
fileName, err := blobstore.Get("fake-blob-id", "")
Expect(err).ToNot(HaveOccurred())
Expect(len(runner.RunCommands)).To(Equal(1))
Expect(runner.RunCommands[0]).To(Equal([]string{
"bosh-blobstore-fake-provider", "-c", configPath, "get",
"fake-blob-id",
tempFile.Name(),
}))
Expect(fileName).To(Equal(tempFile.Name()))
Expect(fs.FileExists(tempFile.Name())).To(BeTrue())
})
示例2:
Context("when dependency installation fails", func() {
JustBeforeEach(func() {
fakeExtractor.ExtractReturns(errors.New("fake-install-error"))
})
It("returns an error", func() {
_, _, err := compiler.Compile(pkg)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-install-error"))
})
})
Context("when the packaging script does not exist", func() {
JustBeforeEach(func() {
err := fs.RemoveAll(path.Join(pkg.ExtractedPath, "packaging"))
Expect(err).ToNot(HaveOccurred())
})
It("returns error", func() {
_, _, err := compiler.Compile(pkg)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Packaging script for package 'fake-package-1' not found"))
})
})
Context("when the packaging script fails", func() {
JustBeforeEach(func() {
fakeResult := fakesys.FakeCmdResult{
ExitStatus: 1,
Error: errors.New("fake-error"),
示例3:
var (
comboManifestPath string
fakeFs *fakesys.FakeFileSystem
parser Parser
)
BeforeEach(func() {
comboManifestPath = "fake-deployment-path"
fakeFs = fakesys.NewFakeFileSystem()
logger := boshlog.NewLogger(boshlog.LevelNone)
parser = NewParser(fakeFs, logger)
})
Context("when combo manifest path does not exist", func() {
BeforeEach(func() {
err := fakeFs.RemoveAll(comboManifestPath)
Expect(err).ToNot(HaveOccurred())
})
It("returns an error", func() {
_, err := parser.Parse(comboManifestPath)
Expect(err).To(HaveOccurred())
})
})
Context("when parser fails to read the combo manifest file", func() {
BeforeEach(func() {
fakeFs.ReadFileError = errors.New("fake-read-file-error")
})
It("returns an error", func() {
示例4:
fs *fakeboshsys.FakeFileSystem
logFile boshsys.File
)
BeforeEach(func() {
fs = fakeboshsys.NewFakeFileSystem()
var err error
logFile, err = fs.TempFile("file-logger-test")
Expect(err).ToNot(HaveOccurred())
err = logFile.Close()
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
logFile.Close()
fs.RemoveAll(logFile.Name())
})
It("logs the formatted DEBUG message to the file", func() {
logger, logFile, err := New(boshlog.LevelDebug, logFile.Name(), DefaultLogFileMode, fs)
Expect(err).ToNot(HaveOccurred())
logger.Debug("TAG", "some %s info to log", "awesome")
contents, err := fs.ReadFileString(logFile.Name())
Expect(err).ToNot(HaveOccurred())
expectedContent := expectedLogFormat("TAG", "DEBUG - some awesome info to log")
Expect(contents).To(MatchRegexp(expectedContent))
})
示例5: rootDesc
//.........這裏部分代碼省略.........
installationManifest.Registry,
fakeVMManager,
mockBlobstore,
gomock.Any(),
).Do(func(_, _, _, _, _, _ interface{}, stage biui.Stage) {
Expect(fakeStage.SubStages).To(ContainElement(stage))
}).Return(mockDeployment, nil).AnyTimes()
expectCPIReleaseExtract = mockReleaseExtractor.EXPECT().Extract(cpiReleaseTarballPath).Return(fakeCPIRelease, nil).AnyTimes()
expectNewCloud = mockCloudFactory.EXPECT().NewCloud(installation, directorID).Return(cloud, nil).AnyTimes()
})
It("prints the deployment manifest and state file", func() {
err := command.Run(fakeStage, []string{deploymentManifestPath})
Expect(err).NotTo(HaveOccurred())
Expect(stdOut).To(gbytes.Say("Deployment manifest: '/path/to/manifest.yml'"))
Expect(stdOut).To(gbytes.Say("Deployment state: '/path/to/manifest-state.json'"))
})
It("does not migrate the legacy bosh-deployments.yml if manifest-state.json exists", func() {
err := fakeFs.WriteFileString(deploymentStatePath, "{}")
Expect(err).ToNot(HaveOccurred())
expectLegacyMigrate.Times(0)
err = command.Run(fakeStage, []string{deploymentManifestPath})
Expect(err).NotTo(HaveOccurred())
Expect(fakeInstallationParser.ParsePath).To(Equal(deploymentManifestPath))
})
It("migrates the legacy bosh-deployments.yml if manifest-state.json does not exist", func() {
err := fakeFs.RemoveAll(deploymentStatePath)
Expect(err).ToNot(HaveOccurred())
expectLegacyMigrate.Return(true, nil).Times(1)
err = command.Run(fakeStage, []string{deploymentManifestPath})
Expect(err).NotTo(HaveOccurred())
Expect(fakeInstallationParser.ParsePath).To(Equal(deploymentManifestPath))
Expect(stdOut).To(gbytes.Say("Deployment manifest: '/path/to/manifest.yml'"))
Expect(stdOut).To(gbytes.Say("Deployment state: '/path/to/manifest-state.json'"))
Expect(stdOut).To(gbytes.Say("Migrated legacy deployments file: '/path/to/bosh-deployments.yml'"))
})
It("sets the temp root", func() {
err := command.Run(fakeStage, []string{deploymentManifestPath})
Expect(err).NotTo(HaveOccurred())
Expect(fakeFs.TempRootPath).To(Equal("fake-install-dir/fake-installation-id/tmp"))
})
Context("when setting the temp root fails", func() {
It("returns an error", func() {
fakeFs.ChangeTempRootErr = errors.New("fake ChangeTempRootErr")
err := command.Run(fakeStage, []string{deploymentManifestPath})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Setting temp root: fake ChangeTempRootErr"))
})
})
It("parses the installation manifest", func() {
err := command.Run(fakeStage, []string{deploymentManifestPath})
Expect(err).NotTo(HaveOccurred())
Expect(fakeInstallationParser.ParsePath).To(Equal(deploymentManifestPath))
示例6:
Expect(target.Path()).To(Equal("/.bosh_init/installations/fake-uuid-1"))
})
It("saves the new installation_id", func() {
_, err := targetProvider.NewTarget()
Expect(err).ToNot(HaveOccurred())
deploymentState, err := deploymentStateService.Load()
Expect(err).ToNot(HaveOccurred())
Expect(deploymentState.InstallationID).To(Equal("fake-uuid-1"))
})
})
Context("when the deployment state does not exist", func() {
BeforeEach(func() {
err := fakeFS.RemoveAll(configPath)
Expect(err).ToNot(HaveOccurred())
})
It("generates a new installation_id & returns a target based on it", func() {
target, err := targetProvider.NewTarget()
Expect(err).ToNot(HaveOccurred())
Expect(target.Path()).To(Equal("/.bosh_init/installations/fake-uuid-1"))
})
It("saves the new installation_id", func() {
_, err := targetProvider.NewTarget()
Expect(err).ToNot(HaveOccurred())
deploymentState, err := deploymentStateService.Load()
Expect(err).ToNot(HaveOccurred())
示例7:
context,
nil,
)
fakeERBRenderer.SetRenderBehavior(
filepath.Join(srcPath, "monit"),
filepath.Join(dstPath, "monit"),
context,
nil,
)
fs.TempDirDir = dstPath
})
AfterEach(func() {
err := fs.RemoveAll(dstPath)
Expect(err).ToNot(HaveOccurred())
})
Describe("Render", func() {
It("renders job templates", func() {
renderedjob, err := jobRenderer.Render(job, &releaseJobProperties, jobProperties, globalProperties, "fake-deployment-name", "1.2.3.4")
Expect(err).ToNot(HaveOccurred())
Expect(fakeERBRenderer.RenderInputs).To(Equal([]fakebirender.RenderInput{
{
SrcPath: filepath.Join(srcPath, "templates/director.yml.erb"),
DstPath: filepath.Join(renderedjob.Path(), "config/director.yml"),
Context: context,
},
{
示例8:
err := fs.MkdirAll("fake-other-extracted-dir", os.ModePerm)
Expect(err).ToNot(HaveOccurred())
}).Return(otherRelease, nil).AnyTimes()
})
It("extracts all provided releases & finds the cpi release before executing the expected cloud & agent client commands", func() {
expectDeployFlow()
err := newDeployCmd().Run(fakeStage, []string{deploymentManifestPath})
Expect(err).ToNot(HaveOccurred())
})
})
Context("when the deployment state file does not exist", func() {
BeforeEach(func() {
err := fs.RemoveAll(deploymentStatePath)
Expect(err).ToNot(HaveOccurred())
directorID = "fake-uuid-1"
})
It("creates one", func() {
expectDeployFlow()
// new directorID will be generated
mockAgentClientFactory.EXPECT().NewAgentClient(gomock.Any(), mbusURL).Return(mockAgentClient)
err := newDeployCmd().Run(fakeStage, []string{deploymentManifestPath})
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists(deploymentStatePath)).To(BeTrue())
示例9:
})
})
Context("when the CPI release manifest is invalid", func() {
BeforeEach(func() {
fakeFs.WriteFileString("/extracted/release/release.MF", "{")
})
It("returns an error when the YAML in unparseable", func() {
_, err := reader.Read()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Parsing release manifest"))
})
It("returns an error when the release manifest is missing", func() {
fakeFs.RemoveAll("/extracted/release/release.MF")
_, err := reader.Read()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Reading release manifest"))
})
})
Context("when the job refers to a package that does not exist", func() {
It("returns error", func() {
releaseMFContents :=
`---
name: fake-release
version: fake-version
commit_hash: abc123
uncommitted_changes: true