diff options
| author | Jonathan Amsterdam <jba@google.com> | 2021-08-19 11:30:41 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2021-08-19 16:18:23 +0000 |
| commit | 34219a32ecc362fc3e1b5f97b1e8a983fa4cf7ab (patch) | |
| tree | 933b0c33919b5fc7fa2708244e8765debb305f07 /internal/fetch | |
| parent | 5e769f62846dcc94c3472c43335b72082a078c84 (diff) | |
| download | go-x-pkgsite-34219a32ecc362fc3e1b5f97b1e8a983fa4cf7ab.tar.xz | |
internal/fetch: remove FetchLocalModule
It is no longer used.
For golang/go#47780
Change-Id: I9857e6b4d0ac77cfe4b30ce02e670fc93f34e51e
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/343629
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/fetch')
| -rw-r--r-- | internal/fetch/fetchlocal.go | 24 | ||||
| -rw-r--r-- | internal/fetch/fetchlocal_test.go | 23 | ||||
| -rw-r--r-- | internal/fetch/helper_test.go | 12 |
3 files changed, 17 insertions, 42 deletions
diff --git a/internal/fetch/fetchlocal.go b/internal/fetch/fetchlocal.go index 640b2df5..f22bb64c 100644 --- a/internal/fetch/fetchlocal.go +++ b/internal/fetch/fetchlocal.go @@ -20,7 +20,6 @@ import ( "golang.org/x/mod/modfile" "golang.org/x/pkgsite/internal/derrors" "golang.org/x/pkgsite/internal/proxy" - "golang.org/x/pkgsite/internal/source" ) // Version and commit time are pre specified when fetching a local module, as these @@ -100,29 +99,6 @@ func (g *directoryModuleGetter) ZipSize(ctx context.Context, path, version strin return 0, errors.New("directoryModuleGetter.ZipSize unimplemented") } -// FetchLocalModule fetches a module from a local directory and process its contents -// to return an internal.Module and other related information. modulePath is not necessary -// if the module has a go.mod file, but if both exist, then they must match. -// FetchResult.Error should be checked to verify that the fetch succeeded. Even if the -// error is non-nil the result may contain useful data. -func FetchLocalModule(ctx context.Context, modulePath, localPath string, sourceClient *source.Client) *FetchResult { - g, err := NewDirectoryModuleGetter(modulePath, localPath) - if err != nil { - return &FetchResult{ - ModulePath: modulePath, - Error: err, - } - } - if modulePath == "" { - modulePath = g.modulePath - } - fr := FetchModule(ctx, modulePath, LocalVersion, g, sourceClient) - if fr.Error != nil { - fr.Error = fmt.Errorf("FetchLocalModule(%q, %q): %w", modulePath, localPath, fr.Error) - } - return fr -} - // createZipReader creates a zip file from a directory given a local path and // returns a zip.Reader to be passed to processZipFile. The purpose of the // function is to transform a local go module into a zip file to be processed by diff --git a/internal/fetch/fetchlocal_test.go b/internal/fetch/fetchlocal_test.go index 25d72520..914c052a 100644 --- a/internal/fetch/fetchlocal_test.go +++ b/internal/fetch/fetchlocal_test.go @@ -5,28 +5,23 @@ package fetch import ( - "context" "errors" "testing" "golang.org/x/pkgsite/internal/derrors" - "golang.org/x/pkgsite/internal/source" ) -func TestLocalEmptyModulePath(t *testing.T) { - // Test local fetching when the module path is empty (corresponding to the - // main module of a directory). Other cases are tested in TestFetchModule. - ctx := context.Background() - got := FetchLocalModule(ctx, "", "testdata/has_go_mod", source.NewClientForTesting()) - if got.Error != nil { - t.Fatal(got.Error) +func TestDirectoryModuleGetterEmpty(t *testing.T) { + g, err := NewDirectoryModuleGetter("", "testdata/has_go_mod") + if err != nil { + t.Fatal(err) } - if want := "testmod"; got.ModulePath != want { - t.Errorf("got %q, want %q", got.ModulePath, want) + if want := "testmod"; g.modulePath != want { + t.Errorf("got %q, want %q", g.modulePath, want) } - got = FetchLocalModule(ctx, "", "testdata/no_go_mod", source.NewClientForTesting()) - if !errors.Is(got.Error, derrors.BadModule) { - t.Errorf("got %v, want BadModule", got.Error) + _, err = NewDirectoryModuleGetter("", "testdata/no_go_mod") + if !errors.Is(err, derrors.BadModule) { + t.Errorf("got %v, want BadModule", err) } } diff --git a/internal/fetch/helper_test.go b/internal/fetch/helper_test.go index b1589245..871ee8f1 100644 --- a/internal/fetch/helper_test.go +++ b/internal/fetch/helper_test.go @@ -157,9 +157,9 @@ func proxyFetcher(t *testing.T, withLicenseDetector bool, ctx context.Context, m return got, d } -// localFetcher is a helper function that creates a test directory to hold a module, -// fetches the module from the directory using FetchLocalModule, and returns a fetch -// result, and a license detector. +// localFetcher is a helper function that creates a test directory to hold a +// module, fetches the module from the directory, and returns a fetch result +// and a license detector. func localFetcher(t *testing.T, withLicenseDetector bool, ctx context.Context, mod *proxytest.Module, fetchVersion string) (*FetchResult, *licenses.Detector) { t.Helper() @@ -170,7 +170,11 @@ func localFetcher(t *testing.T, withLicenseDetector bool, ctx context.Context, m defer os.RemoveAll(directory) modulePath := mod.ModulePath - got := FetchLocalModule(ctx, modulePath, directory, source.NewClientForTesting()) + g, err := NewDirectoryModuleGetter(modulePath, directory) + if err != nil { + t.Fatal(err) + } + got := FetchModule(ctx, modulePath, LocalVersion, g, source.NewClientForTesting()) if !withLicenseDetector { return got, nil } |
