func (cmd *PluginInstall) tryDownloadPluginBinaryfromGivenPath(pluginSourceFilepath string, downloader fileutils.Downloader) string { size, filename, err := downloader.DownloadFile(pluginSourceFilepath) if err != nil { cmd.ui.Failed(fmt.Sprintf(T("Download attempt failed: {{.Error}}\n\nUnable to install, plugin is not available from the given url.", map[string]interface{}{"Error": err.Error()}))) } cmd.ui.Say(fmt.Sprintf("%d "+T("bytes downloaded")+"...", size)) executablePath := filepath.Join(downloader.SavePath(), filename) os.Chmod(executablePath, 0700) return executablePath }
err := downloader.RemoveFile() Expect(err).NotTo(HaveOccurred()) }) Context("when the server responds with the file", func() { BeforeEach(func() { server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/abc.zip"), ghttp.RespondWith(http.StatusOK, "abc123"), ), ) }) It("saves file with name found in URL in provided dir", func() { _, _, err := downloader.DownloadFile(server.URL() + "/abc.zip") Expect(err).NotTo(HaveOccurred()) _, err = os.Stat(path.Join(tempDir, "abc.zip")) Expect(err).NotTo(HaveOccurred()) }) It("returns the number of bytes written to the file", func() { n, _, err := downloader.DownloadFile(server.URL() + "/abc.zip") Expect(err).NotTo(HaveOccurred()) Expect(n).To(Equal(int64(len("abc123")))) }) It("returns the name of the file that was downloaded", func() { _, name, err := downloader.DownloadFile(server.URL() + "/abc.zip") Expect(err).NotTo(HaveOccurred())