internal/postgres: delete LegacyGetLicenses
TestGetLicenses is updated to test GetUnit using the WithLicenses
fieldset.
For golang/go#39629
Change-Id: I176191c7255db697a7a102fc7d67802380377097
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258294
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/internal/postgres/licenses.go b/internal/postgres/licenses.go
index 0c5d7c1..f5435b3 100644
--- a/internal/postgres/licenses.go
+++ b/internal/postgres/licenses.go
@@ -14,26 +14,11 @@
"strings"
"github.com/lib/pq"
- "golang.org/x/mod/semver"
"golang.org/x/pkgsite/internal/derrors"
"golang.org/x/pkgsite/internal/licenses"
"golang.org/x/pkgsite/internal/stdlib"
)
-// LegacyGetLicenses returns the licenses that applies to the fullPath for the given module version.
-// It returns an InvalidArgument error if the module path or version is invalid.
-func (db *DB) LegacyGetLicenses(ctx context.Context, fullPath, modulePath, resolvedVersion string) (_ []*licenses.License, err error) {
- defer derrors.Wrap(&err, "GetLicenses(ctx, %q, %q, %q)", fullPath, modulePath, resolvedVersion)
- if fullPath == "" || modulePath == "" || !semver.IsValid(resolvedVersion) {
- return nil, derrors.InvalidArgument
- }
- pathID, err := db.getPathID(ctx, fullPath, modulePath, resolvedVersion)
- if err != nil {
- return nil, err
- }
- return db.getLicenses(ctx, fullPath, modulePath, pathID)
-}
-
func (db *DB) getLicenses(ctx context.Context, fullPath, modulePath string, pathID int) (_ []*licenses.License, err error) {
defer derrors.Wrap(&err, "getLicenses(ctx, %d)", pathID)
diff --git a/internal/postgres/licenses_test.go b/internal/postgres/licenses_test.go
index 3514802..825608a 100644
--- a/internal/postgres/licenses_test.go
+++ b/internal/postgres/licenses_test.go
@@ -13,7 +13,6 @@
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"golang.org/x/pkgsite/internal"
- "golang.org/x/pkgsite/internal/derrors"
"golang.org/x/pkgsite/internal/licenses"
"golang.org/x/pkgsite/internal/stdlib"
"golang.org/x/pkgsite/internal/testing/sample"
@@ -54,10 +53,6 @@
want []*licenses.License
}{
{
- name: "empty path",
- err: derrors.InvalidArgument,
- },
- {
name: "module root",
fullPath: sample.ModulePath,
modulePath: sample.ModulePath,
@@ -101,10 +96,11 @@
},
} {
t.Run(test.name, func(t *testing.T) {
- got, err := testDB.LegacyGetLicenses(ctx, test.fullPath, test.modulePath, test.version)
+ u, err := testDB.GetUnit(ctx, &internal.UnitMeta{Path: test.fullPath, ModulePath: test.modulePath, Version: test.version}, internal.WithLicenses)
if !errors.Is(err, test.err) {
t.Fatal(err)
}
+ got := u.LicenseContents
sort.Slice(got, func(i, j int) bool {
return got[i].FilePath < got[j].FilePath
})
@@ -173,22 +169,17 @@
}
// check reads and the second license in the module and compares it with want.
- check := func(bypass, legacy bool, want *licenses.License) {
+ check := func(bypass bool, want *licenses.License) {
t.Helper()
db := testDB
if bypass {
db = bypassDB
}
- var lics []*licenses.License
- var err error
- if legacy {
- lics, err = db.getModuleLicenses(ctx, sample.ModulePath, m.Version)
- } else {
- lics, err = db.LegacyGetLicenses(ctx, sample.ModulePath, sample.ModulePath, m.Version)
- }
+ u, err := db.GetUnit(ctx, &internal.UnitMeta{Path: sample.ModulePath, ModulePath: sample.ModulePath, Version: m.Version}, internal.WithLicenses)
if err != nil {
t.Fatal(err)
}
+ lics := u.LicenseContents
if len(lics) != 2 {
t.Fatal("did not read two licenses")
}
@@ -198,14 +189,12 @@
}
// Read with license bypass includes non-redistributable license contents.
- check(true, false, sample.NonRedistributableLicense)
- check(true, true, sample.NonRedistributableLicense)
+ check(true, sample.NonRedistributableLicense)
// Read without license bypass does not include non-redistributable license contents.
nonRedist := *sample.NonRedistributableLicense
nonRedist.Contents = nil
- check(false, false, &nonRedist)
- check(false, true, &nonRedist)
+ check(false, &nonRedist)
}
func nonRedistributableModule() *internal.Module {