diff options
| author | Julie Qiu <julie@golang.org> | 2021-01-19 12:00:24 -0500 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2021-01-19 19:32:23 +0000 |
| commit | e2c2bf53d665a88f4937cdc20b5cce4a64c009ea (patch) | |
| tree | ace85a8149064a8cdf644e40fac3a25ed109c102 /internal/postgres/path_test.go | |
| parent | 5b39ce470fd5c9481017a281aa03715692847919 (diff) | |
| download | go-x-pkgsite-e2c2bf53d665a88f4937cdc20b5cce4a64c009ea.tar.xz | |
internal: delete experiment not-at-v1
Additionally, only redirect if the non-v1 path does not match the full
path, and is actually a non-v1 path.
Otherwise, this will redirect requests to <path>@<missing-version> to
<path>@latest, or <path>/v3 to <path>, instead of return a 404 that
allows the user to fetch the missing version.
Change-Id: I66946062d341477fdc19bfc2a0f18b848943807d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/284580
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/postgres/path_test.go')
| -rw-r--r-- | internal/postgres/path_test.go | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/internal/postgres/path_test.go b/internal/postgres/path_test.go index bdadb276..cf7dbacc 100644 --- a/internal/postgres/path_test.go +++ b/internal/postgres/path_test.go @@ -6,6 +6,8 @@ package postgres import ( "context" + "strconv" + "strings" "testing" "golang.org/x/pkgsite/internal/testing/sample" @@ -15,18 +17,27 @@ func TestGetLatestMajorPathForV1Path(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() - checkLatest := func(t *testing.T, versions []string, v1path string, wantVersion string) { + checkLatest := func(t *testing.T, versions []string, v1path string, version, suffix string) { t.Helper() - got, err := testDB.GetLatestMajorPathForV1Path(ctx, v1path) + gotPath, gotVer, err := testDB.GetLatestMajorPathForV1Path(ctx, v1path) if err != nil { t.Fatal(err) } want := sample.ModulePath - if wantVersion != "" { - want = want + "/" + wantVersion + if suffix != "" { + want = want + "/" + suffix } - if got != want { - t.Errorf("GetLatestMajorPathForV1Path(%q) = %q, want %q", v1path, got, want) + var wantVer int + if version == "" { + wantVer = 1 + } else { + wantVer, err = strconv.Atoi(strings.TrimPrefix(version, "v")) + if err != nil { + t.Fatal(err) + } + } + if gotPath != want || gotVer != wantVer { + t.Errorf("GetLatestMajorPathForV1Path(%q) = %q, %d, want %q, %d", v1path, gotPath, gotVer, want, wantVer) } } @@ -71,14 +82,15 @@ func TestGetLatestMajorPathForV1Path(t *testing.T) { } t.Run("module", func(t *testing.T) { v1path := sample.ModulePath - checkLatest(t, test.versions, v1path, test.want) + checkLatest(t, test.versions, v1path, test.want, test.want) }) t.Run("package", func(t *testing.T) { + want := test.want if test.want != "" { - test.want += "/" + want += "/" } v1path := sample.ModulePath + "/" + suffix - checkLatest(t, test.versions, v1path, test.want+suffix) + checkLatest(t, test.versions, v1path, test.want, want+suffix) }) }) } |
