コード例 #1
0
		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())
コード例 #2
0
				[]bireljob.Job{
					{
						Name: "fake-cpi-release-job-name",
						Templates: map[string]string{
							"templates/cpi.erb": "bin/cpi",
						},
					},
				},
				[]*birelpkg.Package{},
				"fake-cpi-extracted-dir",
				fs,
				false,
			)

			expectCPIExtractRelease = 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()
		}

		var allowCPIToBeInstalled = func() {
			installationManifest := biinstallmanifest.Manifest{
				Name: "test-release",
				Template: biinstallmanifest.ReleaseJobRef{
					Name:    "fake-cpi-release-job-name",
					Release: "fake-cpi-release-name",
				},
				Mbus:       mbusURL,
				Properties: biproperty.Map{},
			}
コード例 #3
0
ファイル: diskutil_test.go プロジェクト: vestel/bosh-init
		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"})
コード例 #4
0
ファイル: extractor_test.go プロジェクト: vestel/bosh-init
			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)
コード例 #5
0
		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},
コード例 #6
0
				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())
			})
		})
	})
})
コード例 #7
0
		pathResolver = NewIDDevicePathResolver(500*time.Millisecond, udev, fs)
		diskSettings = boshsettings.DiskSettings{
			ID: "fake-disk-id-include-truncate",
		}
	})

	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())
			})

			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())
			})
		})
コード例 #8
0
	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.RemoveAllError = bosherr.Error("fake-delete-error")
			})

			It("returns an error", func() {
				err := renderedJobListArchive.Delete()
				Expect(err).To(HaveOccurred())
コード例 #9
0
ファイル: rendered_job_test.go プロジェクト: vestel/bosh-init
	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.RemoveAllError = bosherr.Error("fake-delete-error")
			})

			It("returns an error", func() {
				err := renderedJob.Delete()
				Expect(err).To(HaveOccurred())