internal/postgres: delete LegacyGetModuleInfo
For golang/go#39629
Change-Id: I3be1a9ce361d73e0d6f7b373ac7c410bc571481b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258290
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/details.go b/internal/postgres/details.go
index a3f9cb6..ab8ce63 100644
--- a/internal/postgres/details.go
+++ b/internal/postgres/details.go
@@ -193,52 +193,6 @@
return mi, nil
}
-// LegacyGetModuleInfo fetches a module version from the database with the primary key
-// (module_path, version).
-func (db *DB) LegacyGetModuleInfo(ctx context.Context, modulePath string, requestedVersion string) (_ *internal.LegacyModuleInfo, err error) {
- defer derrors.Wrap(&err, "LegacyGetModuleInfo(ctx, %q, %q)", modulePath, requestedVersion)
-
- query := `
- SELECT
- module_path,
- version,
- commit_time,
- readme_file_path,
- readme_contents,
- source_info,
- redistributable,
- has_go_mod
- FROM
- modules m`
-
- args := []interface{}{modulePath}
- if requestedVersion == internal.LatestVersion {
- query += fmt.Sprintf(`
- WHERE m.module_path = $1 %s LIMIT 1;`, orderByLatest)
- } else {
- query += `
- WHERE m.module_path = $1 AND m.version = $2;`
- args = append(args, requestedVersion)
- }
-
- var mi internal.LegacyModuleInfo
- row := db.db.QueryRow(ctx, query, args...)
- if err := row.Scan(&mi.ModulePath, &mi.Version, &mi.CommitTime,
- database.NullIsEmpty(&mi.LegacyReadmeFilePath), database.NullIsEmpty(&mi.LegacyReadmeContents),
- jsonbScanner{&mi.SourceInfo}, &mi.IsRedistributable, &mi.HasGoMod); err != nil {
- if err == sql.ErrNoRows {
- return nil, fmt.Errorf("module version %s@%s: %w", modulePath, requestedVersion, derrors.NotFound)
- }
- return nil, fmt.Errorf("row.Scan(): %v", err)
- }
- if db.bypassLicenseCheck {
- mi.IsRedistributable = true
- } else {
- mi.RemoveNonRedistributableData()
- }
- return &mi, nil
-}
-
// jsonbScanner scans a jsonb value into a Go value.
type jsonbScanner struct {
ptr interface{} // a pointer to a Go struct or other JSON-serializable value
diff --git a/internal/postgres/details_test.go b/internal/postgres/details_test.go
index 03087cd..c100e12 100644
--- a/internal/postgres/details_test.go
+++ b/internal/postgres/details_test.go
@@ -201,75 +201,6 @@
}
}
-func TestPostgres_GetVersionInfo_Latest(t *testing.T) {
- ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
- defer cancel()
-
- defer ResetTestDB(testDB, t)
-
- testCases := []struct {
- name, path string
- modules []*internal.Module
- wantIndex int // index into versions
- wantErr error
- }{
- {
- name: "largest release",
- path: "mod.1",
- modules: []*internal.Module{
- sample.Module("mod.1", "v1.1.0-alpha.1", sample.Suffix),
- sample.Module("mod.1", "v1.0.0", sample.Suffix),
- sample.Module("mod.1", "v1.0.0-20190311183353-d8887717615a", sample.Suffix),
- sample.Module("mod.1", "v2.0.0+incompatible", sample.Suffix),
- },
- wantIndex: 1,
- },
- {
- name: "largest prerelease",
- path: "mod.2",
- modules: []*internal.Module{
- sample.Module("mod.2", "v1.1.0-beta.10", sample.Suffix),
- sample.Module("mod.2", "v1.1.0-beta.2", sample.Suffix),
- sample.Module("mod.2", "v1.0.0-20190311183353-d8887717615a", sample.Suffix),
- },
- wantIndex: 0,
- },
- {
- name: "no versions",
- path: "mod3",
- wantErr: derrors.NotFound,
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- for _, v := range tc.modules {
- if err := testDB.InsertModule(ctx, v); err != nil {
- t.Error(err)
- }
- }
-
- gotVI, err := testDB.LegacyGetModuleInfo(ctx, tc.path, internal.LatestVersion)
- if err != nil {
- if tc.wantErr == nil {
- t.Fatalf("got unexpected error %v", err)
- }
- if !errors.Is(err, tc.wantErr) {
- t.Fatalf("got error %v, want Is(%v)", err, tc.wantErr)
- }
- return
- }
- if tc.wantIndex >= len(tc.modules) {
- t.Fatal("wantIndex too large")
- }
- wantVI := &tc.modules[tc.wantIndex].LegacyModuleInfo
- if diff := cmp.Diff(wantVI, gotVI, cmpopts.EquateEmpty(), cmp.AllowUnexported(source.Info{})); diff != "" {
- t.Errorf("mismatch (-want +got):\n%s", diff)
- }
- })
- }
-}
-
func TestGetImportedBy(t *testing.T) {
var (
m1 = sample.Module("path.to/foo", "v1.1.0", "bar")
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 6dcde6a..cd64eaa 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -85,12 +85,12 @@
}
func checkModule(ctx context.Context, t *testing.T, want *internal.Module) {
- got, err := testDB.LegacyGetModuleInfo(ctx, want.ModulePath, want.Version)
+ got, err := testDB.GetModuleInfo(ctx, want.ModulePath, want.Version)
if err != nil {
t.Fatal(err)
}
- if diff := cmp.Diff(want.LegacyModuleInfo, *got, cmp.AllowUnexported(source.Info{})); diff != "" {
- t.Fatalf("testDB.LegacyGetModuleInfo(%q, %q) mismatch (-want +got):\n%s", want.ModulePath, want.Version, diff)
+ if diff := cmp.Diff(want.ModuleInfo, *got, cmp.AllowUnexported(source.Info{})); diff != "" {
+ t.Fatalf("testDB.GetModuleInfo(%q, %q) mismatch (-want +got):\n%s", want.ModulePath, want.Version, diff)
}
for _, wantp := range want.LegacyPackages {
@@ -177,17 +177,6 @@
t.Fatal(err)
}
- // Legacy model
- mi, err := db.LegacyGetModuleInfo(ctx, mod.ModulePath, mod.Version)
- if err != nil {
- t.Fatal(err)
- }
- pkg, err := db.LegacyGetPackage(ctx, mod.ModulePath, mod.ModulePath, mod.Version)
- if err != nil {
- t.Fatal(err)
- }
- checkHasRedistData(mi.LegacyReadmeContents, pkg.DocumentationHTML, bypass)
-
// New model
pathInfo := &internal.UnitMeta{
Path: mod.ModulePath,
@@ -436,7 +425,7 @@
if err := testDB.InsertModule(ctx, v); err != nil {
t.Fatal(err)
}
- if _, err := testDB.LegacyGetModuleInfo(ctx, v.ModulePath, v.Version); err != nil {
+ if _, err := testDB.GetModuleInfo(ctx, v.ModulePath, v.Version); err != nil {
t.Fatal(err)
}
@@ -451,7 +440,7 @@
if err := testDB.DeleteModule(ctx, v.ModulePath, v.Version); err != nil {
t.Fatal(err)
}
- if _, err := testDB.LegacyGetModuleInfo(ctx, v.ModulePath, v.Version); !errors.Is(err, derrors.NotFound) {
+ if _, err := testDB.GetModuleInfo(ctx, v.ModulePath, v.Version); !errors.Is(err, derrors.NotFound) {
t.Errorf("got %v, want NotFound", err)
}