internal/frontend: fix latest badge for module pages

The latest badge for pageType == "module" and pageType == "std" is
fixed, by removing and unnecessary check in latestMinorVersion.

Fixes golang/go#43203

Change-Id: I94210a9b093064432dc4e300a123be92a1163bbb
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/278534
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Trust: Julie Qiu <julie@golang.org>
diff --git a/internal/frontend/latest_version.go b/internal/frontend/latest_version.go
index e0d2425..c540ffe 100644
--- a/internal/frontend/latest_version.go
+++ b/internal/frontend/latest_version.go
@@ -30,10 +30,10 @@
 // GetLatestMinorVersion returns the latest minor version of the package or module.
 // The linkable form of the minor version is returned and is an empty string on error.
 // It is intended to be used as an argument to middleware.LatestVersions.
-func (s *Server) GetLatestMinorVersion(ctx context.Context, packagePath, modulePath, pageType string) string {
+func (s *Server) GetLatestMinorVersion(ctx context.Context, packagePath, modulePath string) string {
 	// It is okay to use a different DataSource (DB connection) than the rest of the
 	// request, because this makes a self-contained call on the DB.
-	v, err := latestMinorVersion(ctx, s.getDataSource(ctx), packagePath, modulePath, pageType)
+	v, err := latestMinorVersion(ctx, s.getDataSource(ctx), packagePath, modulePath)
 	if err != nil {
 		// We get NotFound errors from directories; they clutter the log.
 		if !errors.Is(err, derrors.NotFound) {
@@ -47,12 +47,8 @@
 
 // TODO(https://github.com/golang/go/issues/40107): this is currently tested in server_test.go, but
 // we should add tests for this function.
-func latestMinorVersion(ctx context.Context, ds internal.DataSource, packagePath, modulePath, pageType string) (_ string, err error) {
-	defer derrors.Wrap(&err, "latestMinorVersion(ctx, %q, %q)", modulePath, packagePath)
-	fullPath := packagePath
-	if pageType == pageTypeModule || pageType == pageTypeModuleStd {
-		fullPath = modulePath
-	}
+func latestMinorVersion(ctx context.Context, ds internal.DataSource, fullPath, modulePath string) (_ string, err error) {
+	defer derrors.Wrap(&err, "latestMinorVersion(ctx, %q, %q)", fullPath, modulePath)
 	um, err := ds.GetUnitMeta(ctx, fullPath, modulePath, internal.LatestVersion)
 	if err != nil {
 		return "", err
diff --git a/internal/frontend/server_test.go b/internal/frontend/server_test.go
index 668f989..285b94c 100644
--- a/internal/frontend/server_test.go
+++ b/internal/frontend/server_test.go
@@ -535,6 +535,22 @@
 		CommitTime:             absoluteTime(sample.NowTruncated()),
 	}
 
+	cloudMod := &pagecheck.Page{
+		ModulePath:             "cloud.google.com/go",
+		ModuleURL:              "cloud.google.com/go",
+		Title:                  "go",
+		Suffix:                 "go",
+		Version:                "v0.69.0",
+		FormattedVersion:       "v0.69.0",
+		LicenseType:            "MIT",
+		LicenseFilePath:        "LICENSE",
+		IsLatestMinor:          true,
+		IsLatestMajor:          true,
+		UnitURLFormat:          "/cloud.google.com/go%s",
+		LatestLink:             "/cloud.google.com/go",
+		LatestMajorVersionLink: "/cloud.google.com/go",
+	}
+
 	pubsubliteDir := &pagecheck.Page{
 		ModulePath:             "cloud.google.com/go",
 		ModuleURL:              "cloud.google.com/go",
@@ -927,6 +943,13 @@
 			want: in("",
 				pagecheck.UnitHeader(pubsubliteDir, versioned, isDirectory)),
 		},
+		{
+			name:           "cloud.google.com/go module",
+			urlPath:        "/cloud.google.com/go",
+			wantStatusCode: http.StatusOK,
+			want: in("",
+				pagecheck.UnitHeader(cloudMod, unversioned, isDirectory)),
+		},
 	}
 }
 
diff --git a/internal/middleware/latestversion.go b/internal/middleware/latestversion.go
index 1953b12..6b793ca 100644
--- a/internal/middleware/latestversion.go
+++ b/internal/middleware/latestversion.go
@@ -27,7 +27,7 @@
 // latestInfoRegexp extracts values needed to determine the latest-version badge from a page's HTML.
 var latestInfoRegexp = regexp.MustCompile(`data-version="([^"]*)" data-mpath="([^"]*)" data-ppath="([^"]*)" data-pagetype="([^"]*)"`)
 
-type latestMinorFunc func(ctx context.Context, packagePath, modulePath, pageType string) string
+type latestMinorFunc func(ctx context.Context, packagePath, modulePath string) string
 type latestMajorFunc func(ctx context.Context, fullPath, modulePath string) (string, string)
 
 // LatestVersions replaces the HTML placeholder values for the badge and banner
@@ -47,8 +47,7 @@
 				modulePath := string(matches[2])
 				_, majorVersion, _ := module.SplitPathVersion(modulePath)
 				packagePath := string(matches[3])
-				pageType := string(matches[4])
-				latestMinorVersion := latestMinor(r.Context(), packagePath, internal.UnknownModulePath, pageType)
+				latestMinorVersion := latestMinor(r.Context(), packagePath, internal.UnknownModulePath)
 				latestMinorClass := "DetailsHeader-badge"
 				switch {
 				case latestMinorVersion == "":
diff --git a/internal/middleware/latestversion_test.go b/internal/middleware/latestversion_test.go
index 0d326ff..01ed123 100644
--- a/internal/middleware/latestversion_test.go
+++ b/internal/middleware/latestversion_test.go
@@ -22,7 +22,7 @@
 	}{
 		{
 			name:   "package version is not latest",
-			latest: func(context.Context, string, string, string) string { return "v1.2.3" },
+			latest: func(context.Context, string, string) string { return "v1.2.3" },
 			in: `
                 <div class="DetailsHeader-badge $$GODISCOVERY_LATESTMINORCLASS$$"
 					 data-version="v1.0.0" data-mpath="p1/p2" data-ppath="p1/p2/p3" data-pagetype="pkg">
@@ -38,7 +38,7 @@
 		},
 		{
 			name:   "package version is latest",
-			latest: func(context.Context, string, string, string) string { return "v1.2.3" },
+			latest: func(context.Context, string, string) string { return "v1.2.3" },
 			in: `
                 <div class="DetailsHeader-badge $$GODISCOVERY_LATESTMINORCLASS$$"
 					 data-version="v1.2.3" data-mpath="p1/p2" data-ppath="p1/p2/p3" data-pagetype="pkg">
@@ -54,7 +54,7 @@
 		},
 		{
 			name:   "package version with build is latest",
-			latest: func(context.Context, string, string, string) string { return "v1.2.3+build" },
+			latest: func(context.Context, string, string) string { return "v1.2.3+build" },
 			in: `
                 <div class="DetailsHeader-badge $$GODISCOVERY_LATESTMINORCLASS$$"
 					 data-version="v1.2.3&#43;build" data-mpath="p1/p2" data-ppath="p1/p2/p3" data-pagetype="pkg">
@@ -70,7 +70,7 @@
 		},
 		{
 			name:   "module version is not latest",
-			latest: func(context.Context, string, string, string) string { return "v1.2.3" },
+			latest: func(context.Context, string, string) string { return "v1.2.3" },
 			in: `
                 <div class="DetailsHeader-badge $$GODISCOVERY_LATESTMINORCLASS$$"
 					 data-version="v1.0.0" data-mpath="p1/p2" data-ppath="" data-pagetype="pkg">
@@ -86,7 +86,7 @@
 		},
 		{
 			name:   "module version is latest",
-			latest: func(context.Context, string, string, string) string { return "v1.2.3" },
+			latest: func(context.Context, string, string) string { return "v1.2.3" },
 			in: `
                 <div class="DetailsHeader-badge $$GODISCOVERY_LATESTMINORCLASS$$"
 					 data-version="v1.2.3" data-mpath="p1/p2" data-ppath="" data-pagetype="pkg">
@@ -102,7 +102,7 @@
 		},
 		{
 			name:   "latest func returns empty string",
-			latest: func(context.Context, string, string, string) string { return "" },
+			latest: func(context.Context, string, string) string { return "" },
 			in: `
                 <div class="DetailsHeader-badge $$GODISCOVERY_LATESTMINORCLASS$$"
 					 data-version="v1.2.3" data-mpath="p1/p2" data-ppath="" data-pagetype="pkg">
@@ -118,7 +118,7 @@
 		},
 		{
 			name:   "no regexp match",
-			latest: func(context.Context, string, string, string) string { return "v1.2.3" },
+			latest: func(context.Context, string, string) string { return "v1.2.3" },
 			in: `
                 <div class="DetailsHeader-badge $$GODISCOVERY_LATESTMINORCLASS$$">
                     <span>Latest</span>
@@ -238,7 +238,7 @@
 			handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 				fmt.Fprint(w, test.in)
 			})
-			latestMinor := func(context.Context, string, string, string) string { return "" }
+			latestMinor := func(context.Context, string, string) string { return "" }
 			ts := httptest.NewServer(LatestVersions(latestMinor, test.latest)(handler))
 			defer ts.Close()
 			resp, err := ts.Client().Get(ts.URL)