Skip to content

Commit

Permalink
download-product iginore non-semver compatible versions
Browse files Browse the repository at this point in the history
We found this as an issue in PKS. It has versions like '1.1.x',
which is not parsable by the semver library. So we chose to ignore
such versions and give a warning, but continue to parse the rest
of versions. The same behavior found in pivnet-resource as well.

Signed-off-by: JT Archie <[email protected]>
  • Loading branch information
fredwangwang authored and JT Archie committed Jan 3, 2019
1 parent 1cab772 commit 73cf62f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
1 change: 0 additions & 1 deletion acceptance/configure_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ var _ = Describe("configure-product command", func() {
_, err = configFile.WriteString(configFileContents)
Expect(err).ToNot(HaveOccurred())


command := exec.Command(pathToMain,
"--target", server.URL,
"--username", "some-username",
Expand Down
4 changes: 3 additions & 1 deletion commands/download_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func (c DownloadProduct) Execute(args []string) error {

v, err := version.NewVersion(release.Version)
if err != nil {
return fmt.Errorf("could not parse version: %s: %s", release.Version, err)
c.logger.Info(fmt.Sprintf("could not parse version: %s", release.Version))
continue
}
versions = append(versions, v)
}
Expand Down Expand Up @@ -234,6 +235,7 @@ func (c *DownloadProduct) downloadProductFile(slug, version, glob string) (int,
}
defer productFile.Close()

c.logger.Info(fmt.Sprintf("downloading %s...", productFile.Name()))
err = c.client.DownloadProductFile(productFile, slug, release.ID, productFileName.ID, c.progressWriter)
if err != nil {
return release.ID, "", fmt.Errorf("could not download product file %s %s: %s", slug, version, err)
Expand Down
29 changes: 29 additions & 0 deletions commands/download_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,35 @@ var _ = Describe("DownloadProduct", func() {
Expect(fileName).To(BeAnExistingFile())
Expect(string(fileContent)).To(MatchJSON(fmt.Sprintf(`{"product_path": "%s", "product_slug": "elastic-runtime" }`, file.Name())))
})

Context("when the releases contains non-semver-compatible version", func() {
BeforeEach(func() {
fakePivnetDownloader.ReleasesForProductSlugReturns([]pivnet.Release{
{
ID: 3,
Version: "2.1.2",
},
{
ID: 0,
Version: "2.0.x",
},
}, nil)
})

It("ignores the version and prints a warning", func() {
err := command.Execute([]string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
"--product-version-regex", `2\..\..*`,
"--output-directory", tempDir,
})
Expect(err).NotTo(HaveOccurred())

logStr, _ := logger.InfoArgsForCall(0)
Expect(logStr).To(Equal("could not parse version: 2.0.x"))
})
})
})

Context("when the globs returns multiple files", func() {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func main() {
})
logWriter := commands.NewLogWriter(os.Stdout)
tableWriter := tablewriter.NewWriter(os.Stdout)
pivnetLogWriter := logshim.NewLogShim(stdout, stdout, global.Trace)
pivnetLogWriter := logshim.NewLogShim(stderr, stderr, global.Trace)

form := formcontent.NewForm()

Expand Down

0 comments on commit 73cf62f

Please sign in to comment.