當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeFileSystem.FileExists方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.FileExists方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.FileExists方法的具體用法?Golang FakeFileSystem.FileExists怎麽用?Golang FakeFileSystem.FileExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem的用法示例。


在下文中一共展示了FakeFileSystem.FileExists方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

		It("returns the repo record", func() {
			record, err := compiler.Compile(pkg)
			Expect(err).ToNot(HaveOccurred())

			Expect(record).To(Equal(bistatepkg.CompiledPackageRecord{
				BlobID:   "fake-blob-id",
				BlobSHA1: "fake-fingerprint",
			}))
		})

		It("cleans up the packages dir", func() {
			_, err := compiler.Compile(pkg)
			Expect(err).ToNot(HaveOccurred())

			Expect(fs.FileExists(packagesDir)).To(BeFalse())
		})

		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() {
開發者ID:vestel,項目名稱:bosh-init,代碼行數:30,代碼來源:compiler_test.go

示例2: init


//.........這裏部分代碼省略.........
						fs.WriteFile("/setting/path.json", []byte(`$%^&*(`))

						err := service.LoadSettings()
						Expect(err).To(HaveOccurred())
						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() {
				fakeSettingsSource.SettingsValue = Settings{}
				fakeSettingsSource.SettingsErr = nil
				service, fs := buildService()

				fs.WriteFile("/setting/path.json", []byte(`{}`))

				err := service.InvalidateSettings()
				Expect(err).ToNot(HaveOccurred())

				Expect(fs.FileExists("/setting/path.json")).To(BeFalse())
			})

			It("returns err if removing settings file errored", func() {
				fakeSettingsSource.SettingsValue = Settings{}
				fakeSettingsSource.SettingsErr = nil
				service, fs := buildService()

				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() {
				fakeSettingsSource.SettingsValue = loadedSettings
				fakeSettingsSource.SettingsErr = nil
				service, _ = buildService()
				err := service.LoadSettings()
				Expect(err).NotTo(HaveOccurred())
			})
開發者ID:vestel,項目名稱:bosh-init,代碼行數:67,代碼來源:service_test.go

示例3:

		Context("when the job does not exist", func() {
			It("returns nil and false", func() {
				_, ok := release.FindJobByName("fake-non-existent-job")
				Expect(ok).To(BeFalse())
			})
		})
	})

	Describe("Delete", func() {
		BeforeEach(func() {
			fakeFS.WriteFileString("fake-extracted-path", "")
		})

		It("deletes the extracted release path", func() {
			Expect(fakeFS.FileExists("fake-extracted-path")).To(BeTrue())
			err := release.Delete()
			Expect(err).ToNot(HaveOccurred())
			Expect(fakeFS.FileExists("fake-extracted-path")).To(BeFalse())
		})
	})

	Describe("Exists", func() {
		BeforeEach(func() {
			fakeFS.WriteFileString("fake-extracted-path", "")
		})

		It("returns false after deletion", func() {
			Expect(release.Exists()).To(BeTrue())
			err := release.Delete()
			Expect(err).ToNot(HaveOccurred())
開發者ID:hanzhefeng,項目名稱:bosh-init,代碼行數:30,代碼來源:release_test.go

示例4:

		fs.WriteFileString("source-path", "")

		err := cache.Save("source-path", &fakeSource{
			sha1:        "fake-sha1",
			url:         "http://foo.bar.com",
			description: "some tarball",
		})
		Expect(err).ToNot(HaveOccurred())

		path, found := cache.Get(&fakeSource{
			sha1:        "fake-sha1",
			url:         "http://foo.bar.com",
			description: "some tarball",
		})
		Expect(found).To(BeTrue())
		Expect(fs.FileExists(path)).To(BeTrue())
	})

	It("is a cache miss when a tarball from a different url has been downloaded, even if SHA1 matches", func() {
		fs.WriteFileString("source-path", "")

		err := cache.Save("source-path", &fakeSource{
			sha1:        "fake-sha1",
			url:         "http://foo.bar.com",
			description: "some tarball",
		})
		Expect(err).ToNot(HaveOccurred())

		_, found := cache.Get(&fakeSource{
			sha1:        "fake-sha1",
			url:         "http://baz.bar.com",
開發者ID:vestel,項目名稱:bosh-init,代碼行數:31,代碼來源:cache_test.go

示例5:

		blobSHA1 = "fake-sha1"
		fileName = "tarball.tgz"
		blobstore.GetFileName = fileName
		fakeError = errors.New("Initial error")

		extractor = NewExtractor(fs, compressor, blobstore, logger)
	})

	Describe("Cleanup", func() {
		BeforeEach(func() {
			err := extractor.Extract(blobID, blobSHA1, targetDir)
			Expect(err).ToNot(HaveOccurred())
		})

		It("deletes the extracted temp file", func() {
			Expect(fs.FileExists(targetDir)).To(BeTrue())
			err := extractor.Cleanup(blobID, targetDir)
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(targetDir)).To(BeFalse())
		})

		It("deletes the stored blob", func() {
			err := extractor.Cleanup(blobID, targetDir)
			Expect(err).ToNot(HaveOccurred())
			Expect(blobstore.DeleteBlobID).To(Equal(blobID))
		})
	})

	Describe("Extract", func() {
		Context("when the specified blobID exists in the blobstore", func() {
			It("creates the installed package dir if it does not exist", func() {
開發者ID:vestel,項目名稱:bosh-init,代碼行數:31,代碼來源:extractor_test.go

示例6:

			Expect(deploymentState.DirectorID).To(Equal("fake-director-id"))
			Expect(deploymentState.Stemcells).To(Equal(stemcells))
			Expect(deploymentState.CurrentVMCID).To(Equal("fake-vm-cid"))
			Expect(deploymentState.CurrentDiskID).To(Equal("fake-disk-id"))
			Expect(deploymentState.Disks).To(Equal(disks))
		})

		Context("when the config does not exist", func() {
			It("returns a new DeploymentState with generated defaults", func() {
				deploymentState, err := service.Load()
				Expect(err).NotTo(HaveOccurred())
				Expect(deploymentState).To(Equal(DeploymentState{
					DirectorID: "fake-uuid-0",
				}))

				Expect(fakeFs.FileExists(deploymentStatePath)).To(BeTrue())
			})
		})

		Context("when reading config file fails", func() {
			BeforeEach(func() {
				fakeFs.WriteFileString(deploymentStatePath, "{}")
				fakeFs.ReadFileError = errors.New("fake-read-error")
			})

			It("returns an error", func() {
				_, err := service.Load()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-read-error"))
			})
		})
開發者ID:vestel,項目名稱:bosh-init,代碼行數:31,代碼來源:file_system_deployment_state_service_test.go

示例7:

	})

	Describe("Path", func() {
		It("returns the rendered job path", func() {
			Expect(renderedJob.Path()).To(Equal(renderedJobPath))
		})
	})

	Describe("Delete", func() {
		It("deletes the rendered job path from the file system", func() {
			err := fs.MkdirAll(renderedJobPath, os.ModePerm)
			Expect(err).ToNot(HaveOccurred())

			err = renderedJob.Delete()
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(renderedJobPath)).To(BeFalse())
		})

		Context("when deleting from the file system fails", func() {
			JustBeforeEach(func() {
				fs.RemoveAllError = bosherr.Error("fake-delete-error")
			})

			It("returns an error", func() {
				err := renderedJob.Delete()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-delete-error"))
			})
		})
	})
開發者ID:vestel,項目名稱:bosh-init,代碼行數:30,代碼來源:rendered_job_test.go

示例8:

				Expect(archive.Fingerprint()).To(Equal("fake-sha1"))
			})

			It("calculates the SHA1 of the archive", func() {
				fakeCompressor.CompressFilesInDirTarballPath = "fake-archive-path"

				fakeSHA1Calculator.SetCalculateBehavior(map[string]fakebicrypto.CalculateInput{
					"fake-archive-path": fakebicrypto.CalculateInput{Sha1: "fake-sha1"},
				})

				archive, err := renderedJobListCompressor.Compress(renderedJobList)
				Expect(err).ToNot(HaveOccurred())

				Expect(archive.SHA1()).To(Equal("fake-sha1"))
			})

			It("deletes the temp dir compressed into the archive", func() {
				fakeFS.TempDirDir = "fake-rendered-job-list-path"
				err := fakeFS.MkdirAll("fake-rendered-job-list-path", os.ModePerm)
				Expect(err).ToNot(HaveOccurred())

				_, err = renderedJobListCompressor.Compress(renderedJobList)
				Expect(err).ToNot(HaveOccurred())

				Expect(fakeFS.FileExists("fake-rendered-job-list-path")).To(BeFalse())
			})
		})
	})
})
開發者ID:vestel,項目名稱:bosh-init,代碼行數:29,代碼來源:rendered_job_list_compressor_test.go

示例9:

			Expect(count).To(Equal(0))
		})
	})

	Describe("cert.Manager implementations", func() {
		var (
			fakeFs      *fakesys.FakeFileSystem
			fakeCmd     *fakesys.FakeCmdRunner
			certManager cert.Manager
		)

		SharedLinuxCertManagerExamples := func(certBasePath, certUpdateProgram string) {
			It("writes 1 cert to a file", func() {
				err := certManager.UpdateCertificates(cert1)
				Expect(err).NotTo(HaveOccurred())
				Expect(fakeFs.FileExists(fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath))).To(BeTrue())
			})

			It("writes each cert to its own file", func() {
				certs := fmt.Sprintf("%s\n%s\n", cert1, cert1)

				err := certManager.UpdateCertificates(certs)
				Expect(err).NotTo(HaveOccurred())
				Expect(fakeFs.FileExists(fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath))).To(BeTrue())
				Expect(fakeFs.FileExists(fmt.Sprintf("%s/bosh-trusted-cert-2.crt", certBasePath))).To(BeTrue())
				Expect(countFiles(fakeFs, certBasePath)).To(Equal(2))
			})

			It("deletes all certs when passed an empty string", func() {
				fakeFs.WriteFileString(fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath), "goodbye")
				fakeFs.SetGlob(fmt.Sprintf("%s/bosh-trusted-cert-*", certBasePath), []string{
開發者ID:vestel,項目名稱:bosh-init,代碼行數:31,代碼來源:cert_manager_test.go

示例10:

		It("errs when copy file errs", func() {
			tempFile, err := fs.TempFile("bosh-blobstore-local-TestLocalGetErrsWhenCopyFileErrs")
			Expect(err).ToNot(HaveOccurred())

			fs.ReturnTempFile = tempFile
			defer fs.RemoveAll(tempFile.Name())

			fs.CopyFileError = errors.New("fake-copy-file-error")

			fileName, err := blobstore.Get("fake-blob-id", "")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-copy-file-error"))

			Expect(fileName).To(BeEmpty())
			Expect(fs.FileExists(tempFile.Name())).To(BeFalse())
		})
	})

	Describe("CleanUp", func() {
		It("removes the path given by Get", func() {
			file, err := fs.TempFile("bosh-blobstore-local-TestLocalCleanUp")
			Expect(err).ToNot(HaveOccurred())
			fileName := file.Name()

			defer fs.RemoveAll(fileName)

			err = blobstore.CleanUp(fileName)
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(fileName)).To(BeFalse())
		})
開發者ID:vestel,項目名稱:bosh-init,代碼行數:30,代碼來源:local_blobstore_test.go

示例11:

		fs     *fakesys.FakeFileSystem
		cdrom  *fakecdrom.FakeCdrom
		cdutil boshdevutil.DeviceUtil
		logger boshlog.Logger
	)

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		cdrom = fakecdrom.NewFakeCdrom(fs, "env", "fake env contents")
		logger = boshlog.NewLogger(boshlog.LevelNone)
	})

	JustBeforeEach(func() {
		cdutil = boshcdrom.NewCdUtil("/fake/settings/dir", fs, cdrom, logger)
	})

	It("gets file contents from CDROM", func() {
		contents, err := cdutil.GetFilesContents([]string{"env"})
		Expect(err).NotTo(HaveOccurred())

		Expect(cdrom.Mounted).To(Equal(false))
		Expect(cdrom.MediaAvailable).To(Equal(false))
		Expect(fs.FileExists("/fake/settings/dir")).To(Equal(true))
		Expect(cdrom.MountMountPath).To(Equal("/fake/settings/dir"))

		Expect(len(contents)).To(Equal(1))
		Expect(contents[0]).To(Equal([]byte("fake env contents")))
	})

})
開發者ID:vestel,項目名稱:bosh-init,代碼行數:30,代碼來源:cdutil_test.go

示例12:

							_, err := provider.Get(source, fakeStage)
							Expect(err).To(HaveOccurred())
							Expect(err.Error()).To(ContainSubstring("'fake-sha2' does not match expected SHA1 'fake-sha1'"))
						})

						It("retries downloading up to 3 times", func() {
							_, err := provider.Get(source, fakeStage)
							Expect(err).To(HaveOccurred())

							Expect(httpClient.GetInputs).To(HaveLen(3))
						})

						It("removes the downloaded file", func() {
							_, err := provider.Get(source, fakeStage)
							Expect(err).To(HaveOccurred())
							Expect(fs.FileExists(tempDownloadFilePath)).To(BeFalse())
						})
					})

					Context("when saving to cache fails", func() {
						BeforeEach(func() {
							// Creating cache base directory fails
							fs.MkdirAllError = errors.New("fake-mkdir-error")
						})

						It("returns an error", func() {
							_, err := provider.Get(source, fakeStage)
							Expect(err).To(HaveOccurred())
							Expect(err.Error()).To(ContainSubstring("fake-mkdir-error"))
						})
開發者ID:vestel,項目名稱:bosh-init,代碼行數:30,代碼來源:provider_test.go

示例13:

		fakeUUIDGenerator = fakeuuid.NewFakeGenerator()
		legacyDeploymentStateFilePath = "/path/to/legacy/bosh-deployment.yml"
		modernDeploymentStateFilePath = "/path/to/legacy/deployment.json"
		logger := boshlog.NewLogger(boshlog.LevelNone)
		deploymentStateService = NewFileSystemDeploymentStateService(fakeFs, fakeUUIDGenerator, logger, modernDeploymentStateFilePath)
		migrator = NewLegacyDeploymentStateMigrator(deploymentStateService, fakeFs, fakeUUIDGenerator, logger)
	})

	Describe("MigrateIfExists", func() {
		Context("when no legacy deploment config file exists", func() {
			It("does nothing", func() {
				migrated, err := migrator.MigrateIfExists(legacyDeploymentStateFilePath)
				Expect(migrated).To(BeFalse())
				Expect(err).ToNot(HaveOccurred())

				Expect(fakeFs.FileExists(modernDeploymentStateFilePath)).To(BeFalse())
			})
		})

		Context("when legacy deploment config file exists (but is unparseable)", func() {
			BeforeEach(func() {
				fakeFs.WriteFileString(legacyDeploymentStateFilePath, `xyz`)
			})

			It("does not delete the legacy deployment state file", func() {
				migrated, err := migrator.MigrateIfExists(legacyDeploymentStateFilePath)
				Expect(migrated).To(BeFalse())
				Expect(err).To(HaveOccurred())

				Expect(fakeFs.FileExists(modernDeploymentStateFilePath)).To(BeFalse())
				Expect(fakeFs.FileExists(legacyDeploymentStateFilePath)).To(BeTrue())
開發者ID:vestel,項目名稱:bosh-init,代碼行數:31,代碼來源:legacy_deployment_state_migrator_test.go

示例14:

	})

	Describe("SHA1", func() {
		It("returns the rendered job list archive sha1", func() {
			Expect(renderedJobListArchive.SHA1()).To(Equal(renderedJobListArchiveSHA1))
		})
	})

	Describe("Delete", func() {
		It("deletes the rendered job list archive from the file system", func() {
			err := fs.MkdirAll(renderedJobListArchivePath, os.ModePerm)
			Expect(err).ToNot(HaveOccurred())

			err = renderedJobListArchive.Delete()
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(renderedJobListArchivePath)).To(BeFalse())
		})

		Context("when deleting from the file system fails", func() {
			JustBeforeEach(func() {
				fs.RemoveAllError = bosherr.Error("fake-delete-error")
			})

			It("returns an error", func() {
				err := renderedJobListArchive.Delete()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-delete-error"))
			})
		})
	})
開發者ID:vestel,項目名稱:bosh-init,代碼行數:30,代碼來源:rendered_job_list_archive_test.go

示例15:

			It("extracts and parses the stemcell manifest", func() {
				stemcell, err := extractor.Extract(stemcellTarballPath)
				Expect(err).ToNot(HaveOccurred())
				Expect(stemcell).To(Equal(expectedExtractedStemcell))

				Expect(reader.ReadInputs).To(Equal([]fakebistemcell.ReadInput{
					{
						StemcellTarballPath: stemcellTarballPath,
						DestPath:            stemcellExtractionDir,
					},
				}))
			})

			It("does not delete the destination file path", func() {
				extractor.Extract(stemcellTarballPath)
				Expect(fs.FileExists(stemcellExtractionDir)).To(BeTrue())
			})
		})

		Context("when the read fails", func() {
			BeforeEach(func() {
				reader.SetReadBehavior(stemcellTarballPath, stemcellExtractionDir, expectedExtractedStemcell, errors.New("fake-read-error"))
			})

			It("returns an error", func() {
				_, err := extractor.Extract(stemcellTarballPath)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-read-error"))
			})

			It("deletes the destination file path", func() {
開發者ID:vestel,項目名稱:bosh-init,代碼行數:31,代碼來源:extractor_test.go


注:本文中的github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.FileExists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。