mirror of
https://github.com/gomods/athens
synced 2026-02-10 14:38:12 +00:00
Inlining afero fs to goget call, and new go getfetcher
This commit is contained in:
@@ -25,22 +25,19 @@ import (
|
||||
func New() (download.Protocol, error) {
|
||||
const op errors.Op = "goget.New"
|
||||
goBin := env.GoBinPath()
|
||||
fs := afero.NewOsFs()
|
||||
mf, err := module.NewGoGetFetcher(goBin, fs)
|
||||
mf, err := module.NewGoGetFetcher(goBin)
|
||||
if err != nil {
|
||||
return nil, errors.E(op, err)
|
||||
}
|
||||
return &goget{
|
||||
goBinPath: goBin,
|
||||
fetcher: mf,
|
||||
fs: fs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type goget struct {
|
||||
goBinPath string
|
||||
fetcher module.Fetcher
|
||||
fs afero.Fs
|
||||
}
|
||||
|
||||
func (gg *goget) List(ctx context.Context, mod string) ([]string, error) {
|
||||
@@ -91,12 +88,13 @@ func (gg *goget) Latest(ctx context.Context, mod string) (*storage.RevInfo, erro
|
||||
}
|
||||
|
||||
func (gg *goget) list(op errors.Op, mod string) (*listResp, error) {
|
||||
hackyPath, err := afero.TempDir(gg.fs, "", "hackymod")
|
||||
fs := afero.NewOsFs()
|
||||
hackyPath, err := afero.TempDir(fs, "", "hackymod")
|
||||
if err != nil {
|
||||
return nil, errors.E(op, err)
|
||||
}
|
||||
defer gg.fs.RemoveAll(hackyPath)
|
||||
err = module.Dummy(gg.fs, hackyPath)
|
||||
defer fs.RemoveAll(hackyPath)
|
||||
err = module.Dummy(fs, hackyPath)
|
||||
cmd := exec.Command(
|
||||
gg.goBinPath,
|
||||
"list", "-m", "-versions", "-json",
|
||||
|
||||
@@ -19,13 +19,13 @@ type goGetFetcher struct {
|
||||
}
|
||||
|
||||
// NewGoGetFetcher creates fetcher which uses go get tool to fetch modules
|
||||
func NewGoGetFetcher(goBinaryName string, fs afero.Fs) (Fetcher, error) {
|
||||
func NewGoGetFetcher(goBinaryName string) (Fetcher, error) {
|
||||
const op errors.Op = "module.NewGoGetFetcher"
|
||||
if err := validGoBinary(goBinaryName); err != nil {
|
||||
return nil, errors.E(op, err)
|
||||
}
|
||||
return &goGetFetcher{
|
||||
fs: fs,
|
||||
fs: afero.NewOsFs(),
|
||||
goBinaryName: goBinaryName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -6,20 +6,18 @@ import (
|
||||
|
||||
"github.com/gomods/athens/pkg/config/env"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
func (s *ModuleSuite) TestNewGoGetFetcher() {
|
||||
r := s.Require()
|
||||
fetcher, err := NewGoGetFetcher(s.goBinaryName, s.fs)
|
||||
fetcher, err := NewGoGetFetcher(s.goBinaryName)
|
||||
r.NoError(err)
|
||||
_, ok := fetcher.(*goGetFetcher)
|
||||
r.True(ok)
|
||||
}
|
||||
|
||||
func (s *ModuleSuite) TestGoGetFetcherError() {
|
||||
fetcher, err := NewGoGetFetcher("invalidpath", afero.NewOsFs())
|
||||
fetcher, err := NewGoGetFetcher("invalidpath")
|
||||
|
||||
assert.Nil(s.T(), fetcher)
|
||||
assert.EqualError(s.T(), err, "exec: \"invalidpath\": executable file not found in $PATH")
|
||||
@@ -29,7 +27,7 @@ func (s *ModuleSuite) TestGoGetFetcherFetch() {
|
||||
r := s.Require()
|
||||
// we need to use an OS filesystem because fetch executes vgo on the command line, which
|
||||
// always writes to the filesystem
|
||||
fetcher, err := NewGoGetFetcher(s.goBinaryName, afero.NewOsFs())
|
||||
fetcher, err := NewGoGetFetcher(s.goBinaryName)
|
||||
r.NoError(err)
|
||||
ref, err := fetcher.Fetch(repoURI, version)
|
||||
r.NoError(err, "fetch shouldn't error")
|
||||
@@ -56,7 +54,7 @@ func ExampleFetch() {
|
||||
repoURI := "github.com/arschles/assert"
|
||||
version := "v1.0.0"
|
||||
goBinaryName := env.GoBinPath()
|
||||
fetcher, err := NewGoGetFetcher(goBinaryName, afero.NewOsFs())
|
||||
fetcher, err := NewGoGetFetcher(goBinaryName)
|
||||
ref, err := fetcher.Fetch(repoURI, version)
|
||||
// handle errors if any
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user