@ -44,7 +44,7 @@ func TestRepoRemove(t *testing.T) {
b := bytes . NewBuffer ( nil )
b := bytes . NewBuffer ( nil )
rmOpts := repoRemoveOptions {
rmOpts := repoRemoveOptions {
name : testRepoName ,
name s: [ ] string { testRepoName } ,
repoFile : repoFile ,
repoFile : repoFile ,
repoCache : rootDir ,
repoCache : rootDir ,
}
}
@ -62,14 +62,9 @@ func TestRepoRemove(t *testing.T) {
t . Error ( err )
t . Error ( err )
}
}
idx := filepath . Join ( rootDir , helmpath . CacheIndexFile ( testRepoName ) )
cacheIndexFile , cacheChartsFile := createCacheFiles ( rootDir , testRepoName )
mf , _ := os . Create ( idx )
mf . Close ( )
idx2 := filepath . Join ( rootDir , helmpath . CacheChartsFile ( testRepoName ) )
mf , _ = os . Create ( idx2 )
mf . Close ( )
// Reset the buffer before running repo remove
b . Reset ( )
b . Reset ( )
if err := rmOpts . run ( b ) ; err != nil {
if err := rmOpts . run ( b ) ; err != nil {
@ -79,13 +74,7 @@ func TestRepoRemove(t *testing.T) {
t . Errorf ( "Unexpected output: %s" , b . String ( ) )
t . Errorf ( "Unexpected output: %s" , b . String ( ) )
}
}
if _ , err := os . Stat ( idx ) ; err == nil {
testCacheFiles ( t , cacheIndexFile , cacheChartsFile , testRepoName )
t . Errorf ( "Error cache index file was not removed for repository %s" , testRepoName )
}
if _ , err := os . Stat ( idx2 ) ; err == nil {
t . Errorf ( "Error cache chart file was not removed for repository %s" , testRepoName )
}
f , err := repo . LoadFile ( repoFile )
f , err := repo . LoadFile ( repoFile )
if err != nil {
if err != nil {
@ -95,4 +84,79 @@ func TestRepoRemove(t *testing.T) {
if f . Has ( testRepoName ) {
if f . Has ( testRepoName ) {
t . Errorf ( "%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
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 )
}
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 )
}
}
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 )
}
}
}