ref(pkg/repo): rename RepoFile to File

To resolve the linter warning: name start with package name.

Signed-off-by: Roc <roc@imroc.io>
pull/4946/head
roc 6 years ago
parent b290247efa
commit 212d326a34

@ -130,7 +130,7 @@ func ensureTestHome(t *testing.T, home helmpath.Home) {
repoFile := home.RepositoryFile()
if _, err := os.Stat(repoFile); err != nil {
rf := repo.NewRepoFile()
rf := repo.NewFile()
rf.Add(&repo.Entry{
Name: "charts",
URL: "http://example.com/foo",
@ -140,7 +140,7 @@ func ensureTestHome(t *testing.T, home helmpath.Home) {
t.Fatal(err)
}
}
if r, err := repo.LoadRepositoriesFile(repoFile); err == repo.ErrRepoOutOfDate {
if r, err := repo.LoadFile(repoFile); err == repo.ErrRepoOutOfDate {
if err := r.WriteFile(repoFile, 0644); err != nil {
t.Fatal(err)
}

@ -113,7 +113,7 @@ func ensureDefaultRepos(home helmpath.Home, out io.Writer, skipRefresh bool, url
repoFile := home.RepositoryFile()
if fi, err := os.Stat(repoFile); err != nil {
fmt.Fprintf(out, "Creating %s \n", repoFile)
f := repo.NewRepoFile()
f := repo.NewFile()
sr, err := initRepo(url, home.CacheIndex(stableRepository), out, skipRefresh, home)
if err != nil {
return err
@ -154,7 +154,7 @@ func initRepo(url, cacheFile string, out io.Writer, skipRefresh bool, home helmp
}
func ensureRepoFileFormat(file string, out io.Writer) error {
r, err := repo.LoadRepositoriesFile(file)
r, err := repo.LoadFile(file)
if err == repo.ErrRepoOutOfDate {
fmt.Fprintln(out, "Updating repository file format...")
if err := r.WriteFile(file, 0644); err != nil {

@ -78,7 +78,7 @@ func (o *repoAddOptions) run(out io.Writer) error {
}
func addRepository(name, url, username, password string, home helmpath.Home, certFile, keyFile, caFile string, noUpdate bool) error {
f, err := repo.LoadRepositoriesFile(home.RepositoryFile())
f, err := repo.LoadFile(home.RepositoryFile())
if err != nil {
return err
}

@ -70,7 +70,7 @@ func TestRepoAdd(t *testing.T) {
t.Error(err)
}
f, err := repo.LoadRepositoriesFile(hh.RepositoryFile())
f, err := repo.LoadFile(hh.RepositoryFile())
if err != nil {
t.Error(err)
}

@ -50,7 +50,7 @@ func newRepoListCmd(out io.Writer) *cobra.Command {
}
func (o *repoListOptions) run(out io.Writer) error {
f, err := repo.LoadRepositoriesFile(o.home.RepositoryFile())
f, err := repo.LoadFile(o.home.RepositoryFile())
if err != nil {
return err
}

@ -59,7 +59,7 @@ func (r *repoRemoveOptions) run(out io.Writer) error {
func removeRepoLine(out io.Writer, name string, home helmpath.Home) error {
repoFile := home.RepositoryFile()
r, err := repo.LoadRepositoriesFile(repoFile)
r, err := repo.LoadFile(repoFile)
if err != nil {
return err
}

@ -66,7 +66,7 @@ func TestRepoRemove(t *testing.T) {
t.Errorf("Error cache file was not removed for repository %s", testRepoName)
}
f, err := repo.LoadRepositoriesFile(hh.RepositoryFile())
f, err := repo.LoadFile(hh.RepositoryFile())
if err != nil {
t.Error(err)
}

@ -63,7 +63,7 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command {
}
func (o *repoUpdateOptions) run(out io.Writer) error {
f, err := repo.LoadRepositoriesFile(o.home.RepositoryFile())
f, err := repo.LoadFile(o.home.RepositoryFile())
if err != nil {
return err
}

@ -141,7 +141,7 @@ func (o *searchOptions) formatSearchResults(res []*search.Result) string {
func (o *searchOptions) buildIndex(out io.Writer) (*search.Index, error) {
// Load the repositories.yaml
rf, err := repo.LoadRepositoriesFile(o.helmhome.RepositoryFile())
rf, err := repo.LoadFile(o.helmhome.RepositoryFile())
if err != nil {
return nil, err
}

@ -159,7 +159,7 @@ func (c *ChartDownloader) ResolveChartVersionAndGetRepo(ref, version string) (*u
return nil, nil, nil, errors.Errorf("invalid chart URL format: %s", ref)
}
rf, err := repo.LoadRepositoriesFile(c.HelmHome.RepositoryFile())
rf, err := repo.LoadFile(c.HelmHome.RepositoryFile())
if err != nil {
return u, nil, nil, err
}
@ -338,7 +338,7 @@ func pickChartRepositoryConfigByName(name string, cfgs []*repo.Entry) (*repo.Ent
// The same URL can technically exist in two or more repositories. This algorithm
// will return the first one it finds. Order is determined by the order of repositories
// in the repositories.yaml file.
func (c *ChartDownloader) scanReposForURL(u string, rf *repo.RepoFile) (*repo.Entry, error) {
func (c *ChartDownloader) scanReposForURL(u string, rf *repo.File) (*repo.Entry, error) {
// FIXME: This is far from optimal. Larger installations and index files will
// incur a performance hit for this type of scanning.
for _, rc := range rf.Repositories {

@ -293,7 +293,7 @@ func TestScanReposForURL(t *testing.T) {
}
u := "http://example.com/alpine-0.2.0.tgz"
rf, err := repo.LoadRepositoriesFile(c.HelmHome.RepositoryFile())
rf, err := repo.LoadFile(c.HelmHome.RepositoryFile())
if err != nil {
t.Fatal(err)
}

@ -320,7 +320,7 @@ func (m *Manager) safeDeleteDep(name, dir string) error {
// hasAllRepos ensures that all of the referenced deps are in the local repo cache.
func (m *Manager) hasAllRepos(deps []*chart.Dependency) error {
rf, err := repo.LoadRepositoriesFile(m.HelmHome.RepositoryFile())
rf, err := repo.LoadFile(m.HelmHome.RepositoryFile())
if err != nil {
return err
}
@ -354,7 +354,7 @@ Loop:
// getRepoNames returns the repo names of the referenced deps which can be used to fetch the cahced index file.
func (m *Manager) getRepoNames(deps []*chart.Dependency) (map[string]string, error) {
rf, err := repo.LoadRepositoriesFile(m.HelmHome.RepositoryFile())
rf, err := repo.LoadFile(m.HelmHome.RepositoryFile())
if err != nil {
return nil, err
}
@ -421,7 +421,7 @@ repository, use "https://kubernetes-charts.storage.googleapis.com/" or "@stable"
// UpdateRepositories updates all of the local repos to the latest.
func (m *Manager) UpdateRepositories() error {
rf, err := repo.LoadRepositoriesFile(m.HelmHome.RepositoryFile())
rf, err := repo.LoadFile(m.HelmHome.RepositoryFile())
if err != nil {
return err
}
@ -561,7 +561,7 @@ func (m *Manager) loadChartRepositories() (map[string]*repo.ChartRepository, err
repoyaml := m.HelmHome.RepositoryFile()
// Load repositories.yaml file
rf, err := repo.LoadRepositoriesFile(repoyaml)
rf, err := repo.LoadFile(repoyaml)
if err != nil {
return indices, errors.Wrapf(err, "failed to load %s", repoyaml)
}

@ -30,30 +30,29 @@ import (
// is fixable.
var ErrRepoOutOfDate = errors.New("repository file is out of date")
// RepoFile represents the repositories.yaml file in $HELM_HOME
// TODO: change type name to File in Helm 3 to resolve linter warning
type RepoFile struct { // nolint
// File represents the repositories.yaml file in $HELM_HOME
type File struct {
APIVersion string `json:"apiVersion"`
Generated time.Time `json:"generated"`
Repositories []*Entry `json:"repositories"`
}
// NewRepoFile generates an empty repositories file.
// NewFile generates an empty repositories file.
//
// Generated and APIVersion are automatically set.
func NewRepoFile() *RepoFile {
return &RepoFile{
func NewFile() *File {
return &File{
APIVersion: APIVersionV1,
Generated: time.Now(),
Repositories: []*Entry{},
}
}
// LoadRepositoriesFile takes a file at the given path and returns a RepoFile object
// LoadFile takes a file at the given path and returns a File object
//
// If this returns ErrRepoOutOfDate, it also returns a recovered RepoFile that
// If this returns ErrRepoOutOfDate, it also returns a recovered File that
// can be saved as a replacement to the out of date file.
func LoadRepositoriesFile(path string) (*RepoFile, error) {
func LoadFile(path string) (*File, error) {
b, err := ioutil.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
@ -62,7 +61,7 @@ func LoadRepositoriesFile(path string) (*RepoFile, error) {
return nil, err
}
r := &RepoFile{}
r := &File{}
err = yaml.Unmarshal(b, r)
if err != nil {
return nil, err
@ -74,7 +73,7 @@ func LoadRepositoriesFile(path string) (*RepoFile, error) {
if err = yaml.Unmarshal(b, &m); err != nil {
return nil, err
}
r := NewRepoFile()
r := NewFile()
for k, v := range m {
r.Add(&Entry{
Name: k,
@ -89,13 +88,13 @@ func LoadRepositoriesFile(path string) (*RepoFile, error) {
}
// Add adds one or more repo entries to a repo file.
func (r *RepoFile) Add(re ...*Entry) {
func (r *File) Add(re ...*Entry) {
r.Repositories = append(r.Repositories, re...)
}
// Update attempts to replace one or more repo entries in a repo file. If an
// entry with the same name doesn't exist in the repo file it will add it.
func (r *RepoFile) Update(re ...*Entry) {
func (r *File) Update(re ...*Entry) {
for _, target := range re {
found := false
for j, repo := range r.Repositories {
@ -112,7 +111,7 @@ func (r *RepoFile) Update(re ...*Entry) {
}
// Has returns true if the given name is already a repository name.
func (r *RepoFile) Has(name string) bool {
func (r *File) Has(name string) bool {
for _, rf := range r.Repositories {
if rf.Name == name {
return true
@ -122,7 +121,7 @@ func (r *RepoFile) Has(name string) bool {
}
// Remove removes the entry from the list of repositories.
func (r *RepoFile) Remove(name string) bool {
func (r *File) Remove(name string) bool {
cp := []*Entry{}
found := false
for _, rf := range r.Repositories {
@ -137,7 +136,7 @@ func (r *RepoFile) Remove(name string) bool {
}
// WriteFile writes a repositories file to the given path.
func (r *RepoFile) WriteFile(path string, perm os.FileMode) error {
func (r *File) WriteFile(path string, perm os.FileMode) error {
data, err := yaml.Marshal(r)
if err != nil {
return err

@ -23,8 +23,8 @@ import "strings"
const testRepositoriesFile = "testdata/repositories.yaml"
func TestRepoFile(t *testing.T) {
rf := NewRepoFile()
func TestFile(t *testing.T) {
rf := NewFile()
rf.Add(
&Entry{
Name: "stable",
@ -61,8 +61,8 @@ func TestRepoFile(t *testing.T) {
}
}
func TestNewRepositoriesFile(t *testing.T) {
expects := NewRepoFile()
func TestNewFile(t *testing.T) {
expects := NewFile()
expects.Add(
&Entry{
Name: "stable",
@ -76,17 +76,17 @@ func TestNewRepositoriesFile(t *testing.T) {
},
)
repofile, err := LoadRepositoriesFile(testRepositoriesFile)
file, err := LoadFile(testRepositoriesFile)
if err != nil {
t.Errorf("%q could not be loaded: %s", testRepositoriesFile, err)
}
if len(expects.Repositories) != len(repofile.Repositories) {
t.Fatalf("Unexpected repo data: %#v", repofile.Repositories)
if len(expects.Repositories) != len(file.Repositories) {
t.Fatalf("Unexpected repo data: %#v", file.Repositories)
}
for i, expect := range expects.Repositories {
got := repofile.Repositories[i]
got := file.Repositories[i]
if expect.Name != got.Name {
t.Errorf("Expected name %q, got %q", expect.Name, got.Name)
}
@ -99,8 +99,8 @@ func TestNewRepositoriesFile(t *testing.T) {
}
}
func TestNewPreV1RepositoriesFile(t *testing.T) {
r, err := LoadRepositoriesFile("testdata/old-repositories.yaml")
func TestNewPreV1File(t *testing.T) {
r, err := LoadFile("testdata/old-repositories.yaml")
if err != nil && err != ErrRepoOutOfDate {
t.Fatal(err)
}
@ -121,7 +121,7 @@ func TestNewPreV1RepositoriesFile(t *testing.T) {
}
func TestRemoveRepository(t *testing.T) {
sampleRepository := NewRepoFile()
sampleRepository := NewFile()
sampleRepository.Add(
&Entry{
Name: "stable",
@ -148,7 +148,7 @@ func TestRemoveRepository(t *testing.T) {
}
func TestUpdateRepository(t *testing.T) {
sampleRepository := NewRepoFile()
sampleRepository := NewFile()
sampleRepository.Add(
&Entry{
Name: "stable",
@ -183,7 +183,7 @@ func TestUpdateRepository(t *testing.T) {
}
func TestWriteFile(t *testing.T) {
sampleRepository := NewRepoFile()
sampleRepository := NewFile()
sampleRepository.Add(
&Entry{
Name: "stable",
@ -197,16 +197,16 @@ func TestWriteFile(t *testing.T) {
},
)
repoFile, err := ioutil.TempFile("", "helm-repo")
file, err := ioutil.TempFile("", "helm-repo")
if err != nil {
t.Errorf("failed to create test-file (%v)", err)
}
defer os.Remove(repoFile.Name())
if err := sampleRepository.WriteFile(repoFile.Name(), 0744); err != nil {
defer os.Remove(file.Name())
if err := sampleRepository.WriteFile(file.Name(), 0744); err != nil {
t.Errorf("failed to write file (%v)", err)
}
repos, err := LoadRepositoriesFile(repoFile.Name())
repos, err := LoadFile(file.Name())
if err != nil {
t.Errorf("failed to load file (%v)", err)
}
@ -218,7 +218,7 @@ func TestWriteFile(t *testing.T) {
}
func TestRepoNotExists(t *testing.T) {
_, err := LoadRepositoriesFile("/this/path/does/not/exist.yaml")
_, err := LoadFile("/this/path/does/not/exist.yaml")
if err == nil {
t.Errorf("expected err to be non-nil when path does not exist")
} else if !strings.Contains(err.Error(), "You might need to run `helm init`") {

@ -161,7 +161,7 @@ func (s *Server) LinkIndices() error {
// setTestingRepository sets up a testing repository.yaml with only the given name/URL.
func setTestingRepository(home helmpath.Home, name, url string) error {
r := repo.NewRepoFile()
r := repo.NewFile()
r.Add(&repo.Entry{
Name: name,
URL: url,

Loading…
Cancel
Save