Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify upload release handling to always check if skippable #586

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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