Skip to content

Commit 2c14b9c

Browse files
Adds test to see the v is stripped
1 parent ce26b74 commit 2c14b9c

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

remote_fetcher.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (r RemoteFetcher) Get(buildpack RemoteBuildpack) (string, error) {
8080
}
8181

8282
path := cachedEntry.URI
83-
tagName := strings.TrimLeft(release.TagName, "v")
83+
tagName := strings.TrimPrefix(release.TagName, "v")
8484

8585
if tagName != cachedEntry.Version || !exist {
8686
missingReleaseArtifacts := !(len(release.Assets) > 0)

remote_fetcher_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,55 @@ func testRemoteFetcher(t *testing.T, context spec.G, it spec.S) {
320320
})
321321
})
322322

323+
context("when there is a v prepending the release tag", func() {
324+
it.Before(func() {
325+
gitReleaseFetcher.GetCall.Returns.Release = github.Release{
326+
TagName: "v1.2.3",
327+
Assets: []github.ReleaseAsset{
328+
{
329+
URL: "some-url",
330+
},
331+
},
332+
TarballURL: "some-tarball-url",
333+
}
334+
335+
buildpackCache.GetCall.Returns.CacheEntry = freezer.CacheEntry{
336+
Version: "some-other-tag",
337+
}
338+
339+
Expect(os.MkdirAll(filepath.Join(cacheDir, "some-org", "some-repo"), os.ModePerm)).To(Succeed())
340+
})
341+
342+
it("removes the v from the tag", func() {
343+
uri, err := remoteFetcher.Get(remoteBuildpack)
344+
Expect(err).ToNot(HaveOccurred())
345+
346+
Expect(gitReleaseFetcher.GetCall.Receives.Org).To(Equal("some-org"))
347+
Expect(gitReleaseFetcher.GetCall.Receives.Repo).To(Equal("some-repo"))
348+
349+
Expect(buildpackCache.GetCall.Receives.Key).To(Equal("some-org:some-repo"))
350+
351+
Expect(gitReleaseFetcher.GetReleaseAssetCall.Receives.Asset).To(Equal(github.ReleaseAsset{
352+
URL: "some-url",
353+
}))
354+
355+
Expect(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz")).To(BeAnExistingFile())
356+
file, err := os.Open(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz"))
357+
Expect(err).ToNot(HaveOccurred())
358+
359+
err = vacation.NewArchive(file).Decompress(filepath.Join(cacheDir, "some-org", "some-repo"))
360+
Expect(err).ToNot(HaveOccurred())
361+
362+
content, err := os.ReadFile(filepath.Join(cacheDir, "some-org", "some-repo", "some-file"))
363+
Expect(err).NotTo(HaveOccurred())
364+
Expect(string(content)).To(Equal("some content"))
365+
366+
Expect(buildpackCache.SetCall.CallCount).To(Equal(1))
367+
368+
Expect(uri).To(Equal(filepath.Join(cacheDir, "some-org", "some-repo", "1.2.3.tgz")))
369+
})
370+
})
371+
323372
context("failure cases", func() {
324373
context("when there is a failure in the gitReleaseFetcher get", func() {
325374
it.Before(func() {

0 commit comments

Comments
 (0)