Skip to content

Commit

Permalink
deprecate --download-stemcell on download-product command
Browse files Browse the repository at this point in the history
Signed-off-by: JT Archie <[email protected]>
  • Loading branch information
fredwangwang authored and JT Archie committed Jan 3, 2019
1 parent 73cf62f commit ada0d4a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 40 deletions.
6 changes: 3 additions & 3 deletions commands/download_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type DownloadProduct struct {
ProductVersion string `long:"product-version" short:"v" description:"version of the product-slug to download files from. Incompatible with --product-version-regex flag."`
ProductVersionRegex string `long:"product-version-regex" short:"r" description:"Regex pattern matching versions of the product-slug to download files from. Highest-versioned match will be used. Incompatible with --product-version flag."`
OutputDir string `long:"output-directory" short:"o" description:"Directory path to which the file will be outputted. File name will be preserved from Pivotal Network" required:"true"`
Stemcell bool `long:"download-stemcell" description:"If set, the latest available stemcell for the product will also be downloaded"`
StemcellIaas string `long:"stemcell-iaas" description:"The stemcell for the specified iaas. for example 'vsphere' or 'vcloud' or 'openstack' or 'google' or 'azure' or 'aws'"`
Stemcell bool `long:"download-stemcell" description:"No-op for backwards compatibility"`
StemcellIaas string `long:"stemcell-iaas" description:"Download the latest available stemcell for the product for the specified iaas. for example 'vsphere' or 'vcloud' or 'openstack' or 'google' or 'azure' or 'aws'"`
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ func (c DownloadProduct) Execute(args []string) error {
return fmt.Errorf("could not download product: %s", err)
}

if !c.Options.Stemcell {
if c.Options.StemcellIaas == "" {
return c.writeOutputFile(productFileName, stemcellFileName, "")
}

Expand Down
65 changes: 28 additions & 37 deletions commands/download_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
var _ = Describe("DownloadProduct", func() {
var (
command commands.DownloadProduct
commandArgs []string
logger *loggerfakes.FakeLogger
fakePivnetDownloader *fakes.PivnetDownloader
fakeWriter *gbytes.Buffer
Expand Down Expand Up @@ -60,6 +61,14 @@ var _ = Describe("DownloadProduct", func() {

tempDir, err = ioutil.TempDir("", "om-tests-")
Expect(err).NotTo(HaveOccurred())

commandArgs = []string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
"--product-version", "2.0.0",
"--output-directory", tempDir,
}
})

AfterEach(func() {
Expand All @@ -68,13 +77,7 @@ var _ = Describe("DownloadProduct", func() {
})

It("downloads a product from Pivotal Network", func() {
err := command.Execute([]string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
"--product-version", "2.0.0",
"--output-directory", tempDir,
})
err = command.Execute(commandArgs)
Expect(err).NotTo(HaveOccurred())

Expect(fakePivnetDownloader.ReleasesForProductSlugCallCount()).To(Equal(0))
Expand Down Expand Up @@ -139,16 +142,18 @@ var _ = Describe("DownloadProduct", func() {
fakePivnetDownloader.ReleaseForVersionReturnsOnCall(0, pivnet.Release{
ID: 4,
}, nil)
})

It("downloads the highest version matching that regex", func() {
err := command.Execute([]string{
commandArgs = []string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
"--product-version-regex", `2\..\..*`,
"--output-directory", tempDir,
})
}
})

It("downloads the highest version matching that regex", func() {
err = command.Execute(commandArgs)
Expect(err).NotTo(HaveOccurred())

Expect(fakePivnetDownloader.ReleasesForProductSlugCallCount()).To(Equal(1))
Expand Down Expand Up @@ -195,13 +200,7 @@ var _ = Describe("DownloadProduct", func() {
})

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,
})
err = command.Execute(commandArgs)
Expect(err).NotTo(HaveOccurred())

logStr, _ := logger.InfoArgsForCall(0)
Expand All @@ -227,13 +226,7 @@ var _ = Describe("DownloadProduct", func() {
})

It("returns an error", func() {
err := command.Execute([]string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
"--product-version", "2.0.0",
"--output-directory", tempDir,
})
err = command.Execute(commandArgs)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(`the glob '*.pivotal' matches multiple files. Write your glob to match exactly one of the following:`))
})
Expand Down Expand Up @@ -303,14 +296,13 @@ var _ = Describe("DownloadProduct", func() {
})

It("grabs the latest stemcell for the product that matches the glob", func() {
err := command.Execute([]string{
err = command.Execute([]string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
"--product-version", "2.0.0",
"--output-directory", tempDir,
"--download-stemcell",
"stemcell-iaas", "google",
"--stemcell-iaas", "google",
})
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -361,22 +353,21 @@ var _ = Describe("DownloadProduct", func() {
})

It("exit gracefully when the product is not a tile", func() {
err := command.Execute([]string{
err = command.Execute([]string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.tgz",
"--pivnet-product-slug", "elastic-runtime",
"--product-version", "2.0.0",
"--output-directory", tempDir,
"--download-stemcell",
"stemcell-iaas", "google",
"--stemcell-iaas", "google",
})
Expect(err).NotTo(HaveOccurred())
Expect(fakePivnetDownloader.ProductFilesForReleaseCallCount()).To(Equal(1))
Expect(fakePivnetDownloader.DownloadProductFileCallCount()).To(Equal(1))
Expect(fakePivnetDownloader.DownloadProductFileCallCount()).To(Equal(1))
Expect(fakePivnetDownloader.ReleaseForVersionCallCount()).To(Equal(1))

infoStr, _ := logger.InfoArgsForCall(1)
infoStr, _ := logger.InfoArgsForCall(2)
Expect(infoStr).To(Equal("the downloaded file is not a .pivotal file. Not determining and fetching required stemcell."))
})
})
Expand Down Expand Up @@ -407,7 +398,7 @@ var _ = Describe("DownloadProduct", func() {
})

It("does not download the file again", func() {
err := command.Execute([]string{
err = command.Execute([]string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
Expand Down Expand Up @@ -514,21 +505,21 @@ output-directory: %s
Context("failure cases", func() {
Context("when an unknown flag is provided", func() {
It("returns an error", func() {
err := command.Execute([]string{"--badflag"})
err = command.Execute([]string{"--badflag"})
Expect(err).To(MatchError("could not parse download-product flags: flag provided but not defined: -badflag"))
})
})

Context("when a required flag is not provided", func() {
It("returns an error", func() {
err := command.Execute([]string{})
err = command.Execute([]string{})
Expect(err).To(MatchError("could not parse download-product flags: missing required flag \"--pivnet-api-token\""))
})
})

Context("when both product-version and product-version-regex are set", func() {
It("fails with an error saying that the user must pick one or the other", func() {
err := command.Execute([]string{
err = command.Execute([]string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
Expand All @@ -547,7 +538,7 @@ output-directory: %s
})

It("returns an error", func() {
err := command.Execute([]string{
err = command.Execute([]string{
"--pivnet-api-token", "token",
"--pivnet-file-glob", "*.pivotal",
"--pivnet-product-slug", "elastic-runtime",
Expand Down

0 comments on commit ada0d4a

Please sign in to comment.