github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/actor/v7action/buildpack_windows_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  				ioutil.WriteFile(filepath.Join(source, "file1"), []byte{}, 0666)
    42  				ioutil.WriteFile(filepath.Join(source, "file2"), []byte{}, 0666)
    43  				subDir, err = ioutil.TempDir(source, "zipit-subdir-")
    44  				Expect(err).ToNot(HaveOccurred())
    45  				ioutil.WriteFile(filepath.Join(subDir, "file3"), []byte{}, 0666)
    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("ensures that regular files have the executable bit set for the owner", 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  				reader, err := ykk.NewReader(zipFile, zipStat.Size())
    65  				Expect(err).ToNot(HaveOccurred())
    66  
    67  				Expect(reader.File).To(HaveLen(4))
    68  				Expect(reader.File[0].Name).To(Equal("file1"))
    69  				Expect(reader.File[0].Mode()).To(Equal(os.FileMode(0766)))
    70  
    71  				Expect(reader.File[1].Name).To(Equal("file2"))
    72  				Expect(reader.File[1].Mode()).To(Equal(os.FileMode(0766)))
    73  
    74  				dirName := fmt.Sprintf("%s/", filepath.Base(subDir))
    75  				Expect(reader.File[2].Name).To(Equal(dirName))
    76  				Expect(reader.File[2].Mode()).To(Equal(os.FileMode(020000000777)))
    77  
    78  				Expect(reader.File[3].Name).To(Equal(filepath.ToSlash(filepath.Join(dirName, "file3"))))
    79  				Expect(reader.File[3].Mode()).To(Equal(os.FileMode(0766)))
    80  			})
    81  		})
    82  	})
    83  })