diff options
| author | Ethan Lee <ethanalee@google.com> | 2026-03-11 21:20:21 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-03-30 13:26:49 -0700 |
| commit | 8514eebca6ca7b3213e879faa2a83c7e9ea6e181 (patch) | |
| tree | 85db643baa162d5a828895d3655b8e1fd3f5c9af /internal/testing | |
| parent | 46b63f3ffddc9657bc2c45fb116dc49c0b381a34 (diff) | |
| download | go-x-pkgsite-8514eebca6ca7b3213e879faa2a83c7e9ea6e181.tar.xz | |
internal/api: implement package imported-by endpoint
- Implement ServePackageImportedBy handler and GetImportedBy and GetImportedByCount datasource methods.
Change-Id: I8c4cc65fbff7172eaf48e5426e4f3f41c82bd38e
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/754865
Reviewed-by: Jonathan Amsterdam <jba@google.com>
kokoro-CI: kokoro <noreply+kokoro@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ethan Lee <ethanalee@google.com>
Diffstat (limited to 'internal/testing')
| -rw-r--r-- | internal/testing/fakedatasource/fakedatasource.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/testing/fakedatasource/fakedatasource.go b/internal/testing/fakedatasource/fakedatasource.go index 1075d147..3da3b3bf 100644 --- a/internal/testing/fakedatasource/fakedatasource.go +++ b/internal/testing/fakedatasource/fakedatasource.go @@ -393,18 +393,18 @@ func (ds *FakeDataSource) IsExcluded(ctx context.Context, path, version string) return false } -// GetImportedBy returns the set of packages importing the given pkgPath. -func (ds *FakeDataSource) GetImportedBy(ctx context.Context, pkgPath, modulePath string, limit int) (paths []string, err error) { - importedBy := append([]string{}, ds.importedBy[pkgPath]...) - sort.Strings(importedBy) - if len(importedBy) > limit { - importedBy = importedBy[:limit] +// GetImportedBy returns the paths of packages that import the given package. +func (ds *FakeDataSource) GetImportedBy(ctx context.Context, pkgPath, modulePath string, limit int) ([]string, error) { + paths := ds.importedBy[pkgPath] + if len(paths) > limit { + return paths[:limit], nil } - return importedBy, nil + return paths, nil } +// GetImportedByCount returns the number of packages that import the given package. func (ds *FakeDataSource) GetImportedByCount(ctx context.Context, pkgPath, modulePath string) (int, error) { - return 0, nil + return len(ds.importedBy[pkgPath]), nil } func (ds *FakeDataSource) GetLatestMajorPathForV1Path(ctx context.Context, v1path string) (string, int, error) { |
