|
|
@ -35,10 +35,11 @@ func TestUpdateCmd(t *testing.T) {
|
|
|
|
var out bytes.Buffer
|
|
|
|
var out bytes.Buffer
|
|
|
|
// Instead of using the HTTP updater, we provide our own for this test.
|
|
|
|
// Instead of using the HTTP updater, we provide our own for this test.
|
|
|
|
// The TestUpdateCharts test verifies the HTTP behavior independently.
|
|
|
|
// The TestUpdateCharts test verifies the HTTP behavior independently.
|
|
|
|
updater := func(repos []*repo.ChartRepository, out io.Writer) {
|
|
|
|
updater := func(repos []*repo.ChartRepository, out io.Writer, failOnRepoUpdateFail bool) error {
|
|
|
|
for _, re := range repos {
|
|
|
|
for _, re := range repos {
|
|
|
|
fmt.Fprintln(out, re.Config.Name)
|
|
|
|
fmt.Fprintln(out, re.Config.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
o := &repoUpdateOptions{
|
|
|
|
o := &repoUpdateOptions{
|
|
|
|
update: updater,
|
|
|
|
update: updater,
|
|
|
@ -59,10 +60,11 @@ func TestUpdateCmdMultiple(t *testing.T) {
|
|
|
|
var out bytes.Buffer
|
|
|
|
var out bytes.Buffer
|
|
|
|
// Instead of using the HTTP updater, we provide our own for this test.
|
|
|
|
// Instead of using the HTTP updater, we provide our own for this test.
|
|
|
|
// The TestUpdateCharts test verifies the HTTP behavior independently.
|
|
|
|
// The TestUpdateCharts test verifies the HTTP behavior independently.
|
|
|
|
updater := func(repos []*repo.ChartRepository, out io.Writer) {
|
|
|
|
updater := func(repos []*repo.ChartRepository, out io.Writer, failOnRepoUpdateFail bool) error {
|
|
|
|
for _, re := range repos {
|
|
|
|
for _, re := range repos {
|
|
|
|
fmt.Fprintln(out, re.Config.Name)
|
|
|
|
fmt.Fprintln(out, re.Config.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
o := &repoUpdateOptions{
|
|
|
|
o := &repoUpdateOptions{
|
|
|
|
update: updater,
|
|
|
|
update: updater,
|
|
|
@ -84,10 +86,11 @@ func TestUpdateCmdInvalid(t *testing.T) {
|
|
|
|
var out bytes.Buffer
|
|
|
|
var out bytes.Buffer
|
|
|
|
// Instead of using the HTTP updater, we provide our own for this test.
|
|
|
|
// Instead of using the HTTP updater, we provide our own for this test.
|
|
|
|
// The TestUpdateCharts test verifies the HTTP behavior independently.
|
|
|
|
// The TestUpdateCharts test verifies the HTTP behavior independently.
|
|
|
|
updater := func(repos []*repo.ChartRepository, out io.Writer) {
|
|
|
|
updater := func(repos []*repo.ChartRepository, out io.Writer, failOnRepoUpdateFail bool) error {
|
|
|
|
for _, re := range repos {
|
|
|
|
for _, re := range repos {
|
|
|
|
fmt.Fprintln(out, re.Config.Name)
|
|
|
|
fmt.Fprintln(out, re.Config.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
o := &repoUpdateOptions{
|
|
|
|
o := &repoUpdateOptions{
|
|
|
|
update: updater,
|
|
|
|
update: updater,
|
|
|
@ -144,7 +147,7 @@ func TestUpdateCharts(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
updateCharts([]*repo.ChartRepository{r}, b)
|
|
|
|
updateCharts([]*repo.ChartRepository{r}, b, false)
|
|
|
|
|
|
|
|
|
|
|
|
got := b.String()
|
|
|
|
got := b.String()
|
|
|
|
if strings.Contains(got, "Unable to get an update") {
|
|
|
|
if strings.Contains(got, "Unable to get an update") {
|
|
|
@ -159,3 +162,79 @@ func TestRepoUpdateFileCompletion(t *testing.T) {
|
|
|
|
checkFileCompletion(t, "repo update", false)
|
|
|
|
checkFileCompletion(t, "repo update", false)
|
|
|
|
checkFileCompletion(t, "repo update repo1", false)
|
|
|
|
checkFileCompletion(t, "repo update repo1", false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestUpdateChartsFail(t *testing.T) {
|
|
|
|
|
|
|
|
defer resetEnv()()
|
|
|
|
|
|
|
|
defer ensure.HelmHome(t)()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ts, err := repotest.NewTempServerWithCleanup(t, "testdata/testserver/*.*")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer ts.Stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var invalidURL = ts.URL() + "55"
|
|
|
|
|
|
|
|
r, err := repo.NewChartRepository(&repo.Entry{
|
|
|
|
|
|
|
|
Name: "charts",
|
|
|
|
|
|
|
|
URL: invalidURL,
|
|
|
|
|
|
|
|
}, getter.All(settings))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
|
|
|
|
if err := updateCharts([]*repo.ChartRepository{r}, b, false); err != nil {
|
|
|
|
|
|
|
|
t.Error("Repo update should not return error if update of repository fails")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
got := b.String()
|
|
|
|
|
|
|
|
if !strings.Contains(got, "Unable to get an update") {
|
|
|
|
|
|
|
|
t.Errorf("Repo should have failed update but instead got: %q", got)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(got, "Update Complete.") {
|
|
|
|
|
|
|
|
t.Error("Update was not successful")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestUpdateChartsFailWithError(t *testing.T) {
|
|
|
|
|
|
|
|
defer resetEnv()()
|
|
|
|
|
|
|
|
defer ensure.HelmHome(t)()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ts, err := repotest.NewTempServerWithCleanup(t, "testdata/testserver/*.*")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer ts.Stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var invalidURL = ts.URL() + "55"
|
|
|
|
|
|
|
|
r, err := repo.NewChartRepository(&repo.Entry{
|
|
|
|
|
|
|
|
Name: "charts",
|
|
|
|
|
|
|
|
URL: invalidURL,
|
|
|
|
|
|
|
|
}, getter.All(settings))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
|
|
|
|
err = updateCharts([]*repo.ChartRepository{r}, b, true)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
t.Error("Repo update should return error because update of repository fails and 'fail-on-repo-update-fail' flag set")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var expectedErr = "Failed to update the following repositories"
|
|
|
|
|
|
|
|
var receivedErr = err.Error()
|
|
|
|
|
|
|
|
if !strings.Contains(receivedErr, expectedErr) {
|
|
|
|
|
|
|
|
t.Errorf("Expected error (%s) but got (%s) instead", expectedErr, receivedErr)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(receivedErr, invalidURL) {
|
|
|
|
|
|
|
|
t.Errorf("Expected invalid URL (%s) in error message but got (%s) instead", invalidURL, receivedErr)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
got := b.String()
|
|
|
|
|
|
|
|
if !strings.Contains(got, "Unable to get an update") {
|
|
|
|
|
|
|
|
t.Errorf("Repo should have failed update but instead got: %q", got)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.Contains(got, "Update Complete.") {
|
|
|
|
|
|
|
|
t.Error("Update was not successful and should return error message because 'fail-on-repo-update-fail' flag set")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|