diff options
| author | Julie Qiu <julie@golang.org> | 2021-08-13 10:51:45 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2021-09-14 19:35:06 +0000 |
| commit | facaa9442889295c274882feb2d3f455455ab8be (patch) | |
| tree | c4d81117220b56d2be8fd193bad44ac783349386 /internal/postgres/insert_module_test.go | |
| parent | bcdff3a7d0af167901eb8dfbb60da1f265f92fe1 (diff) | |
| download | go-x-pkgsite-facaa9442889295c274882feb2d3f455455ab8be.tar.xz | |
internal/postgres: change UpsertModuleVersionStates to update
UpsertModuleVersionStates is changed to UpdateModuleVersionStates. There
should never be a situation where UpsertModuleVersionStates is called
and a row does not already exist for that module.
If that happens, an error is now returned.
For golang/go#46985
Fixes golang/go#39628
Change-Id: I357396cee6eb743513ae249609f76f4cd4c19e9b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/341860
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>
Diffstat (limited to 'internal/postgres/insert_module_test.go')
| -rw-r--r-- | internal/postgres/insert_module_test.go | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go index 00e178d9..3c44d872 100644 --- a/internal/postgres/insert_module_test.go +++ b/internal/postgres/insert_module_test.go @@ -458,7 +458,7 @@ func TestPostgres_NewerAlternative(t *testing.T) { okVersion = "v1.0.0" ) - mvs := &ModuleVersionStateForUpsert{ + mvs := &ModuleVersionStateForUpdate{ ModulePath: "example.com/Mod", Version: altVersion, AppVersion: "appVersion", @@ -467,8 +467,17 @@ func TestPostgres_NewerAlternative(t *testing.T) { GoModPath: "example.com/mod", FetchErr: derrors.AlternativeModule, } + if err := testDB.InsertIndexVersions(ctx, []*internal.IndexVersion{ + { + Path: mvs.ModulePath, + Version: mvs.Version, + Timestamp: mvs.Timestamp, + }, + }); err != nil { + t.Fatal(err) + } addLatest(ctx, t, testDB, mvs.ModulePath, altVersion, "") - if err := testDB.UpsertModuleVersionState(ctx, mvs); err != nil { + if err := testDB.UpdateModuleVersionState(ctx, mvs); err != nil { t.Fatal(err) } m := sample.Module(mvs.ModulePath, okVersion, "p") @@ -592,17 +601,27 @@ func TestIsAlternativeModulePath(t *testing.T) { {modulePathA, "v1.4.0", 200, false}, // new latest version is OK {modulePathA, "v1.5.0", altModuleStatus, true}, // "I can do this all day." --Captain America } { - addLatest(ctx, t, testDB, test.modulePath, test.version, "") - if err := testDB.UpsertModuleVersionState(ctx, &ModuleVersionStateForUpsert{ + mvs := &ModuleVersionStateForUpdate{ ModulePath: test.modulePath, Version: test.version, AppVersion: "appVersion", Timestamp: time.Now(), Status: test.status, HasGoMod: true, + } + if err := testDB.InsertIndexVersions(ctx, []*internal.IndexVersion{ + { + Path: mvs.ModulePath, + Version: mvs.Version, + Timestamp: mvs.Timestamp, + }, }); err != nil { t.Fatal(err) } + addLatest(ctx, t, testDB, test.modulePath, test.version, "") + if err := testDB.UpdateModuleVersionState(ctx, mvs); err != nil { + t.Fatal(err) + } got, err := isAlternativeModulePath(ctx, testDB.db, modulePathA) if err != nil { @@ -630,7 +649,17 @@ func TestReconcileSearch(t *testing.T) { addLatest(ctx, t, testDB, modulePath, version, modfile) } - if err := testDB.UpsertModuleVersionState(ctx, &ModuleVersionStateForUpsert{ + if err := testDB.InsertIndexVersions(ctx, + []*internal.IndexVersion{ + { + Path: modulePath, + Version: version, + Timestamp: time.Now(), + }, + }); err != nil { + t.Fatal(err) + } + if err := testDB.UpdateModuleVersionState(ctx, &ModuleVersionStateForUpdate{ ModulePath: modulePath, Version: version, AppVersion: "app", |
