Expect(os.Mkdir(filepath.Join(tmpDir, "subfolder"), 0755)).To(Succeed())
			Expect(ioutil.WriteFile(filepath.Join(tmpDir, "subfolder", "sub"), []byte("sub contents"), 0644)).To(Succeed())

			prevDir, err = os.Getwd()
			Expect(err).NotTo(HaveOccurred())
			Expect(os.Chdir(tmpDir)).To(Succeed())
		})

		AfterEach(func() {
			Expect(os.Chdir(prevDir)).To(Succeed())
			Expect(os.RemoveAll(tmpDir)).To(Succeed())
		})

		It("zips successfully", func() {
			zipPath, err := zipper.Zip(tmpDir, fakeCFIgnore)
			Expect(err).NotTo(HaveOccurred())

			zipReader, err := zip.OpenReader(zipPath)
			Expect(err).NotTo(HaveOccurred())

			Expect(zipReader.File).To(HaveLen(6))

			h := zipReader.File[0].FileHeader
			Expect(h.FileInfo().Mode()).To(Equal(os.FileMode(0700)))

			h = zipReader.File[1].FileHeader
			Expect(h.FileInfo().Mode()).To(Equal(os.FileMode(0750)))

			h = zipReader.File[2].FileHeader
			Expect(h.FileInfo().Mode()).To(Equal(os.FileMode(0644)))
Exemplo n.º 2
0
			prevDir, err = os.Getwd()
			Expect(err).NotTo(HaveOccurred())
			Expect(os.Chdir(tmpDir)).To(Succeed())

			fakeCFIgnore.ShouldIgnoreStub = func(path string) bool {
				return path == "some-ignored-file"
			}
		})

		AfterEach(func() {
			Expect(os.Chdir(prevDir)).To(Succeed())
			Expect(os.RemoveAll(tmpDir)).To(Succeed())
		})

		It("zips successfully", func() {
			zipPath, err := zipper.Zip(tmpDir, fakeCFIgnore)
			Expect(err).NotTo(HaveOccurred())

			zipReader, err := zip.OpenReader(zipPath)
			Expect(err).NotTo(HaveOccurred())

			Expect(zipReader.File).To(HaveLen(6))

			buffer := make([]byte, 12)
			h := zipReader.File[0].FileHeader
			f, err := zipReader.File[0].Open()
			Expect(err).NotTo(HaveOccurred())
			defer f.Close()
			Expect(h.Name).To(Equal("aaa"))
			Expect(h.FileInfo().Mode()).To(Equal(os.FileMode(0700)))
			Expect(f.Read(buffer)).To(Equal(12))