当前位置: 首页>>代码示例>>Golang>>正文


Golang FakeFileSystem.MkdirAll方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.MkdirAll方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeFileSystem.MkdirAll方法的具体用法?Golang FakeFileSystem.MkdirAll怎么用?Golang FakeFileSystem.MkdirAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem的用法示例。


在下文中一共展示了FakeFileSystem.MkdirAll方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: init

func init() {
	Describe("concreteCompiler", func() {
		var (
			compiler       Compiler
			compressor     *fakecmd.FakeCompressor
			blobstore      *fakeblobstore.FakeBlobstore
			fs             *fakesys.FakeFileSystem
			runner         *fakecmdrunner.FakeFileLoggingCmdRunner
			packageApplier *fakepackages.FakeApplier
			packagesBc     *fakebc.FakeBundleCollection
		)

		BeforeEach(func() {
			compressor = fakecmd.NewFakeCompressor()
			blobstore = &fakeblobstore.FakeBlobstore{}
			fs = fakesys.NewFakeFileSystem()
			runner = fakecmdrunner.NewFakeFileLoggingCmdRunner()
			packageApplier = fakepackages.NewFakeApplier()
			packagesBc = fakebc.NewFakeBundleCollection()

			compiler = NewConcreteCompiler(
				compressor,
				blobstore,
				fs,
				runner,
				FakeCompileDirProvider{Dir: "/fake-compile-dir"},
				packageApplier,
				packagesBc,
			)
		})

		BeforeEach(func() {
			fs.MkdirAll("/fake-compile-dir", os.ModePerm)
		})

		Describe("Compile", func() {
			var (
				bundle  *fakebc.FakeBundle
				pkg     Package
				pkgDeps []boshmodels.Package
			)

			BeforeEach(func() {
				bundle = packagesBc.FakeGet(boshmodels.Package{
					Name:    "pkg_name",
					Version: "pkg_version",
				})

				bundle.InstallPath = "/fake-dir/data/packages/pkg_name/pkg_version"
				bundle.EnablePath = "/fake-dir/packages/pkg_name"

				compressor.CompressFilesInDirTarballPath = "/tmp/compressed-compiled-package"

				pkg, pkgDeps = getCompileArgs()
			})

			It("returns blob id and sha1 of created compiled package", func() {
				blobstore.CreateBlobID = "fake-blob-id"
				blobstore.CreateFingerprint = "fake-blob-sha1"

				blobID, sha1, err := compiler.Compile(pkg, pkgDeps)
				Expect(err).ToNot(HaveOccurred())

				Expect(blobID).To(Equal("fake-blob-id"))
				Expect(sha1).To(Equal("fake-blob-sha1"))
			})

			It("cleans up all packages before and after applying dependent packages", func() {
				_, _, err := compiler.Compile(pkg, pkgDeps)
				Expect(err).ToNot(HaveOccurred())
				Expect(packageApplier.ActionsCalled).To(Equal([]string{"KeepOnly", "Apply", "Apply", "KeepOnly"}))
				Expect(packageApplier.KeptOnlyPackages).To(BeEmpty())
			})

			It("returns an error if cleaning up packages fails", func() {
				packageApplier.KeepOnlyErr = errors.New("fake-keep-only-error")

				_, _, err := compiler.Compile(pkg, pkgDeps)
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-keep-only-error"))
			})

			It("fetches source package from blobstore without checking SHA1 by default because of Director bug", func() {
				_, _, err := compiler.Compile(pkg, pkgDeps)
				Expect(err).ToNot(HaveOccurred())

				Expect(blobstore.GetBlobIDs[0]).To(Equal("blobstore_id"))
				Expect(blobstore.GetFingerprints[0]).To(Equal(""))
			})

			PIt("(Pending Tracker Story: <https://www.pivotaltracker.com/story/show/94524232>) fetches source package from blobstore and checks SHA1 by default in future", func() {
				_, _, err := compiler.Compile(pkg, pkgDeps)
				Expect(err).ToNot(HaveOccurred())

				Expect(blobstore.GetBlobIDs[0]).To(Equal("blobstore_id"))
				Expect(blobstore.GetFingerprints[0]).To(Equal("sha1"))
			})

			It("returns an error if removing compile target directory during uncompression fails", func() {
				fs.RemoveAllStub = func(path string) error {
//.........这里部分代码省略.........
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:101,代码来源:concrete_compiler_test.go

示例2:

	})

	Describe("Start", func() {
		It("start starts each monit service in group vcap", func() {
			client.ServicesInGroupServices = []string{"fake-service"}

			err := monit.Start()
			Expect(err).ToNot(HaveOccurred())

			Expect(client.ServicesInGroupName).To(Equal("vcap"))
			Expect(len(client.StartServiceNames)).To(Equal(1))
			Expect(client.StartServiceNames[0]).To(Equal("fake-service"))
		})

		It("deletes stopped file", func() {
			fs.MkdirAll("/var/vcap/monit/stopped", os.FileMode(0755))
			fs.WriteFileString("/var/vcap/monit/stopped", "")

			err := monit.Start()
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists("/var/vcap/monit/stopped")).ToNot(BeTrue())
		})

		It("does not fail if stopped file is not present", func() {
			err := monit.Start()
			Expect(err).ToNot(HaveOccurred())
		})
	})

	Describe("Stop", func() {
		It("stop stops each monit service in group vcap", func() {
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:31,代码来源:monit_job_supervisor_test.go

示例3:

			It("decompresses the blob into the target dir", func() {
				err := extractor.Extract(blobID, blobSHA1, targetDir)
				Expect(err).ToNot(HaveOccurred())
				Expect(compressor.DecompressFileToDirTarballPaths).To(ContainElement(fileName))
				Expect(compressor.DecompressFileToDirDirs).To(ContainElement(targetDir))
			})

			It("cleans up the extracted blob file", func() {
				err := extractor.Extract(blobID, blobSHA1, targetDir)
				Expect(err).ToNot(HaveOccurred())
				Expect(blobstore.CleanUpFileName).To(Equal(fileName))
			})

			Context("when the installed package dir already exists", func() {
				BeforeEach(func() {
					fs.MkdirAll(targetDir, os.ModePerm)
				})

				It("decompresses the blob into the target dir", func() {
					Expect(fs.FileExists(targetDir)).To(BeTrue())
					Expect(compressor.DecompressFileToDirTarballPaths).ToNot(ContainElement(fileName))

					err := extractor.Extract(blobID, blobSHA1, targetDir)
					Expect(err).ToNot(HaveOccurred())
					Expect(fs.FileExists(targetDir)).To(BeTrue())
					Expect(compressor.DecompressFileToDirTarballPaths).To(ContainElement(fileName))
				})

				It("does not re-create the target package dir", func() {
					fs.MkdirAllError = fakeError
					err := extractor.Extract(blobID, blobSHA1, targetDir)
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:extractor_test.go

示例4:

				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:mattcui,项目名称:bosh-init,代码行数:29,代码来源:rendered_job_list_compressor_test.go

示例5:

	})

	JustBeforeEach(func() {
		pathResolver = NewIDDevicePathResolver(500*time.Millisecond, udev, fs)
	})

	Describe("GetRealDevicePath", func() {
		It("refreshes udev", func() {
			pathResolver.GetRealDevicePath(diskSettings)
			Expect(udev.Triggered).To(Equal(true))
			Expect(udev.Settled).To(Equal(true))
		})

		Context("when path exists", func() {
			BeforeEach(func() {
				err := fs.MkdirAll("fake-device-path", os.FileMode(0750))
				Expect(err).ToNot(HaveOccurred())

				err = fs.Symlink("fake-device-path", "/dev/disk/by-id/virtio-fake-disk-id-include")
				Expect(err).ToNot(HaveOccurred())

				fs.SetGlob("/dev/disk/by-id/*fake-disk-id-include", []string{"fake-device-path"})
			})

			It("returns the path", func() {
				path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
				Expect(err).ToNot(HaveOccurred())

				Expect(path).To(Equal("fake-device-path"))
				Expect(timeout).To(BeFalse())
			})
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:31,代码来源:id_device_path_resolver_test.go

示例6:

	Describe("Fingerprint", func() {
		It("returns the rendered job list fingerprint", func() {
			Expect(renderedJobListArchive.Fingerprint()).To(Equal(renderedJobListFingerprint))
		})
	})

	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.RemoveAllStub = func(_ string) error {
					return bosherr.Error("fake-delete-error")
				}
			})

			It("returns an error", func() {
开发者ID:mattcui,项目名称:bosh-init,代码行数:30,代码来源:rendered_job_list_archive_test.go

示例7:

		installPath string
		enablePath  string
		fileBundle  FileBundle
	)

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		installPath = "/install-path"
		enablePath = "/enable-path"
		logger = boshlog.NewLogger(boshlog.LevelNone)
		fileBundle = NewFileBundle(installPath, enablePath, fs, logger)
	})

	createSourcePath := func() string {
		path := "/source-path"
		err := fs.MkdirAll(path, os.ModePerm)
		Expect(err).ToNot(HaveOccurred())
		return path
	}

	BeforeEach(func() {
		sourcePath = createSourcePath()
	})

	Describe("Install", func() {
		It("installs the bundle from source at the given path", func() {
			actualFs, path, err := fileBundle.Install(sourcePath)
			Expect(err).NotTo(HaveOccurred())
			Expect(actualFs).To(Equal(fs))
			Expect(path).To(Equal(installPath))
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:30,代码来源:file_bundle_test.go

示例8:

	BeforeEach(func() {
		fs = fakesys.NewFakeFileSystem()
		cmdRunner = fakesys.NewFakeCmdRunner()
		runner = NewFileLoggingCmdRunner(fs, cmdRunner, "/fake-base-dir", 15)

		cmd = boshsys.Command{
			Name:       "fake-cmd",
			Args:       []string{"fake-args"},
			Env:        map[string]string{"fake-env-key": "fake-env-var"},
			WorkingDir: "/fake-working-dir",
		}
	})

	Describe("RunCommand", func() {
		It("cleans logs directory", func() {
			err := fs.MkdirAll("/fake-base-dir/fake-log-dir-name/", os.FileMode(0750))
			Expect(err).ToNot(HaveOccurred())

			err = fs.WriteFile("/fake-base-dir/fake-log-dir-name/old-file", []byte("test-data"))
			Expect(err).ToNot(HaveOccurred())

			_, err = runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
			Expect(err).ToNot(HaveOccurred())

			Expect(fs.FileExists("/fake-base-dir/fake-log-dir-name/old-file")).To(BeFalse())
		})

		It("returns an error if it fails to remove previous logs directory", func() {
			fs.RemoveAllError = errors.New("fake-remove-all-error")

			_, err := runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:31,代码来源:file_logging_cmd_runner_test.go

示例9:

		Context("when path is directory", func() {
			BeforeEach(func() {
				fs.RegisterOpenFile("/fake-templates-dir", &fakesys.FakeFile{
					Stats: &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeDir},
				})

				fs.RegisterOpenFile("/fake-templates-dir/file-1", &fakesys.FakeFile{
					Contents: []byte("fake-file-1-contents"),
				})

				fs.WriteFileString("/fake-templates-dir/file-1", "fake-file-1-contents")

				fs.RegisterOpenFile("/fake-templates-dir/config/file-2", &fakesys.FakeFile{
					Contents: []byte("fake-file-2-contents"),
				})
				fs.MkdirAll("/fake-templates-dir/config", os.ModePerm)
				fs.WriteFileString("/fake-templates-dir/config/file-2", "fake-file-2-contents")
			})

			It("returns sha1 of the all files in the directory", func() {
				sha1, err := sha1Calculator.Calculate("/fake-templates-dir")
				Expect(err).ToNot(HaveOccurred())
				Expect(sha1).To(Equal("bc0646cd41b98cd6c878db7a0573eca345f78200"))
			})
		})

		Context("when path is a file", func() {
			BeforeEach(func() {
				fs.RegisterOpenFile("/fake-archived-templates-path", &fakesys.FakeFile{
					Contents: []byte("fake-archive-contents"),
					Stats:    &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeFile},
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:sha1_calculator_test.go

示例10:

		It("returns the added rendered jobs", func() {
			renderedJob0 := NewRenderedJob(bireljob.Job{Name: "fake-job-0"}, "fake-path-0", fs, logger)
			renderedJob1 := NewRenderedJob(bireljob.Job{Name: "fake-job-1"}, "fake-path-1", fs, logger)
			renderedJobList.Add(renderedJob0)
			renderedJobList.Add(renderedJob1)

			Expect(renderedJobList.All()).To(Equal([]RenderedJob{
				renderedJob0,
				renderedJob1,
			}))
		})
	})

	Describe("Delete", func() {
		It("deletes the rendered jobs", func() {
			err := fs.MkdirAll("fake-path-0", os.ModePerm)
			Expect(err).ToNot(HaveOccurred())

			err = fs.MkdirAll("fake-path-1", os.ModePerm)
			Expect(err).ToNot(HaveOccurred())

			renderedJob0 := NewRenderedJob(bireljob.Job{Name: "fake-job-0"}, "fake-path-0", fs, logger)
			renderedJob1 := NewRenderedJob(bireljob.Job{Name: "fake-job-1"}, "fake-path-1", fs, logger)
			renderedJobList.Add(renderedJob0)
			renderedJobList.Add(renderedJob1)

			err = renderedJobList.Delete()
			Expect(err).ToNot(HaveOccurred())

			Expect(fs.FileExists("fake-path-0")).To(BeFalse())
			Expect(fs.FileExists("fake-path-1")).To(BeFalse())
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:rendered_job_list_test.go

示例11:

				[]bireljob.Job{
					{
						Name: "fake-cpi-release-job-name",
						Templates: map[string]string{
							"cpi.erb": "bin/cpi",
						},
						Packages: []*birelpkg.Package{&cpiPackage},
					},
				},
				[]*birelpkg.Package{&cpiPackage},
				"fake-cpi-extracted-dir",
				fs,
				false,
			)
			mockReleaseExtractor.EXPECT().Extract("/fake-cpi-release.tgz").Do(func(_ string) {
				err := fs.MkdirAll("fake-cpi-extracted-dir", os.ModePerm)
				Expect(err).ToNot(HaveOccurred())
			}).Return(cpiRelease, nil).AnyTimes()

			installationManifest := biinstallmanifest.Manifest{
				Name: "test-deployment",
				Template: biinstallmanifest.ReleaseJobRef{
					Name:    "fake-cpi-release-job-name",
					Release: "fake-cpi-release-name",
				},
				Registry: biinstallmanifest.Registry{
					Username: "registry",
					Password: "registry-password",
					Host:     "127.0.0.1",
					Port:     6901,
					SSHTunnel: biinstallmanifest.SSHTunnel{
开发者ID:mattcui,项目名称:bosh-init,代码行数:31,代码来源:deploy_test.go

示例12:

		logger := boshlog.NewLogger(boshlog.LevelNone)
		diskUtil = NewDiskUtil("fake-disk-path", mounter, fs, logger)
	})

	Describe("GetFileContents", func() {
		Context("when disk path does not exist", func() {
			It("returns an error if diskpath does not exist", func() {
				_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("disk path 'fake-disk-path' does not exist"))
			})
		})

		Context("when disk path does not exist", func() {
			BeforeEach(func() {
				fs.MkdirAll("fake-disk-path", 0700)
				fs.TempDirDir = "fake-tempdir"
				fs.WriteFileString("fake-tempdir/fake-file-path-1", "fake-contents-1")
				fs.WriteFileString("fake-tempdir/fake-file-path-2", "fake-contents-2")
			})

			It("mounts disk path to temporary directory", func() {
				_, err := diskUtil.GetFilesContents([]string{"fake-file-path-1"})
				Expect(err).ToNot(HaveOccurred())

				Expect(mounter.MountPartitionPaths).To(ContainElement("fake-disk-path"))
				Expect(mounter.MountMountPoints).To(ContainElement("fake-tempdir"))
			})

			It("returns contents of files on a disk", func() {
				contents, err := diskUtil.GetFilesContents([]string{"fake-file-path-1", "fake-file-path-2"})
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:31,代码来源:diskutil_test.go

示例13:

	Describe("Job", func() {
		It("returns the release job", func() {
			Expect(renderedJob.Job()).To(Equal(releaseJob))
		})
	})

	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.RemoveAllStub = func(_ string) error {
					return bosherr.Error("fake-delete-error")
				}
			})

			It("returns an error", func() {
开发者ID:mattcui,项目名称:bosh-init,代码行数:30,代码来源:rendered_job_test.go

示例14:

		})
		fs.SetGlob("/sys/bus/vmbus/devices/*/device_id", []string{
			"/sys/bus/vmbus/devices/fake-vmbus-device/device_id",
			"/sys/bus/vmbus/devices/vmbus_0_12/device_id",
			"/sys/bus/vmbus/devices/vmbus_12/device_id",
		})
	})

	Describe("GetRealDevicePath", func() {
		Context("when path exists", func() {
			BeforeEach(func() {
				deviceIDPath := "/sys/bus/vmbus/devices/fake-vmbus-device/device_id"
				err := fs.WriteFileString(deviceIDPath, "fake-host-device-id")
				Expect(err).ToNot(HaveOccurred())

				err = fs.MkdirAll("fake-root/fake-vmbus-device/fake-base", os.FileMode(0750))
				Expect(err).ToNot(HaveOccurred())

				err = fs.Symlink("fake-root/fake-vmbus-device/fake-base", "/sys/class/block/sdc")
				Expect(err).ToNot(HaveOccurred())

				err = fs.MkdirAll("/dev/sdc", os.FileMode(0750))
				Expect(err).ToNot(HaveOccurred())
			})

			It("returns the real path", func() {
				path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
				Expect(err).ToNot(HaveOccurred())

				Expect(path).To(Equal("/dev/sdc"))
				Expect(timeout).To(BeFalse())
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:31,代码来源:scsi_lun_device_path_resolver_test.go


注:本文中的github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.MkdirAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。