aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module_test.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-03-19 09:41:52 -0400
committerJonathan Amsterdam <jba@google.com>2021-03-19 17:57:51 +0000
commit7eca3b55e9e9e35a80dfe1d3d4435be75214acdf (patch)
tree3714f405f7300d12fd288051261e9d1b7c9005fe /internal/postgres/insert_module_test.go
parent50e768a51c2b6bd9c8fdd26ba89bc9e0e9153b79 (diff)
downloadgo-x-pkgsite-7eca3b55e9e9e35a80dfe1d3d4435be75214acdf.tar.xz
internal/postgres: reimplement alternative-module check
When inserting a module, we skip inserting into search_documents if the module path is an alternative one. This CL factors out that test, and also reimplements it in terms of the latest cooked version. Previously, any later version with a 491 status would classify the path as alternative, but this version uses the latest cooked (non-retracted) version's status to decide, allowing module authors to fix mistakes. Change-Id: I3588f3df6a1a4dd4db59333314c34167eda51df1 For golang/go#44710 Change-Id: I670d9085800fed198e6dd6469f1a8d5728c5f039 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/303309 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to 'internal/postgres/insert_module_test.go')
-rw-r--r--internal/postgres/insert_module_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 367e2c87..48d2db74 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -507,6 +507,7 @@ func TestPostgres_NewerAlternative(t *testing.T) {
GoModPath: "example.com/mod",
FetchErr: derrors.AlternativeModule,
}
+ addLatest(ctx, t, testDB, mvs.ModulePath, altVersion, "")
if err := testDB.UpsertModuleVersionState(ctx, mvs); err != nil {
t.Fatal(err)
}
@@ -607,3 +608,46 @@ func TestLock(t *testing.T) {
t.Errorf("got %d, want %d", count, n)
}
}
+
+func TestIsAlternativeModulePath(t *testing.T) {
+ t.Parallel()
+ ctx := context.Background()
+ testDB, release := acquire(t)
+ defer release()
+
+ const modulePath = "m.com/a"
+ altModuleStatus := derrors.ToStatus(derrors.AlternativeModule)
+ // These tests form a sequence. Each test's state affects the next's.
+ for _, test := range []struct {
+ version string
+ status int
+ want bool
+ }{
+ {"v1.2.0", 200, false}, // no 491s
+ {"v1.1.0", altModuleStatus, false}, // 491 is earlier
+ {"v1.3.0-pre", altModuleStatus, false}, // still earlier: release beats pre-release
+ {"v1.3.0", altModuleStatus, true}, // latest version is 491
+ {"v1.4.0", 200, false}, // new latest version is OK
+ {"v1.5.0", altModuleStatus, true}, // "I can do this all day." --Captain America
+ } {
+ addLatest(ctx, t, testDB, modulePath, test.version, "")
+ if err := testDB.UpsertModuleVersionState(ctx, &ModuleVersionStateForUpsert{
+ ModulePath: modulePath,
+ Version: test.version,
+ AppVersion: "appVersion",
+ Timestamp: time.Now(),
+ Status: test.status,
+ HasGoMod: true,
+ }); err != nil {
+ t.Fatal(err)
+ }
+
+ got, err := isAlternativeModulePath(ctx, testDB.db, modulePath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got != test.want {
+ t.Fatalf("%q, %d: got %t, want %t", test.version, test.status, got, test.want)
+ }
+ }
+}