github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/buildpack_unix_test.go (about) 1 // +build !windows 2 3 package v7action_test 4 5 import ( 6 "fmt" 7 "io/ioutil" 8 "os" 9 "path/filepath" 10 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 14 . "code.cloudfoundry.org/cli/actor/v7action" 15 "code.cloudfoundry.org/cli/integration/helpers" 16 "code.cloudfoundry.org/ykk" 17 ) 18 19 var _ = Describe("Buildpack", func() { 20 Describe("Zipit", func() { 21 var ( 22 source string 23 target string 24 25 executeErr error 26 ) 27 28 JustBeforeEach(func() { 29 executeErr = Zipit(source, target, "testzip-") 30 }) 31 32 When("the source directory exists", func() { 33 var subDir string 34 35 BeforeEach(func() { 36 var err error 37 38 source, err = ioutil.TempDir("", "zipit-source-") 39 Expect(err).ToNot(HaveOccurred()) 40 41 Expect(ioutil.WriteFile(filepath.Join(source, "file1"), []byte{}, 0700)).To(Succeed()) 42 Expect(ioutil.WriteFile(filepath.Join(source, "file2"), []byte{}, 0644)).To(Succeed()) 43 subDir, err = ioutil.TempDir(source, "zipit-subdir-") 44 Expect(err).ToNot(HaveOccurred()) 45 Expect(ioutil.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0755)).To(Succeed()) 46 47 p := filepath.FromSlash(fmt.Sprintf("buildpack-%s.zip", helpers.RandomName())) 48 target, err = filepath.Abs(p) 49 Expect(err).ToNot(HaveOccurred()) 50 }) 51 52 AfterEach(func() { 53 Expect(os.RemoveAll(source)).ToNot(HaveOccurred()) 54 Expect(os.RemoveAll(target)).ToNot(HaveOccurred()) 55 }) 56 57 It("preserves the file permissions in the zip", func() { 58 Expect(executeErr).ToNot(HaveOccurred()) 59 zipFile, err := os.Open(target) 60 Expect(err).ToNot(HaveOccurred()) 61 defer zipFile.Close() 62 63 zipStat, err := zipFile.Stat() 64 Expect(err).ToNot(HaveOccurred()) 65 reader, err := ykk.NewReader(zipFile, zipStat.Size()) 66 Expect(err).ToNot(HaveOccurred()) 67 68 Expect(reader.File).To(HaveLen(4)) 69 Expect(reader.File[0].Name).To(Equal("file1")) 70 Expect(reader.File[0].Mode()).To(Equal(os.FileMode(0700))) 71 72 Expect(reader.File[1].Name).To(Equal("file2")) 73 Expect(reader.File[1].Mode()).To(Equal(os.FileMode(0644))) 74 75 dirName := fmt.Sprintf("%s/", filepath.Base(subDir)) 76 Expect(reader.File[2].Name).To(Equal(dirName)) 77 Expect(reader.File[2].Mode()).To(Equal(os.ModeDir | 0700)) 78 79 Expect(reader.File[3].Name).To(Equal(filepath.Join(dirName, "file3"))) 80 Expect(reader.File[3].Mode()).To(Equal(os.FileMode(0755))) 81 }) 82 }) 83 }) 84 })