Skip to content

Commit

Permalink
Add a progress bar on uploads
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Wall <[email protected]>
  • Loading branch information
Pete Wall authored and petewall committed May 26, 2022
1 parent bffa1f4 commit 10475cc
Show file tree
Hide file tree
Showing 17 changed files with 932 additions and 151 deletions.
4 changes: 3 additions & 1 deletion cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var DownloadCmd = &cobra.Command{
if DownloadFilter == "" {
asset = assets[0]
if len(assets) > 1 {
_ = Output.RenderAssets(assets)
return fmt.Errorf("product %s %s has multiple downloadable assets, please use the --filter parameter", product.Slug, version.Number)
}
} else {
Expand All @@ -72,6 +73,7 @@ var DownloadCmd = &cobra.Command{

asset = filterAssets[0]
if len(filterAssets) > 1 {
_ = Output.RenderAssets(filterAssets)
return fmt.Errorf("product %s %s has multiple downloadable assets that match the filter \"%s\", please adjust the --filter parameter", product.Slug, version.Number, DownloadFilter)
}
}
Expand All @@ -92,6 +94,6 @@ var DownloadCmd = &cobra.Command{
}

asset.DownloadRequestPayload.EulaAccepted = DownloadAcceptEULA
return Marketplace.Download(product.ProductId, filename, asset.DownloadRequestPayload)
return Marketplace.Download(filename, asset.DownloadRequestPayload)
},
}
25 changes: 20 additions & 5 deletions cmd/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
"github.com/vmware-labs/marketplace-cli/v2/cmd"
"github.com/vmware-labs/marketplace-cli/v2/cmd/output/outputfakes"
"github.com/vmware-labs/marketplace-cli/v2/internal/models"
"github.com/vmware-labs/marketplace-cli/v2/pkg/pkgfakes"
"github.com/vmware-labs/marketplace-cli/v2/test"
Expand All @@ -19,11 +20,15 @@ import (
var _ = Describe("DownloadCmd", func() {
var (
marketplace *pkgfakes.FakeMarketplaceInterface
output *outputfakes.FakeFormat
product *models.Product
productId string
)

BeforeEach(func() {
output = &outputfakes.FakeFormat{}
cmd.Output = output

productId = uuid.New().String()
product = test.CreateFakeProduct(productId, "My Super Product", "my-super-product", "PENDING")

Expand Down Expand Up @@ -61,8 +66,7 @@ var _ = Describe("DownloadCmd", func() {

By("downloading the asset", func() {
Expect(marketplace.DownloadCallCount()).To(Equal(1))
downloadedProductId, filename, assetPayload := marketplace.DownloadArgsForCall(0)
Expect(downloadedProductId).To(Equal(productId))
filename, assetPayload := marketplace.DownloadArgsForCall(0)
Expect(filename).To(Equal("my-db.ova"))
Expect(assetPayload.ProductId).To(Equal(productId))
Expect(assetPayload.AppVersion).To(Equal("1.1.1"))
Expand Down Expand Up @@ -109,7 +113,7 @@ var _ = Describe("DownloadCmd", func() {
Expect(err).ToNot(HaveOccurred())

Expect(marketplace.DownloadCallCount()).To(Equal(1))
_, filename, _ := marketplace.DownloadArgsForCall(0)
filename, _ := marketplace.DownloadArgsForCall(0)
Expect(filename).To(Equal("overridden-filename.ova"))
})
})
Expand Down Expand Up @@ -161,6 +165,12 @@ var _ = Describe("DownloadCmd", func() {
err := cmd.DownloadCmd.RunE(cmd.DownloadCmd, []string{""})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("product my-super-product 3.3.3 has multiple downloadable assets, please use the --filter parameter"))

By("printing the list of assets", func() {
Expect(output.RenderAssetsCallCount()).To(Equal(1))
assets := output.RenderAssetsArgsForCall(0)
Expect(assets).To(HaveLen(3))
})
})
})

Expand All @@ -175,8 +185,7 @@ var _ = Describe("DownloadCmd", func() {

By("downloading the chosen asset", func() {
Expect(marketplace.DownloadCallCount()).To(Equal(1))
downloadedProductId, filename, assetPayload := marketplace.DownloadArgsForCall(0)
Expect(downloadedProductId).To(Equal(productId))
filename, assetPayload := marketplace.DownloadArgsForCall(0)
Expect(filename).To(Equal("bbb.txt"))
Expect(assetPayload.ProductId).To(Equal(productId))
Expect(assetPayload.AppVersion).To(Equal("3.3.3"))
Expand Down Expand Up @@ -205,6 +214,12 @@ var _ = Describe("DownloadCmd", func() {
err := cmd.DownloadCmd.RunE(cmd.DownloadCmd, []string{""})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("product my-super-product 3.3.3 has multiple downloadable assets that match the filter \"txt\", please adjust the --filter parameter"))

By("printing the list of assets", func() {
Expect(output.RenderAssetsCallCount()).To(Equal(1))
assets := output.RenderAssetsArgsForCall(0)
Expect(assets).To(HaveLen(3))
})
})
})
})
Expand Down
186 changes: 186 additions & 0 deletions internal/internalfakes/fake_progress_bar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 10475cc

Please sign in to comment.