github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7action/buildpack_windows_test.go (about) 1 //go:build windows 2 // +build windows 3 4 package v7action_test 5 6 import ( 7 "fmt" 8 "io/ioutil" 9 "os" 10 "path/filepath" 11 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 15 . "code.cloudfoundry.org/cli/actor/v7action" 16 "code.cloudfoundry.org/cli/integration/helpers" 17 "code.cloudfoundry.org/ykk" 18 ) 19 20 var _ = Describe("Buildpack", func() { 21 Describe("Zipit", func() { 22 var ( 23 source string 24 target string 25 26 executeErr error 27 ) 28 29 JustBeforeEach(func() { 30 executeErr = Zipit(source, target, "testzip-") 31 }) 32 33 When("the source directory exists", func() { 34 var subDir string 35 36 BeforeEach(func() { 37 var err error 38 39 source, err = ioutil.TempDir("", "zipit-source-") 40 Expect(err).ToNot(HaveOccurred()) 41 42 ioutil.WriteFile(filepath.Join(source, "file1"), []byte{}, 0666) 43 ioutil.WriteFile(filepath.Join(source, "file2"), []byte{}, 0666) 44 subDir, err = ioutil.TempDir(source, "zipit-subdir-") 45 Expect(err).ToNot(HaveOccurred()) 46 ioutil.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0666) 47 48 p := filepath.FromSlash(fmt.Sprintf("buildpack-%s.zip", helpers.RandomName())) 49 target, err = filepath.Abs(p) 50 Expect(err).ToNot(HaveOccurred()) 51 }) 52 53 AfterEach(func() { 54 Expect(os.RemoveAll(source)).ToNot(HaveOccurred()) 55 Expect(os.RemoveAll(target)).ToNot(HaveOccurred()) 56 }) 57 58 It("ensures that regular files have the executable bit set for the owner", func() { 59 Expect(executeErr).ToNot(HaveOccurred()) 60 zipFile, err := os.Open(target) 61 Expect(err).ToNot(HaveOccurred()) 62 defer zipFile.Close() 63 64 zipStat, err := zipFile.Stat() 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(0766))) 71 72 Expect(reader.File[1].Name).To(Equal("file2")) 73 Expect(reader.File[1].Mode()).To(Equal(os.FileMode(0766))) 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.FileMode(020000000777))) 78 79 Expect(reader.File[3].Name).To(Equal(filepath.ToSlash(filepath.Join(dirName, "file3")))) 80 Expect(reader.File[3].Mode()).To(Equal(os.FileMode(0766))) 81 }) 82 }) 83 }) 84 })