Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Added check for empty charts in chart-repo (#604)
Browse files Browse the repository at this point in the history
* Signed-off-by: Himanshu Pandey <[email protected]>

Added check for empty charts

* Added Test case for Empty Charts

Signed-off-by: Himanshu Pandey <[email protected]>

* Corrected the test case

Signed-off-by: Himanshu Pandey <[email protected]>
  • Loading branch information
Himanshu Pandey authored and prydonius committed Mar 7, 2019
1 parent c2178b1 commit a5df290
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/chart-repo/testdata/empty-repo-index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
entries:
3 changes: 3 additions & 0 deletions cmd/chart-repo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func syncRepo(dbSession datastore.Session, repoName, repoURL string, authorizati
}

charts := chartsFromIndex(index, r)
if len(charts) == 0 {
return errors.New("no charts in repository index")
}
err = importCharts(dbSession, charts)
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions cmd/chart-repo/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,22 @@ h251U/Daz6NiQBM9AxyAw6EHm8XAZBvCuebfzyrT
t.Error(err)
}
}

var emptyRepoIndexYAMLBytes, _ = ioutil.ReadFile("testdata/empty-repo-index.yaml")
var emptyRepoIndexYAML = string(emptyRepoIndexYAMLBytes)

type emptyChartRepoHTTPClient struct{}

func (h *emptyChartRepoHTTPClient) Do(req *http.Request) (*http.Response, error) {
w := httptest.NewRecorder()
w.Write([]byte(emptyRepoIndexYAML))
return w.Result(), nil
}

func Test_emptyChartRepo(t *testing.T) {
netClient = &emptyChartRepoHTTPClient{}
m := mock.Mock{}
dbSession := mockstore.NewMockSession(&m)
err := syncRepo(dbSession, "testRepo", "https://my.examplerepo.com", "")
assert.ExistsErr(t, err, "Failed Request")
}

0 comments on commit a5df290

Please sign in to comment.