if current version goes away, return latest

[#106794594]
This commit is contained in:
Alex Suraci
2015-10-27 15:00:16 -07:00
parent 6c3c5e9cbd
commit df30f19ffa
2 changed files with 39 additions and 0 deletions

View File

@@ -78,6 +78,14 @@ func (c *CheckCommand) Run(request CheckRequest) ([]Version, error) {
}
}
if !upToLatest {
// current version was removed; start over from latest
reversedVersions = append(
reversedVersions,
versionFromDraft(&filteredReleases[len(filteredReleases)-1]),
)
}
return reversedVersions, nil
}

View File

@@ -131,6 +131,21 @@ var _ = Describe("Check Command", func() {
{Tag: "0.4.0"},
}))
})
It("returns the latest version if the current version is not found", func() {
command := resource.NewCheckCommand(githubClient)
response, err := command.Run(resource.CheckRequest{
Version: resource.Version{
Tag: "v3.4.5",
},
})
Ω(err).ShouldNot(HaveOccurred())
Ω(response).Should(Equal([]resource.Version{
{Tag: "0.4.0"},
}))
})
})
Context("and one of the releases is a draft", func() {
@@ -163,6 +178,7 @@ var _ = Describe("Check Command", func() {
BeforeEach(func() {
returnedReleases = []github.RepositoryRelease{
newDraftRepositoryRelease(1, "v0.1.4"),
newDraftRepositoryRelease(2, "v0.1.3"),
newDraftRepositoryRelease(3, "v0.1.1"),
newRepositoryRelease(2, "0.4.0"),
}
@@ -177,6 +193,21 @@ var _ = Describe("Check Command", func() {
})
Ω(err).ShouldNot(HaveOccurred())
Ω(response).Should(Equal([]resource.Version{
{ID: "2"},
{ID: "1"},
}))
})
It("returns the latest draft version if the current version is not found", func() {
command := resource.NewCheckCommand(githubClient)
response, err := command.Run(resource.CheckRequest{
Version: resource.Version{ID: "5"},
Source: resource.Source{Drafts: true},
})
Ω(err).ShouldNot(HaveOccurred())
Ω(response).Should(Equal([]resource.Version{
{ID: "1"},
}))