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

Commit

Permalink
Added Test case for Empty Charts
Browse files Browse the repository at this point in the history
Signed-off-by: Himanshu Pandey <[email protected]>
  • Loading branch information
Himanshu Pandey committed Mar 1, 2019
1 parent a005c40 commit de90907
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
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:
2 changes: 1 addition & 1 deletion cmd/chart-repo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func syncRepo(dbSession datastore.Session, repoName, repoURL string, authorizati

charts := chartsFromIndex(index, r)
if len(charts) == 0 {
log.Fatal("No charts are found")
errors.New("no charts in repository index")
return nil
}
err = importCharts(dbSession, charts)
Expand Down
41 changes: 41 additions & 0 deletions cmd/chart-repo/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ func (h *goodHTTPClient) Do(req *http.Request) (*http.Response, error) {
return w.Result(), nil
}

type chartHTTPClient struct{}

func (h *chartHTTPClient) Do(req *http.Request) (*http.Response, error){
w := httptest.NewRecorder()
// Don't accept trailing slashes
if strings.HasPrefix(req.URL.Path, "//") {
w.WriteHeader(500)
}
// If subpath repo URL test, check that index.yaml is correctly added to the
// subpath
if req.URL.Host == "subpath.test" && req.URL.Path != "/subpath/index.yaml" {
w.WriteHeader(500)
}

w.Write(nil)
return w.Result(), nil
}

type authenticatedHTTPClient struct{}

func (h *authenticatedHTTPClient) Do(req *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -570,3 +588,26 @@ h251U/Daz6NiQBM9AxyAw6EHm8XAZBvCuebfzyrT
t.Error(err)
}
}

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

type chartHTTPClient struct{}


func (h *emptyChartRepoHTTPClient) Do(req *http.Request) (*http.Response, error){
w := httptest.NewRecorder()
// Don't accept trailing slashes
if strings.HasPrefix(req.URL.Path) {
w.WriteHeader(500)
}
w.Write([]byte(emptyRepoIndexYAML))
return w.Result(), nil
}


func Test_syncURLInvalidity(t *testing.T) {
netClient = &badHTTPClient{}
_, err := fetchRepoIndex(repo{URL: "https://my.examplerepo.com"})
assert.ExistsErr(t, err, "failed request")
}

0 comments on commit de90907

Please sign in to comment.