Skip to content

Commit

Permalink
fix: downloadRelease source path parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
notrepo05 committed Sep 13, 2022
1 parent d3f4ddb commit 4ca4fbb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
10 changes: 6 additions & 4 deletions internal/component/github_release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"log"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -181,10 +182,11 @@ type releaseByTagGetterAssetDownloader interface {

func downloadRelease(ctx context.Context, releaseDir string, remoteRelease Lock, client releaseByTagGetterAssetDownloader, _ *log.Logger) (Local, error) {
filePath := filepath.Join(releaseDir, fmt.Sprintf("%s-%s.tgz", remoteRelease.Name, remoteRelease.Version))
org, repo, err := OwnerAndRepoFromGitHubURI(remoteRelease.RemotePath)
if err != nil {
fmt.Printf("failed to parse repository name and owner: %s: ", err)
}

remoteUrl, err := url.Parse(remoteRelease.RemotePath)
remotePathParts := strings.Split(remoteUrl.Path, "/")
// TODO: add test coverage for length
org, repo := remotePathParts[1], remotePathParts[2]

rTag, _, err0 := client.GetReleaseByTag(ctx, org, repo, remoteRelease.Version)
if err0 != nil {
Expand Down
24 changes: 21 additions & 3 deletions internal/component/github_release_source_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"errors"
"github.com/pivotal-cf/kiln/internal/component/fakes_internal"
"io"
"log"
"os"
Expand All @@ -13,10 +12,16 @@ import (
"github.com/google/go-github/v40/github"

Ω "github.com/onsi/gomega"

"github.com/pivotal-cf/kiln/internal/component/fakes_internal"
)

func TestGithubReleaseSource_downloadRelease(t *testing.T) {
lock := Lock{Name: "routing", Version: "0.226.0", RemotePath: "https://github.com/cloudfoundry/routing-release/"}
lock := Lock{
Name: "routing",
Version: "0.239.0",
RemotePath: "https://github.com/cloudfoundry/routing-release/releases/download/v0.239.0/routing-0.239.0.tgz",
}

please := Ω.NewWithT(t)
tempDir := t.TempDir()
Expand All @@ -31,7 +36,7 @@ func TestGithubReleaseSource_downloadRelease(t *testing.T) {
downloader.GetReleaseByTagReturnsOnCall(1, &github.RepositoryRelease{
Assets: []*github.ReleaseAsset{
{
Name: ptr("routing-0.226.0.tgz"),
Name: ptr("routing-0.239.0.tgz"),
},
},
}, nil, nil)
Expand All @@ -41,6 +46,19 @@ func TestGithubReleaseSource_downloadRelease(t *testing.T) {
local, err := downloadRelease(context.Background(), tempDir, lock, downloader, logger)
please.Expect(err).NotTo(Ω.HaveOccurred())

{
_, org, repo, tag := downloader.GetReleaseByTagArgsForCall(0)
please.Expect(org).To(Ω.Equal("cloudfoundry"))
please.Expect(repo).To(Ω.Equal("routing-release"))
please.Expect(tag).To(Ω.Equal("0.239.0"))
}
{
_, org, repo, tag := downloader.GetReleaseByTagArgsForCall(1)
please.Expect(org).To(Ω.Equal("cloudfoundry"))
please.Expect(repo).To(Ω.Equal("routing-release"))
please.Expect(tag).To(Ω.Equal("v0.239.0"))
}

please.Expect(local.LocalPath).To(Ω.BeAnExistingFile(), "it finds the created asset file")
please.Expect(local.SHA1).To(Ω.Equal("3a2be7b07a1a19072bf54c95a8c4a3fe0cdb35d4"))
}

0 comments on commit 4ca4fbb

Please sign in to comment.