aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module_test.go
diff options
context:
space:
mode:
authorJulie Qiu <julie@golang.org>2021-07-01 18:55:31 -0400
committerJulie Qiu <julie@golang.org>2021-07-13 16:26:28 +0000
commitc1fa4f41069c5a8861fc2d0c0207fa34b7b5dc2d (patch)
treec4bcb2dfa13fb2f351e85eb1e21dacf7e459bc44 /internal/postgres/insert_module_test.go
parent01e3e3198312fe6a30cf012b4d06bee6872f7ef8 (diff)
downloadgo-x-pkgsite-c1fa4f41069c5a8861fc2d0c0207fa34b7b5dc2d.tar.xz
internal/postgres: fix bug in isAlternativeModule
At the moment, isAlternativeModulePath does not filter on the modulePath argument, which means that it reports whether the latest version of a random module has status 491, and not the specified module. This bug is fixed and a test is added. Change-Id: I7a0feb960e1f1e6b7de2fb7a82ec0ea2fdcce738 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/332378 Trust: Julie Qiu <julie@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/postgres/insert_module_test.go')
-rw-r--r--internal/postgres/insert_module_test.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 0ec29eb2..699301e3 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -620,24 +620,26 @@ func TestIsAlternativeModulePath(t *testing.T) {
testDB, release := acquire(t)
defer release()
- const modulePath = "m.com/a"
+ const modulePathA = "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
+ modulePath string
+ 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
+ {"a.com", "v1.4.0", altModuleStatus, false}, // preseeding a different module should not change result for modulePathA
+ {modulePathA, "v1.2.0", 200, false}, // no 491s
+ {modulePathA, "v1.1.0", altModuleStatus, false}, // 491 is earlier
+ {modulePathA, "v1.3.0-pre", altModuleStatus, false}, // still earlier: release beats pre-release
+ {modulePathA, "v1.3.0", altModuleStatus, true}, // latest version is 491
+ {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, modulePath, test.version, "")
+ addLatest(ctx, t, testDB, test.modulePath, test.version, "")
if err := testDB.UpsertModuleVersionState(ctx, &ModuleVersionStateForUpsert{
- ModulePath: modulePath,
+ ModulePath: test.modulePath,
Version: test.version,
AppVersion: "appVersion",
Timestamp: time.Now(),
@@ -647,12 +649,12 @@ func TestIsAlternativeModulePath(t *testing.T) {
t.Fatal(err)
}
- got, err := isAlternativeModulePath(ctx, testDB.db, modulePath)
+ got, err := isAlternativeModulePath(ctx, testDB.db, modulePathA)
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)
+ t.Fatalf("%s@%s, %d: got %t, want %t", test.modulePath, test.version, test.status, got, test.want)
}
}
}