It("fails to upload a buildpack with an invalid directory", func() { apiResponse := repo.UploadBuildpack(buildpack, "/foo/bar") Expect(apiResponse.IsNotSuccessful()).To(BeTrue()) Expect(apiResponse.Message).To(ContainSubstring("Error opening buildpack file")) }) It("uploads a valid buildpack directory", func() { buildpackPath := filepath.Join(buildpacksDir, "example-buildpack") os.Chmod(filepath.Join(buildpackPath, "bin/compile"), 0755) os.Chmod(filepath.Join(buildpackPath, "bin/detect"), 0755) err := os.Chmod(filepath.Join(buildpackPath, "bin/release"), 0755) Expect(err).NotTo(HaveOccurred()) apiResponse := repo.UploadBuildpack(buildpack, buildpackPath) Expect(testServerHandler.AllRequestsCalled()).To(BeTrue()) Expect(apiResponse.IsSuccessful()).To(BeTrue()) }) It("uploads a valid zipped buildpack", func() { buildpackPath := filepath.Join(buildpacksDir, "example-buildpack.zip") apiResponse := repo.UploadBuildpack(buildpack, buildpackPath) Expect(testServerHandler.AllRequestsCalled()).To(BeTrue()) Expect(apiResponse.IsSuccessful()).To(BeTrue()) }) Describe("when the buildpack is wrapped in an extra top-level directory", func() { It("uploads a zip file containing only the actual buildpack", func() { buildpackPath := filepath.Join(buildpacksDir, "example-buildpack-in-dir.zip")
var buildpackFileServerHandler = func(buildpackName string) http.HandlerFunc { return func(writer http.ResponseWriter, request *http.Request) { Expect(request.URL.Path).To(Equal("/place/example-buildpack.zip")) f, err := os.Open(filepath.Join(buildpacksDir, buildpackName)) Expect(err).NotTo(HaveOccurred()) io.Copy(writer, f) } } It("uploads the file over HTTP", func() { fileServer := httptest.NewServer(buildpackFileServerHandler("example-buildpack.zip")) defer fileServer.Close() apiResponse := repo.UploadBuildpack(buildpack, fileServer.URL+"/place/example-buildpack.zip") Expect(handler.AllRequestsCalled()).To(BeTrue()) Expect(apiResponse.IsSuccessful()).To(BeTrue()) }) It("uploads the file over HTTPS", func() { fileServer := httptest.NewTLSServer(buildpackFileServerHandler("example-buildpack.zip")) defer fileServer.Close() apiResponse := repo.UploadBuildpack(buildpack, fileServer.URL+"/place/example-buildpack.zip") Expect(handler.AllRequestsCalled()).To(BeTrue()) Expect(apiResponse.IsSuccessful()).To(BeTrue()) }) Describe("when the buildpack is wrapped in an extra top-level directory", func() { It("uploads a zip file containing only the actual buildpack", func() { fileServer := httptest.NewTLSServer(buildpackFileServerHandler("example-buildpack-in-dir.zip"))