internal/frontend: added tests for frontend.LatestVersion

Added tests for frontend.latestMinorVersion

Fixes golang/go#40107

Change-Id: I568f9f8e193ebd6b280be1e8c7ff52cacc9407eb
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/278752
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Trust: Jamal Carvalho <jamal@golang.org>
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/internal/frontend/latest_version_test.go b/internal/frontend/latest_version_test.go
new file mode 100644
index 0000000..12c866c
--- /dev/null
+++ b/internal/frontend/latest_version_test.go
@@ -0,0 +1,72 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package frontend
+
+import (
+	"context"
+	"fmt"
+	"testing"
+
+	"golang.org/x/pkgsite/internal"
+	"golang.org/x/pkgsite/internal/postgres"
+	"golang.org/x/pkgsite/internal/testing/sample"
+)
+
+func TestLatestMinorVersion(t *testing.T) {
+	defer postgres.ResetTestDB(testDB, t)
+	var persistedModules = []testModule{
+		{
+			path:            "github.com/mymodule/av1module",
+			redistributable: true,
+			versions:        []string{"v1.0.0", "v1.0.1"},
+			packages: []testPackage{
+				{
+					suffix:         "bar",
+					doc:            sample.DocumentationHTML.String(),
+					readmeContents: sample.ReadmeContents,
+					readmeFilePath: sample.ReadmeFilePath,
+				},
+			},
+		},
+	}
+	tt := []struct {
+		name             string
+		fullPath         string
+		modulePath       string
+		wantMinorVersion string
+		wantErr          error
+	}{
+		{
+			name:             "get latest minor version for a persisted module",
+			fullPath:         "github.com/mymodule/av1module",
+			modulePath:       internal.UnknownModulePath,
+			wantMinorVersion: "v1.0.1",
+			wantErr:          nil,
+		},
+		{
+			name:             "module does not exist",
+			fullPath:         "github.com/mymodule/doesnotexist",
+			modulePath:       internal.UnknownModulePath,
+			wantMinorVersion: "",
+			wantErr:          fmt.Errorf("error while retriving minor version"),
+		},
+	}
+	ctx := context.Background()
+	insertTestModules(ctx, t, persistedModules)
+	for _, tc := range tt {
+		t.Run(tc.name, func(t *testing.T) {
+			v, err := latestMinorVersion(ctx, testDB, tc.fullPath, tc.modulePath)
+			if err != nil {
+				if tc.wantErr == nil {
+					t.Fatalf("got %v, want no error", err)
+				}
+				return
+			}
+			if v != tc.wantMinorVersion {
+				t.Fatalf("got %q, want %q", tc.wantMinorVersion, v)
+			}
+		})
+	}
+}