Skip to content

Commit

Permalink
fix download file output
Browse files Browse the repository at this point in the history
change from defer to direct function call
  • Loading branch information
JT Archie committed Oct 31, 2018
1 parent 02b707d commit c043d4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions commands/download_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ func (c DownloadProduct) Execute(args []string) error {
var productFileName, stemcellFileName string
var releaseID int

defer c.writerDownloadedFileList(productFileName, stemcellFileName)

c.init()

releaseID, productFileName, err = c.downloadProductFile(c.Options.ProductSlug, c.Options.ProductVersion, c.Options.FileGlob)
Expand All @@ -95,7 +93,7 @@ func (c DownloadProduct) Execute(args []string) error {
}

if !c.Options.Stemcell {
return nil
return c.writerDownloadedFileList(productFileName, stemcellFileName)
}

c.logger.Info("Downloading stemcell")
Expand All @@ -121,7 +119,7 @@ func (c DownloadProduct) Execute(args []string) error {
return fmt.Errorf("could not download stemcell: %s", err)
}

return nil
return c.writerDownloadedFileList(productFileName, stemcellFileName)
}

func (c DownloadProduct) writerDownloadedFileList(productFileName string, stemcellFileName string) error {
Expand Down
3 changes: 3 additions & 0 deletions commands/download_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ var _ = Describe("DownloadProduct", func() {
Expect(productFileID).To(Equal(54321))

fileName := path.Join(tempDir, commands.DownloadListFilename)
fileContent, err := ioutil.ReadFile(fileName)
Expect(err).NotTo(HaveOccurred())
Expect(fileName).To(BeAnExistingFile())
Expect(string(fileContent)).To(MatchJSON(fmt.Sprintf(`{"product": "%s" }`, file.Name())))
})

Context("when the globs returns multiple files", func() {
Expand Down

0 comments on commit c043d4a

Please sign in to comment.