diff --git a/pkg/chart/testdata/frobnitz-0.0.1.tgz b/pkg/chart/testdata/frobnitz-0.0.1.tgz index 322f46396..fae67e011 100644 Binary files a/pkg/chart/testdata/frobnitz-0.0.1.tgz and b/pkg/chart/testdata/frobnitz-0.0.1.tgz differ diff --git a/pkg/repo/gcs_repo_test.go b/pkg/repo/gcs_repo_test.go index 163d662f5..3f7c01ee4 100644 --- a/pkg/repo/gcs_repo_test.go +++ b/pkg/repo/gcs_repo_test.go @@ -112,7 +112,7 @@ func TestGetChart(t *testing.T) { t.Fatal(err) } - if reflect.DeepEqual(wantFile, haveFile) { + if !reflect.DeepEqual(wantFile, haveFile) { t.Fatalf("retrieved invalid chart\nwant:%#v\nhave:\n%#v\n", wantFile, haveFile) } } diff --git a/pkg/repo/inmem_repo_service.go b/pkg/repo/inmem_repo_service.go index a987dd467..b40368853 100644 --- a/pkg/repo/inmem_repo_service.go +++ b/pkg/repo/inmem_repo_service.go @@ -42,13 +42,13 @@ func NewInmemRepoService() IRepoService { } // List returns the list of all known chart repositories -func (rs *inmemRepoService) List() ([]IRepo, error) { +func (rs *inmemRepoService) List() ([]string, error) { rs.RLock() defer rs.RUnlock() - ret := []IRepo{} + ret := []string{} for _, r := range rs.repositories { - ret = append(ret, r) + ret = append(ret, r.GetName()) } return ret, nil diff --git a/pkg/repo/inmem_repo_service_test.go b/pkg/repo/inmem_repo_service_test.go index 22d8184c8..59c273a2a 100644 --- a/pkg/repo/inmem_repo_service_test.go +++ b/pkg/repo/inmem_repo_service_test.go @@ -32,7 +32,11 @@ func TestService(t *testing.T) { t.Fatalf("unexpected repo count; want: %d, have %d.", 1, len(repos)) } - tr := repos[0] + tr, err := rs.Get(repos[0]) + if err != nil { + t.Fatalf("cannot get repo named %s: %s", repos[0], err) + } + if err := validateRepo(tr, GCSPublicRepoName, GCSPublicRepoURL, "", GCSRepoFormat, GCSRepoType); err != nil { t.Fatal(err) } diff --git a/pkg/repo/repoprovider.go b/pkg/repo/repoprovider.go index 8695c0c3e..5dbe2ee0a 100644 --- a/pkg/repo/repoprovider.go +++ b/pkg/repo/repoprovider.go @@ -33,7 +33,7 @@ import ( type IRepoProvider interface { GetRepoByURL(URL string) (IChartRepo, error) GetRepoByName(repoName string) (IChartRepo, error) - GetChartByReference(reference string) (*chart.Chart, error) + GetChartByReference(reference string) (*chart.Chart, IChartRepo, error) } type repoProvider struct { @@ -157,25 +157,30 @@ func (rp *repoProvider) findRepoByURL(URL string) IChartRepo { // GetChartByReference maps the supplied chart reference into a fully qualified // URL, uses the URL to find the repository it references, queries the repository -// for the chart by URL, and returns the result. -func (rp *repoProvider) GetChartByReference(reference string) (*chart.Chart, error) { +// for the chart by URL, and returns the chart and the repository that backs it. +func (rp *repoProvider) GetChartByReference(reference string) (*chart.Chart, IChartRepo, error) { l, err := ParseGCSChartReference(reference) if err != nil { - return nil, err + return nil, nil, err } URL, err := l.Long(true) if err != nil { - return nil, fmt.Errorf("invalid reference %s: %s", reference, err) + return nil, nil, fmt.Errorf("invalid reference %s: %s", reference, err) } r, err := rp.GetRepoByURL(URL) if err != nil { - return nil, err + return nil, nil, err } name := fmt.Sprintf("%s-%s.tgz", l.Name, l.Version) - return r.GetChart(name) + c, err := r.GetChart(name) + if err != nil { + return nil, nil, err + } + + return c, r, nil } // GCSRepoProvider is a factory for GCS IRepo instances. diff --git a/pkg/repo/repoprovider_test.go b/pkg/repo/repoprovider_test.go index 86533dcc8..ff554ab1c 100644 --- a/pkg/repo/repoprovider_test.go +++ b/pkg/repo/repoprovider_test.go @@ -99,14 +99,14 @@ func TestGetChartByReferenceWithValidReferences(t *testing.T) { for _, vcr := range ValidChartReferences { t.Logf("getting chart by reference: %s", vcr) - tc, err := rp.GetChartByReference(vcr) + tc, _, err := rp.GetChartByReference(vcr) if err != nil { t.Error(err) continue } haveFile := tc.Chartfile() - if reflect.DeepEqual(wantFile, haveFile) { + if !reflect.DeepEqual(wantFile, haveFile) { t.Fatalf("retrieved invalid chart\nwant:%#v\nhave:\n%#v\n", wantFile, haveFile) } } @@ -130,7 +130,7 @@ func getTestRepoProvider(t *testing.T) IRepoProvider { func TestGetChartByReferenceWithInvalidReferences(t *testing.T) { rp := NewRepoProvider(nil, nil, nil) for _, icr := range InvalidChartReferences { - _, err := rp.GetChartByReference(icr) + _, _, err := rp.GetChartByReference(icr) if err == nil { t.Fatalf("found chart using invalid reference: %s", icr) } diff --git a/pkg/repo/types.go b/pkg/repo/types.go index fa13bf474..d58e482db 100644 --- a/pkg/repo/types.go +++ b/pkg/repo/types.go @@ -118,7 +118,7 @@ type IStorageRepo interface { // repository based operations, such as search and chart reference resolution. type IRepoService interface { // List returns the list of all known chart repositories - List() ([]IRepo, error) + List() ([]string, error) // Create adds a known repository to the list Create(repository IRepo) error // Get returns the repository with the given name