internal/postgres: delete LegacyGetPackageLicenses
For golang/go#39629
Change-Id: Ie4b9bb36ca4dcb3b8cdca4d236a8cd90541baf45
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258292
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 0629917..0c5d7c1 100644
--- a/internal/postgres/licenses.go
+++ b/internal/postgres/licenses.go
@@ -115,48 +115,6 @@
return collectLicenses(rows, db.bypassLicenseCheck)
}
-// LegacyGetPackageLicenses returns all licenses associated with the given package path and
-// version.
-// It returns an InvalidArgument error if the module path or version is invalid.
-func (db *DB) LegacyGetPackageLicenses(ctx context.Context, pkgPath, modulePath, resolvedVersion string) (_ []*licenses.License, err error) {
- defer derrors.Wrap(&err, "LegacyGetPackageLicenses(ctx, %q, %q, %q)", pkgPath, modulePath, resolvedVersion)
-
- if pkgPath == "" || resolvedVersion == "" {
- return nil, fmt.Errorf("neither pkgPath nor version can be empty: %w", derrors.InvalidArgument)
- }
- query := `
- SELECT
- l.types,
- l.file_path,
- l.contents,
- l.coverage
- FROM
- licenses l
- INNER JOIN (
- SELECT DISTINCT ON (license_file_path)
- module_path,
- version,
- unnest(license_paths) AS license_file_path
- FROM
- packages
- WHERE
- path = $1
- AND module_path = $2
- AND version = $3
- ) p
- ON
- p.module_path = l.module_path
- AND p.version = l.version
- AND p.license_file_path = l.file_path;`
-
- rows, err := db.db.Query(ctx, query, pkgPath, modulePath, resolvedVersion)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
- return collectLicenses(rows, db.bypassLicenseCheck)
-}
-
// collectLicenses converts the sql rows to a list of licenses. The columns
// must be types, file_path and contents, in that order.
func collectLicenses(rows *sql.Rows, bypassLicenseCheck bool) ([]*licenses.License, error) {
diff --git a/internal/postgres/licenses_test.go b/internal/postgres/licenses_test.go
index 5c41df9..3514802 100644
--- a/internal/postgres/licenses_test.go
+++ b/internal/postgres/licenses_test.go
@@ -159,48 +159,6 @@
}
}
-func TestLegacyGetPackageLicenses(t *testing.T) {
- modulePath := "test.module"
- testModule := sample.Module(modulePath, "v1.2.3", "", "foo")
- testModule.LegacyPackages[0].Licenses = nil
- testModule.LegacyPackages[1].Licenses = sample.LicenseMetadata
-
- tests := []struct {
- label, pkgPath string
- wantLicenses []*licenses.License
- }{
- {
- label: "package with licenses",
- pkgPath: "test.module/foo",
- wantLicenses: sample.Licenses,
- }, {
- label: "package with no licenses",
- pkgPath: "test.module",
- wantLicenses: nil,
- },
- }
-
- defer ResetTestDB(testDB, t)
- ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
- defer cancel()
-
- if err := testDB.InsertModule(ctx, testModule); err != nil {
- t.Fatal(err)
- }
-
- for _, test := range tests {
- t.Run(test.label, func(t *testing.T) {
- got, err := testDB.LegacyGetPackageLicenses(ctx, test.pkgPath, modulePath, testModule.Version)
- if err != nil {
- t.Fatal(err)
- }
- if diff := cmp.Diff(test.wantLicenses, got); diff != "" {
- t.Errorf("testDB.GetLicenses(ctx, %q, %q) mismatch (-want +got):\n%s", test.pkgPath, testModule.Version, diff)
- }
- })
- }
-}
-
func TestGetLicensesBypass(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()