(t *testing.T)
| 30 | ) |
| 31 | |
| 32 | func TestRepoRemove(t *testing.T) { |
| 33 | ts := repotest.NewTempServer( |
| 34 | t, |
| 35 | repotest.WithChartSourceGlob("testdata/testserver/*.*"), |
| 36 | ) |
| 37 | defer ts.Stop() |
| 38 | |
| 39 | rootDir := t.TempDir() |
| 40 | repoFile := filepath.Join(rootDir, "repositories.yaml") |
| 41 | |
| 42 | const testRepoName = "test-name" |
| 43 | |
| 44 | b := bytes.NewBuffer(nil) |
| 45 | |
| 46 | rmOpts := repoRemoveOptions{ |
| 47 | names: []string{testRepoName}, |
| 48 | repoFile: repoFile, |
| 49 | repoCache: rootDir, |
| 50 | } |
| 51 | |
| 52 | if err := rmOpts.run(os.Stderr); err == nil { |
| 53 | t.Errorf("Expected error removing %s, but did not get one.", testRepoName) |
| 54 | } |
| 55 | o := &repoAddOptions{ |
| 56 | name: testRepoName, |
| 57 | url: ts.URL(), |
| 58 | repoFile: repoFile, |
| 59 | } |
| 60 | |
| 61 | if err := o.run(os.Stderr); err != nil { |
| 62 | t.Error(err) |
| 63 | } |
| 64 | |
| 65 | cacheIndexFile, cacheChartsFile := createCacheFiles(rootDir, testRepoName) |
| 66 | |
| 67 | // Reset the buffer before running repo remove |
| 68 | b.Reset() |
| 69 | |
| 70 | if err := rmOpts.run(b); err != nil { |
| 71 | t.Errorf("Error removing %s from repositories", testRepoName) |
| 72 | } |
| 73 | if !strings.Contains(b.String(), "has been removed") { |
| 74 | t.Errorf("Unexpected output: %s", b.String()) |
| 75 | } |
| 76 | |
| 77 | testCacheFiles(t, cacheIndexFile, cacheChartsFile, testRepoName) |
| 78 | |
| 79 | f, err := repo.LoadFile(repoFile) |
| 80 | if err != nil { |
| 81 | t.Error(err) |
| 82 | } |
| 83 | |
| 84 | if f.Has(testRepoName) { |
| 85 | t.Errorf("%s was not successfully removed from repositories list", testRepoName) |
| 86 | } |
| 87 | |
| 88 | // Test removal of multiple repos in one go |
| 89 | var testRepoNames = []string{"foo", "bar", "baz"} |
nothing calls this directly
no test coverage detected
searching dependent graphs…