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"))) }) })
diskUtil boshdevutil.DeviceUtil mounter *fakedisk.FakeMounter fs *fakesys.FakeFileSystem ) BeforeEach(func() { mounter = &fakedisk.FakeMounter{} fs = fakesys.NewFakeFileSystem() 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"})