From 67f483bf812dbb53ae472097c9f729cd5ebbdd2c Mon Sep 17 00:00:00 2001 From: Miguel Acero Date: Mon, 10 Aug 2020 15:08:37 -0400 Subject: internal/postgres: populate modules.incompatible field This change modifies the InsertModule function to insert modules with an Incompatible field for the new Incompatible column in the modules table. A test is added to check the latest version of inserted modules. Updates golang/go#37714 Change-Id: I7ef04b8709f9499d747d9795531cbc83b5de25ad Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/247757 Reviewed-by: Julie Qiu --- internal/postgres/insert_module_test.go | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'internal/postgres/insert_module_test.go') diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go index db7b9c01..d07f407e 100644 --- a/internal/postgres/insert_module_test.go +++ b/internal/postgres/insert_module_test.go @@ -343,6 +343,67 @@ func TestPostgres_ReadAndWriteModuleOtherColumns(t *testing.T) { } } +func TestLatestVersion(t *testing.T) { + // Verify that finding the latest version of a module prefers + // non-incompatible versions first. + defer ResetTestDB(testDB, t) + ctx := context.Background() + + for _, mod := range []struct { + version string + modulePath string + Incompatible bool + }{ + { + version: "v1.5.2", + modulePath: sample.ModulePath, + }, + { + version: "v2.0.0+incompatible", + modulePath: sample.ModulePath, + }, + { + version: "v2.0.1", + modulePath: sample.ModulePath + "/v2", + }, + } { + m := sample.DefaultModule() + m.Version = mod.version + m.ModulePath = mod.modulePath + + if err := testDB.InsertModule(ctx, m); err != nil { + t.Fatal(err) + } + } + + for _, tc := range []struct { + name string + modulePath string + wantVersion string + }{ + { + name: "test v1 version", + modulePath: sample.ModulePath, + wantVersion: "v1.5.2", + }, + { + name: "test v2 version", + modulePath: sample.ModulePath + "/v2", + wantVersion: "v2.0.1", + }, + } { + t.Run(tc.name, func(t *testing.T) { + isLatest, err := isLatestVersion(ctx, testDB.db, tc.modulePath, tc.wantVersion) + if err != nil { + t.Fatal(err) + } + if !isLatest { + t.Errorf("\n%+v is not the Latest version: %+v", tc.modulePath, tc.wantVersion) + } + }) + } +} + func TestDeleteModule(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() -- cgit v1.3