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

Commit

Permalink
Corrected the test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Himanshu Pandey committed Mar 1, 2019
1 parent 5355db7 commit 0dc11ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
3 changes: 1 addition & 2 deletions cmd/chart-repo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func syncRepo(dbSession datastore.Session, repoName, repoURL string, authorizati

charts := chartsFromIndex(index, r)
if len(charts) == 0 {
errors.New("no charts in repository index")
return nil
return errors.New("no charts in repository index")
}
err = importCharts(dbSession, charts)
if err != nil {
Expand Down
26 changes: 5 additions & 21 deletions cmd/chart-repo/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,6 @@ 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 @@ -603,7 +585,9 @@ func (h *emptyChartRepoHTTPClient) Do(req *http.Request) (*http.Response, error)


func Test_emptyChartRepo(t *testing.T) {
netClient = &badHTTPClient{}
_, err := fetchRepoIndex(repo{URL: "https://my.examplerepo.com"})
assert.ExistsErr(t, err, "failed request")
netClient = &emptyChartRepoHTTPClient{}
m := mock.Mock{}
dbSession := mockstore.NewMockSession(&m)
err := syncRepo(dbSession, "test", repo{URL: "https://my.examplerepo.com"}, "")
assert.ExistsErr(t, err, "Failed Request")
}

0 comments on commit 0dc11ed

Please sign in to comment.