Improve readability of ifc.Loader's Repo() method (#4857)

* Improve ldr Repo() method readability

* Change Repo() implementations and calls

* Improve readability of conditions in ldr.New()

* Fix details
This commit is contained in:
Anna Song
2022-11-08 14:48:14 -08:00
committed by GitHub
parent 6d9b54004e
commit beb2825f82
7 changed files with 35 additions and 35 deletions

View File

@@ -121,13 +121,13 @@ func NewFileLoaderAtRoot(fSys filesys.FileSystem) *fileLoader {
RestrictionRootOnly, fSys, filesys.Separator)
}
// Repo returns the absolute path to the repo that contains Root and true
// if this fileLoader was created from a url; otherwise, the empty string and false
func (fl *fileLoader) Repo() (string, bool) {
// Repo returns the absolute path to the repo that contains Root if this fileLoader was created from a url
// or the empty string otherwise.
func (fl *fileLoader) Repo() string {
if fl.repoSpec != nil {
return fl.repoSpec.Dir.String(), true
return fl.repoSpec.Dir.String()
}
return "", false
return ""
}
// Root returns the absolute path that is prepended to any

View File

@@ -95,8 +95,8 @@ func TestLoaderLoad(t *testing.T) {
require := require.New(t)
l1 := makeLoader()
_, remote := l1.Repo()
require.False(remote)
repo := l1.Repo()
require.Empty(repo)
require.Equal("/", l1.Root())
for _, x := range testCases {
@@ -110,8 +110,8 @@ func TestLoaderLoad(t *testing.T) {
l2, err := l1.New("foo/project")
require.NoError(err)
_, remote = l2.Repo()
require.False(remote)
repo = l2.Repo()
require.Empty(repo)
require.Equal("/foo/project", l2.Root())
for _, x := range testCases {
@@ -361,8 +361,7 @@ whatever
repoSpec, fSys, nil,
git.DoNothingCloner(filesys.ConfirmedDir(coRoot)))
require.NoError(err)
repo, remote := l.Repo()
require.True(remote)
repo := l.Repo()
require.Equal(coRoot, repo)
require.Equal(coRoot+"/"+pathInRepo, l.Root())
@@ -378,8 +377,7 @@ whatever
l2, err := l.New(url)
require.NoError(err)
repo, remote = l2.Repo()
require.True(remote)
repo = l2.Repo()
require.Equal(coRoot, repo)
require.Equal(coRoot+"/"+pathInRepo, l2.Root())
}
@@ -435,8 +433,8 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
// This is okay.
l2, err = l1.New("../base")
require.NoError(err)
_, remote := l2.Repo()
require.False(remote)
repo := l2.Repo()
require.Empty(repo)
require.Equal(cloneRoot+"/foo/base", l2.Root())
// This is not okay.
@@ -462,8 +460,7 @@ func TestLocalLoaderReferencingGitBase(t *testing.T) {
l2, err := l1.New("github.com/someOrg/someRepo/foo/base")
require.NoError(err)
repo, remote := l2.Repo()
require.True(remote)
repo := l2.Repo()
require.Equal(cloneRoot, repo)
require.Equal(cloneRoot+"/foo/base", l2.Root())
}