github.com/strongmonkey/helm@v2.7.2+incompatible/cmd/helm/repo_remove_test.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "bytes" 21 "os" 22 "strings" 23 "testing" 24 25 "k8s.io/helm/pkg/helm/helmpath" 26 "k8s.io/helm/pkg/repo" 27 "k8s.io/helm/pkg/repo/repotest" 28 ) 29 30 func TestRepoRemove(t *testing.T) { 31 ts, thome, err := repotest.NewTempServer("testdata/testserver/*.*") 32 if err != nil { 33 t.Fatal(err) 34 } 35 36 hh := helmpath.Home(thome) 37 cleanup := resetEnv() 38 defer func() { 39 ts.Stop() 40 os.Remove(thome.String()) 41 cleanup() 42 }() 43 if err := ensureTestHome(hh, t); err != nil { 44 t.Fatal(err) 45 } 46 47 settings.Home = thome 48 49 b := bytes.NewBuffer(nil) 50 51 if err := removeRepoLine(b, testName, hh); err == nil { 52 t.Errorf("Expected error removing %s, but did not get one.", testName) 53 } 54 if err := addRepository(testName, ts.URL(), hh, "", "", "", true); err != nil { 55 t.Error(err) 56 } 57 58 mf, _ := os.Create(hh.CacheIndex(testName)) 59 mf.Close() 60 61 b.Reset() 62 if err := removeRepoLine(b, testName, hh); err != nil { 63 t.Errorf("Error removing %s from repositories", testName) 64 } 65 if !strings.Contains(b.String(), "has been removed") { 66 t.Errorf("Unexpected output: %s", b.String()) 67 } 68 69 if _, err := os.Stat(hh.CacheIndex(testName)); err == nil { 70 t.Errorf("Error cache file was not removed for repository %s", testName) 71 } 72 73 f, err := repo.LoadRepositoriesFile(hh.RepositoryFile()) 74 if err != nil { 75 t.Error(err) 76 } 77 78 if f.Has(testName) { 79 t.Errorf("%s was not successfully removed from repositories list", testName) 80 } 81 }