diff options
| author | Jonathan Amsterdam <jba@google.com> | 2021-08-13 10:30:07 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2021-08-13 18:10:53 +0000 |
| commit | eb20e7607d6d6c57710b5d967c1d51fd0e1e4034 (patch) | |
| tree | a4dbe25dac5eaf2028a03c673173292a1e32e60d /internal/postgres/insert_module_test.go | |
| parent | 43c22efdbfa9c91934a205fe3f3675529345392d (diff) | |
| download | go-x-pkgsite-eb20e7607d6d6c57710b5d967c1d51fd0e1e4034.tar.xz | |
internal/{worker,postgres}: remove alternative modules from search
When processing a module, if it is an alternative module, remove it
from search_documents and imports_unique.
Change-Id: I3fd12e8522331b8a4f060c9576d97c0ee710785d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/341854
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'internal/postgres/insert_module_test.go')
| -rw-r--r-- | internal/postgres/insert_module_test.go | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go index 76a9c6bf..66233bf5 100644 --- a/internal/postgres/insert_module_test.go +++ b/internal/postgres/insert_module_test.go @@ -620,9 +620,7 @@ func TestReInsertLatestVersion(t *testing.T) { defer release() ctx := context.Background() - const modulePath = "m.com/a" - - insert := func(version string, status int, imports []string, modfile string) { + insert := func(modulePath, version string, status int, imports []string, modfile string) { m := sample.Module(modulePath, version, "pkg") pkg := m.Packages()[0] pkg.Documentation[0].Synopsis = version @@ -647,15 +645,15 @@ func TestReInsertLatestVersion(t *testing.T) { } } - check := func(wantVersion string, wantImports []string) { + check := func(modPath, wantVersion string, wantImports []string) { t.Helper() var gotVersion, gotSynopsis string err := testDB.db.QueryRow(ctx, ` SELECT version, synopsis FROM search_documents - WHERE module_path = 'm.com/a' - AND package_path = 'm.com/a/pkg' - `).Scan(&gotVersion, &gotSynopsis) + WHERE module_path = $1 + AND package_path = $1 || '/pkg' + `, modPath).Scan(&gotVersion, &gotSynopsis) if errors.Is(err, sql.ErrNoRows) { gotVersion = "" gotSynopsis = "" @@ -669,9 +667,9 @@ func TestReInsertLatestVersion(t *testing.T) { gotImports, err := testDB.db.CollectStrings(ctx, ` SELECT to_path FROM imports_unique - WHERE from_path = 'm.com/a/pkg' - AND from_module_path = 'm.com/a' - `) + WHERE from_path = $1 || '/pkg' + AND from_module_path = $1 + `, modPath) if err != nil { t.Fatal(err) } @@ -683,22 +681,33 @@ func TestReInsertLatestVersion(t *testing.T) { } imports1 := []string{"fmt", "log"} + const modPath1 = "m.com/a" // Insert a good module. It should be in search_documents and imports_unique. - insert("v1.1.0", 200, imports1, "") - check("v1.1.0", imports1) + insert(modPath1, "v1.1.0", 200, imports1, "") + check(modPath1, "v1.1.0", imports1) // Insert a higher, good version. It should replace the first. imports2 := []string{"log", "strings"} - insert("v1.2.0", 200, imports2, "") - check("v1.2.0", imports2) + insert(modPath1, "v1.2.0", 200, imports2, "") + check(modPath1, "v1.2.0", imports2) // Now an even higher, bad version comes along that retracts v1.2.0. // The search_documents and imports_unique tables should go back to v1.1.0. - insert("v1.3.0", 400, nil, "retract v1.2.0") - check("v1.1.0", imports1) + insert(modPath1, "v1.3.0", 400, nil, "retract v1.2.0") + check(modPath1, "v1.1.0", imports1) // Now a still higher version comes along that retracts everything. The // module should no longer be in search_documents or imports_unique. - insert("v1.4.0", 200, nil, "retract [v1.0.0, v1.4.0]") - check("", nil) + insert(modPath1, "v1.4.0", 200, nil, "retract [v1.0.0, v1.4.0]") + check(modPath1, "", nil) + + // Insert another good module. + const modPath2 = "m.com/b" + insert(modPath2, "v1.1.0", 200, imports1, "") + check(modPath2, "v1.1.0", imports1) + + // A later version makes this an alternative module. + // The module should be removed from search. + insert(modPath2, "v1.2.0", 491, imports1, "") + check(modPath2, "", nil) } |
