|
|
|
@ -21,9 +21,11 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v4/pkg/helmpath"
|
|
|
|
"helm.sh/helm/v4/pkg/helmpath"
|
|
|
|
"helm.sh/helm/v4/pkg/repo/v1"
|
|
|
|
"helm.sh/helm/v4/pkg/repo/v1"
|
|
|
|
"helm.sh/helm/v4/pkg/repo/v1/repotest"
|
|
|
|
"helm.sh/helm/v4/pkg/repo/v1/repotest"
|
|
|
|
@ -49,41 +51,29 @@ func TestRepoRemove(t *testing.T) {
|
|
|
|
repoCache: rootDir,
|
|
|
|
repoCache: rootDir,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := rmOpts.run(os.Stderr); err == nil {
|
|
|
|
require.Errorf(t, rmOpts.run(os.Stderr), "Expected error removing %s, but did not get one.", testRepoName)
|
|
|
|
t.Errorf("Expected error removing %s, but did not get one.", testRepoName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
o := &repoAddOptions{
|
|
|
|
o := &repoAddOptions{
|
|
|
|
name: testRepoName,
|
|
|
|
name: testRepoName,
|
|
|
|
url: ts.URL(),
|
|
|
|
url: ts.URL(),
|
|
|
|
repoFile: repoFile,
|
|
|
|
repoFile: repoFile,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := o.run(os.Stderr); err != nil {
|
|
|
|
require.NoError(t, o.run(os.Stderr))
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cacheIndexFile, cacheChartsFile := createCacheFiles(rootDir, testRepoName)
|
|
|
|
cacheIndexFile, cacheChartsFile := createCacheFiles(rootDir, testRepoName)
|
|
|
|
|
|
|
|
|
|
|
|
// Reset the buffer before running repo remove
|
|
|
|
// Reset the buffer before running repo remove
|
|
|
|
b.Reset()
|
|
|
|
b.Reset()
|
|
|
|
|
|
|
|
|
|
|
|
if err := rmOpts.run(b); err != nil {
|
|
|
|
require.NoErrorf(t, rmOpts.run(b), "Error removing %s from repositories", testRepoName)
|
|
|
|
t.Errorf("Error removing %s from repositories", testRepoName)
|
|
|
|
assert.Contains(t, b.String(), "has been removed", "Unexpected output: %s", b.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(b.String(), "has been removed") {
|
|
|
|
|
|
|
|
t.Errorf("Unexpected output: %s", b.String())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testCacheFiles(t, cacheIndexFile, cacheChartsFile, testRepoName)
|
|
|
|
testCacheFiles(t, cacheIndexFile, cacheChartsFile, testRepoName)
|
|
|
|
|
|
|
|
|
|
|
|
f, err := repo.LoadFile(repoFile)
|
|
|
|
f, err := repo.LoadFile(repoFile)
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if f.Has(testRepoName) {
|
|
|
|
assert.Falsef(t, f.Has(testRepoName), "%s was not successfully removed from repositories list", testRepoName)
|
|
|
|
t.Errorf("%s was not successfully removed from repositories list", testRepoName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test removal of multiple repos in one go
|
|
|
|
// Test removal of multiple repos in one go
|
|
|
|
var testRepoNames = []string{"foo", "bar", "baz"}
|
|
|
|
var testRepoNames = []string{"foo", "bar", "baz"}
|
|
|
|
@ -97,9 +87,7 @@ func TestRepoRemove(t *testing.T) {
|
|
|
|
repoFile: repoFile,
|
|
|
|
repoFile: repoFile,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := o.run(os.Stderr); err != nil {
|
|
|
|
require.NoError(t, o.run(os.Stderr))
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cacheIndex, cacheChart := createCacheFiles(rootDir, repoName)
|
|
|
|
cacheIndex, cacheChart := createCacheFiles(rootDir, repoName)
|
|
|
|
cacheFiles[repoName] = []string{cacheIndex, cacheChart}
|
|
|
|
cacheFiles[repoName] = []string{cacheIndex, cacheChart}
|
|
|
|
@ -116,23 +104,15 @@ func TestRepoRemove(t *testing.T) {
|
|
|
|
b.Reset()
|
|
|
|
b.Reset()
|
|
|
|
|
|
|
|
|
|
|
|
// Run repo remove command
|
|
|
|
// Run repo remove command
|
|
|
|
if err := multiRmOpts.run(b); err != nil {
|
|
|
|
require.NoErrorf(t, multiRmOpts.run(b), "Error removing list of repos from repositories: %q", testRepoNames)
|
|
|
|
t.Errorf("Error removing list of repos from repositories: %q", testRepoNames)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check that stuff were removed
|
|
|
|
// Check that stuff were removed
|
|
|
|
if !strings.Contains(b.String(), "has been removed") {
|
|
|
|
assert.Contains(t, b.String(), "has been removed", "Unexpected output: %s", b.String())
|
|
|
|
t.Errorf("Unexpected output: %s", b.String())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, repoName := range testRepoNames {
|
|
|
|
for _, repoName := range testRepoNames {
|
|
|
|
f, err := repo.LoadFile(repoFile)
|
|
|
|
f, err := repo.LoadFile(repoFile)
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Error(err)
|
|
|
|
assert.Falsef(t, f.Has(repoName), "%s was not successfully removed from repositories list", repoName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Has(repoName) {
|
|
|
|
|
|
|
|
t.Errorf("%s was not successfully removed from repositories list", repoName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cacheIndex := cacheFiles[repoName][0]
|
|
|
|
cacheIndex := cacheFiles[repoName][0]
|
|
|
|
cacheChart := cacheFiles[repoName][1]
|
|
|
|
cacheChart := cacheFiles[repoName][1]
|
|
|
|
testCacheFiles(t, cacheIndex, cacheChart, repoName)
|
|
|
|
testCacheFiles(t, cacheIndex, cacheChart, repoName)
|
|
|
|
@ -153,12 +133,10 @@ func createCacheFiles(rootDir string, repoName string) (cacheIndexFile string, c
|
|
|
|
|
|
|
|
|
|
|
|
func testCacheFiles(t *testing.T, cacheIndexFile string, cacheChartsFile string, repoName string) {
|
|
|
|
func testCacheFiles(t *testing.T, cacheIndexFile string, cacheChartsFile string, repoName string) {
|
|
|
|
t.Helper()
|
|
|
|
t.Helper()
|
|
|
|
if _, err := os.Stat(cacheIndexFile); err == nil {
|
|
|
|
_, err := os.Stat(cacheIndexFile)
|
|
|
|
t.Errorf("Error cache index file was not removed for repository %s", repoName)
|
|
|
|
require.Errorf(t, err, "Error cache index file was not removed for repository %s", repoName)
|
|
|
|
}
|
|
|
|
_, err = os.Stat(cacheChartsFile)
|
|
|
|
if _, err := os.Stat(cacheChartsFile); err == nil {
|
|
|
|
assert.Errorf(t, err, "Error cache chart file was not removed for repository %s", repoName)
|
|
|
|
t.Errorf("Error cache chart file was not removed for repository %s", repoName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestRepoRemoveCompletion(t *testing.T) {
|
|
|
|
func TestRepoRemoveCompletion(t *testing.T) {
|
|
|
|
@ -183,9 +161,7 @@ func TestRepoRemoveCompletion(t *testing.T) {
|
|
|
|
repoFile: repoFile,
|
|
|
|
repoFile: repoFile,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := o.run(os.Stderr); err != nil {
|
|
|
|
require.NoError(t, o.run(os.Stderr))
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
repoSetup := fmt.Sprintf("--repository-config %s --repository-cache %s", repoFile, repoCache)
|
|
|
|
repoSetup := fmt.Sprintf("--repository-config %s --repository-cache %s", repoFile, repoCache)
|
|
|
|
|