defer f.Close() Expect(h.Name).To(Equal("subfolder/sub")) Expect(h.FileInfo().Mode()).To(Equal(os.FileMode(0644))) Expect(f.Read(buffer)).To(Equal(12)) Expect(string(buffer)).To(Equal("sub contents")) }) Context("failure", func() { It("returns an error if passed a non-directory", func() { _, err := zipper.Zip(filepath.Join(tmpDir, "aaa"), fakeCFIgnore) Expect(err).To(MatchError(fmt.Sprintf("%s must be a directory", filepath.Join(tmpDir, "aaa")))) }) It("returns an error if .cfignore can't be parsed", func() { Expect(ioutil.WriteFile(filepath.Join(tmpDir, ".cfignore"), []byte{}, 0600)).To(Succeed()) fakeCFIgnore.ParseReturns(errors.New("no")) _, err := zipper.Zip(tmpDir, fakeCFIgnore) Expect(err).To(MatchError("no")) }) }) }) Describe("#Unzip", func() { var ( prevDir, tmpDir string err error tmpFile *os.File prevUmask int ) BeforeEach(func() {
Describe(".cfignore", func() { Context("when a .cfignore file is present", func() { BeforeEach(func() { Expect(ioutil.WriteFile(filepath.Join(tmpDir, ".cfignore"), []byte("cfignore contents"), 0644)).To(Succeed()) }) It("parses a .cfignore file if present", func() { test_helpers.ExecuteCommandWithArgs(buildDropletCommand, []string{"droplet-name", "http://some.url/for/buildpack"}) Expect(fakeCFIgnore.ParseCallCount()).To(Equal(1)) Expect(ioutil.ReadAll(fakeCFIgnore.ParseArgsForCall(0))).To(Equal([]byte("cfignore contents"))) }) Context("when parsing the .cfignore file fails", func() { It("returns an error without uploading any bits", func() { fakeCFIgnore.ParseReturns(errors.New("some cfignore parse error")) test_helpers.ExecuteCommandWithArgs(buildDropletCommand, []string{"droplet-name", "http://some.url/for/buildpack"}) Expect(outputBuffer).To(test_helpers.Say("some cfignore parse error")) Expect(fakeDropletRunner.UploadBitsCallCount()).To(Equal(0)) Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.FileSystemError})) }) }) }) It("does not parse a .cfignore file when missing", func() { test_helpers.ExecuteCommandWithArgs(buildDropletCommand, []string{"droplet-name", "http://some.url/for/buildpack"}) Expect(fakeCFIgnore.ParseCallCount()).To(Equal(0)) })