aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module_test.go
diff options
context:
space:
mode:
authorMiguel Acero <acero@google.com>2020-08-10 15:08:37 -0400
committerMiguel Acero <acero@google.com>2020-08-13 20:20:06 +0000
commit67f483bf812dbb53ae472097c9f729cd5ebbdd2c (patch)
tree9485ca705f5f6eaf0c643ca7f22b774acadfaf7c /internal/postgres/insert_module_test.go
parenta1b9579989302b4f1ba71cd3bbb0ca0364ab09d4 (diff)
downloadgo-x-pkgsite-67f483bf812dbb53ae472097c9f729cd5ebbdd2c.tar.xz
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 <julie@golang.org>
Diffstat (limited to 'internal/postgres/insert_module_test.go')
-rw-r--r--internal/postgres/insert_module_test.go61
1 files changed, 61 insertions, 0 deletions
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()