aboutsummaryrefslogtreecommitdiff
path: root/internal/testing
diff options
context:
space:
mode:
authorEthan Lee <ethanalee@google.com>2026-03-11 21:17:12 +0000
committerGopher Robot <gobot@golang.org>2026-03-26 10:33:29 -0700
commit06c847e1184d477cfb622ff6710b48848bf0ffcf (patch)
treef21802263c73f5a2882bb6393746283519e5fbd0 /internal/testing
parentdb1fff145dfefcb1643606d3c661e01b1e91bbbd (diff)
downloadgo-x-pkgsite-06c847e1184d477cfb622ff6710b48848bf0ffcf.tar.xz
internal/api: implement package symbols endpoint
- Introduce a new ServePackageSymbols handler that utilizes the new db.GetSymbols method. - Consolidated module resolution logic shared by ServePackages into resolveModulePath. - Updated Datasource with GetSymbols, which provides a more efficient way to retrieve all symbols for a package at a given version and build context. This differs from the existing getPackageSymbols, since that will return symbols for the latest release/compatible version. - Refactored packageSymbolQueryJoin into a generic helper by removing hardcoded version filters. This allows GetSymbols to query for any specific version, while getPackageSymbols was updated to explicitly include release-only filters to preserve its existing behavior. - GetSymbols still utilizes the same underlying packageSymbolQueryJoin, but it will also attempt to match the most relevant BuildContext for the query. It will also provide a mapping of parent and child symbols. Change-Id: Ib18d2511d24ac6bc5b75c7b3809c4ce126245036 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/754864 Auto-Submit: Ethan Lee <ethanalee@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'internal/testing')
-rw-r--r--internal/testing/fakedatasource/fakedatasource.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/testing/fakedatasource/fakedatasource.go b/internal/testing/fakedatasource/fakedatasource.go
index 82212163..b44212a0 100644
--- a/internal/testing/fakedatasource/fakedatasource.go
+++ b/internal/testing/fakedatasource/fakedatasource.go
@@ -337,6 +337,34 @@ func (ds *FakeDataSource) GetModulePackages(ctx context.Context, modulePath, ver
return pkgs, nil
}
+// GetSymbols returns symbols for the given unit and build context.
+func (ds *FakeDataSource) GetSymbols(ctx context.Context, pkgPath, modulePath, version string, bc internal.BuildContext) ([]*internal.Symbol, error) {
+ m := ds.getModule(modulePath, version)
+ if m == nil {
+ return nil, derrors.NotFound
+ }
+ u := findUnit(m, pkgPath)
+ if u == nil {
+ return nil, derrors.NotFound
+ }
+
+ var bcs []internal.BuildContext
+ for b := range u.Symbols {
+ if bc.Match(b) {
+ bcs = append(bcs, b)
+ }
+ }
+ if len(bcs) == 0 {
+ return nil, derrors.NotFound
+ }
+
+ sort.Slice(bcs, func(i, j int) bool {
+ return internal.CompareBuildContexts(bcs[i], bcs[j]) < 0
+ })
+
+ return u.Symbols[bcs[0]], nil
+}
+
// SearchSupport reports the search types supported by this datasource.
func (ds *FakeDataSource) SearchSupport() internal.SearchSupport {
// internal/frontend.TestDetermineSearchAction depends on us returning FullSearch