Skip to content

Commit

Permalink
Merge pull request #586 from cloudfoundry/fix/176750617-wip-upload-re…
Browse files Browse the repository at this point in the history
…lease

Unify upload release handling to always check if skippable
  • Loading branch information
lnguyen authored Jan 25, 2022
2 parents cc57a73 + d5830b5 commit e75f6a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/upload_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func NewUploadReleaseCmd(
func (c UploadReleaseCmd) Run(opts UploadReleaseOpts) error {
switch {
case opts.Release != nil:
return c.uploadRelease(opts.Release, opts)
return c.uploadIfNecessary(opts, c.uploadFile)
case opts.Args.URL.IsRemote():
return c.uploadIfNecessary(opts, c.uploadRemote)
case opts.Args.URL.IsGit():
return c.uploadIfNecessary(opts, c.uploadGit)
default:
return c.uploadFile(opts)
return c.uploadIfNecessary(opts, c.uploadFile)
}
}

Expand Down
19 changes: 19 additions & 0 deletions cmd/upload_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ var _ = Describe("UploadReleaseCmd", func() {
Expect(rebase).To(BeFalse())
Expect(fix).To(BeFalse())
})
It("does not upload release if name and version match existing release", func() {
releaseReader.ReadStub = func(path string) (boshrel.Release, error) {
Expect(path).To(Equal("./some-file.tgz"))
return release, nil
}
opts.Name = "existing-name"
opts.Version = VersionArg(semver.MustNewVersionFromString("existing-ver"))
director.HasReleaseReturns(true, nil)
err := act()
Expect(err).ToNot(HaveOccurred())

name, version, stemcell := director.HasReleaseArgsForCall(0)
Expect(name).To(Equal("existing-name"))
Expect(version).To(Equal("existing-ver"))
Expect(stemcell).To(Equal(boshdir.OSVersionSlug{}))
Expect(director.UploadReleaseFileCallCount()).To(Equal(0))
Expect(ui.Said).To(Equal(
[]string{"Release 'existing-name/existing-ver' already exists."}))
})

It("clean up release", func() {
releaseReader.ReadStub = func(path string) (boshrel.Release, error) {
Expand Down
4 changes: 4 additions & 0 deletions integration/upload_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ blobstore:
ghttp.VerifyRequest("GET", "/info"),
ghttp.RespondWith(http.StatusOK, `{"user_authentication":{"type":"basic","options":{}}}`),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/releases"),
ghttp.RespondWith(http.StatusOK, "[]"),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/packages/matches"),
ghttp.RespondWith(http.StatusOK, "[]"),
Expand Down

0 comments on commit e75f6a6

Please sign in to comment.