github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/app_files/app_files_test.go (about) 1 package app_files_test 2 3 import ( 4 . "github.com/cloudfoundry/cli/cf/app_files" 5 "os" 6 "path/filepath" 7 8 "github.com/cloudfoundry/cli/cf/models" 9 cffileutils "github.com/cloudfoundry/cli/fileutils" 10 "github.com/cloudfoundry/gofileutils/fileutils" 11 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("AppFiles", func() { 17 var appFiles = ApplicationFiles{} 18 fixturePath := filepath.Join("..", "..", "fixtures", "applications") 19 20 Describe("AppFilesInDir", func() { 21 It("all files have '/' path separators", func() { 22 files, err := appFiles.AppFilesInDir(fixturePath) 23 Expect(err).ShouldNot(HaveOccurred()) 24 25 for _, afile := range files { 26 Expect(afile.Path).Should(Equal(filepath.ToSlash(afile.Path))) 27 } 28 }) 29 30 It("excludes files based on the .cfignore file", func() { 31 appPath := filepath.Join(fixturePath, "app-with-cfignore") 32 files, err := appFiles.AppFilesInDir(appPath) 33 Expect(err).ShouldNot(HaveOccurred()) 34 35 paths := []string{} 36 for _, file := range files { 37 paths = append(paths, file.Path) 38 } 39 40 Expect(paths).To(Equal([]string{ 41 "dir1", 42 "dir1/child-dir", 43 "dir1/child-dir/file3.txt", 44 "dir1/file1.txt", 45 "dir2", 46 47 // TODO: this should be excluded. 48 // .cfignore doesn't handle ** patterns right now 49 "dir2/child-dir2", 50 })) 51 }) 52 53 // NB: on windows, you can never rely on the size of a directory being zero 54 // see: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364946(v=vs.85).aspx 55 // and: https://www.pivotaltracker.com/story/show/70470232 56 It("always sets the size of directories to zero bytes", func() { 57 fileutils.TempDir("something", func(tempdir string, err error) { 58 Expect(err).ToNot(HaveOccurred()) 59 60 err = os.Mkdir(filepath.Join(tempdir, "nothing"), 0600) 61 Expect(err).ToNot(HaveOccurred()) 62 63 files, err := appFiles.AppFilesInDir(tempdir) 64 Expect(err).ToNot(HaveOccurred()) 65 66 sizes := []int64{} 67 for _, file := range files { 68 sizes = append(sizes, file.Size) 69 } 70 71 Expect(sizes).To(Equal([]int64{0})) 72 }) 73 }) 74 }) 75 76 Describe("CopyFiles", func() { 77 It("copies only the files specified", func() { 78 copyDir := filepath.Join(fixturePath, "app-copy-test") 79 80 filesToCopy := []models.AppFileFields{ 81 {Path: filepath.Join("dir1")}, 82 {Path: filepath.Join("dir1", "child-dir", "file2.txt")}, 83 } 84 85 files := []string{} 86 87 cffileutils.TempDir("copyToDir", func(tmpDir string, err error) { 88 copyErr := appFiles.CopyFiles(filesToCopy, copyDir, tmpDir) 89 Expect(copyErr).ToNot(HaveOccurred()) 90 91 filepath.Walk(tmpDir, func(path string, fileInfo os.FileInfo, err error) error { 92 Expect(err).ToNot(HaveOccurred()) 93 94 if !fileInfo.IsDir() { 95 files = append(files, fileInfo.Name()) 96 } 97 return nil 98 }) 99 }) 100 101 // file2.txt is in lowest subtree, thus is walked first. 102 Expect(files).To(Equal([]string{ 103 "file2.txt", 104 })) 105 }) 106 }) 107 })