|
|
|
@ -44,7 +44,7 @@ func TestRepoRemove(t *testing.T) {
|
|
|
|
|
b := bytes.NewBuffer(nil)
|
|
|
|
|
|
|
|
|
|
rmOpts := repoRemoveOptions{
|
|
|
|
|
name: testRepoName,
|
|
|
|
|
names: []string{testRepoName},
|
|
|
|
|
repoFile: repoFile,
|
|
|
|
|
repoCache: rootDir,
|
|
|
|
|
}
|
|
|
|
@ -62,14 +62,9 @@ func TestRepoRemove(t *testing.T) {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
idx := filepath.Join(rootDir, helmpath.CacheIndexFile(testRepoName))
|
|
|
|
|
mf, _ := os.Create(idx)
|
|
|
|
|
mf.Close()
|
|
|
|
|
|
|
|
|
|
idx2 := filepath.Join(rootDir, helmpath.CacheChartsFile(testRepoName))
|
|
|
|
|
mf, _ = os.Create(idx2)
|
|
|
|
|
mf.Close()
|
|
|
|
|
cacheIndexFile, cacheChartsFile := createCacheFiles(rootDir, testRepoName)
|
|
|
|
|
|
|
|
|
|
// Reset the buffer before running repo remove
|
|
|
|
|
b.Reset()
|
|
|
|
|
|
|
|
|
|
if err := rmOpts.run(b); err != nil {
|
|
|
|
@ -79,20 +74,89 @@ func TestRepoRemove(t *testing.T) {
|
|
|
|
|
t.Errorf("Unexpected output: %s", b.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := os.Stat(idx); err == nil {
|
|
|
|
|
t.Errorf("Error cache index file was not removed for repository %s", testRepoName)
|
|
|
|
|
testCacheFiles(t, cacheIndexFile, cacheChartsFile, testRepoName)
|
|
|
|
|
|
|
|
|
|
f, err := repo.LoadFile(repoFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if f.Has(testRepoName) {
|
|
|
|
|
t.Errorf("%s was not successfully removed from repositories list", testRepoName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test removal of multiple repos in one go
|
|
|
|
|
var testRepoNames = []string{"foo", "bar", "baz"}
|
|
|
|
|
cacheFiles := make(map[string][]string, len(testRepoNames))
|
|
|
|
|
|
|
|
|
|
// Add test repos
|
|
|
|
|
for _, repoName := range testRepoNames {
|
|
|
|
|
o := &repoAddOptions{
|
|
|
|
|
name: repoName,
|
|
|
|
|
url: ts.URL(),
|
|
|
|
|
repoFile: repoFile,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := o.run(os.Stderr); err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := os.Stat(idx2); err == nil {
|
|
|
|
|
t.Errorf("Error cache chart file was not removed for repository %s", testRepoName)
|
|
|
|
|
cacheIndex, cacheChart := createCacheFiles(rootDir, repoName)
|
|
|
|
|
cacheFiles[repoName] = []string{cacheIndex, cacheChart}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create repo remove command
|
|
|
|
|
multiRmOpts := repoRemoveOptions{
|
|
|
|
|
names: testRepoNames,
|
|
|
|
|
repoFile: repoFile,
|
|
|
|
|
repoCache: rootDir,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reset the buffer before running repo remove
|
|
|
|
|
b.Reset()
|
|
|
|
|
|
|
|
|
|
// Run repo remove command
|
|
|
|
|
if err := multiRmOpts.run(b); err != nil {
|
|
|
|
|
t.Errorf("Error removing list of repos from repositories: %q", testRepoNames)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that stuff were removed
|
|
|
|
|
if !strings.Contains(b.String(), "has been removed") {
|
|
|
|
|
t.Errorf("Unexpected output: %s", b.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, repoName := range testRepoNames {
|
|
|
|
|
f, err := repo.LoadFile(repoFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
if f.Has(repoName) {
|
|
|
|
|
t.Errorf("%s was not successfully removed from repositories list", repoName)
|
|
|
|
|
}
|
|
|
|
|
cacheIndex := cacheFiles[repoName][0]
|
|
|
|
|
cacheChart := cacheFiles[repoName][1]
|
|
|
|
|
testCacheFiles(t, cacheIndex, cacheChart, repoName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if f.Has(testRepoName) {
|
|
|
|
|
t.Errorf("%s was not successfully removed from repositories list", testRepoName)
|
|
|
|
|
func createCacheFiles(rootDir string, repoName string) (cacheIndexFile string, cacheChartsFile string) {
|
|
|
|
|
cacheIndexFile = filepath.Join(rootDir, helmpath.CacheIndexFile(repoName))
|
|
|
|
|
mf, _ := os.Create(cacheIndexFile)
|
|
|
|
|
mf.Close()
|
|
|
|
|
|
|
|
|
|
cacheChartsFile = filepath.Join(rootDir, helmpath.CacheChartsFile(repoName))
|
|
|
|
|
mf, _ = os.Create(cacheChartsFile)
|
|
|
|
|
mf.Close()
|
|
|
|
|
|
|
|
|
|
return cacheIndexFile, cacheChartsFile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testCacheFiles(t *testing.T, cacheIndexFile string, cacheChartsFile string, repoName string) {
|
|
|
|
|
if _, err := os.Stat(cacheIndexFile); err == nil {
|
|
|
|
|
t.Errorf("Error cache index file was not removed for repository %s", repoName)
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(cacheChartsFile); err == nil {
|
|
|
|
|
t.Errorf("Error cache chart file was not removed for repository %s", repoName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|