x/pkgsite:additional testcase to TestCreatePackage
TestCreatePackage only tests for cases where isLatest = false.
This commit adds testcase with isLatest = true.
Fixes golang/go#40941
@@ -37,6 +37,7 @@ func samplePackage(mutators ...func(*Package)) *Package {
p.Module.URL = constructModuleURL(p.ModulePath, p.LinkVersion)
p.LatestURL = constructPackageURL(p.Path, p.ModulePath, middleware.LatestVersionPlaceholder)
p.Module.LatestURL = constructModuleURL(p.ModulePath, middleware.LatestVersionPlaceholder)
+ p.Module.LinkVersion = linkVersion(sample.VersionString, sample.ModulePath)
return p
}
@@ -105,21 +106,33 @@ func TestCreatePackage(t *testing.T) {
for _, tc := range []struct {
label string
pkg *internal.LegacyVersionedPackage
+ linkVersion bool
wantPkg *Package
}{
{
label: "simple package",
pkg: vpkg(sample.ModulePath, sample.Suffix, ""),
+ linkVersion: false,
wantPkg: samplePackage(),
},
+ {
+ label: "simple package, latest",
+ pkg: vpkg(sample.ModulePath, sample.Suffix, ""),
+ linkVersion: true,
+ wantPkg: samplePackage(func(p *Package) {
+ p.LinkVersion = internal.LatestVersion
+ }),
+ },
{
label: "command package",
pkg: vpkg(sample.ModulePath, sample.Suffix, "main"),
+ linkVersion: false,
wantPkg: samplePackage(),
},
{
label: "v2 command",
pkg: vpkg("pa.th/to/foo/v2", "bar", "main"),
+ linkVersion: false,
wantPkg: samplePackage(func(p *Package) {
p.Path = "pa.th/to/foo/v2/bar"
p.ModulePath = "pa.th/to/foo/v2"
@@ -128,6 +141,7 @@ func TestCreatePackage(t *testing.T) {
{
label: "explicit v1 command",
pkg: vpkg("pa.th/to/foo/v1", "", "main"),
+ linkVersion: false,
wantPkg: samplePackage(func(p *Package) {
p.Path = "pa.th/to/foo/v1"
p.ModulePath = "pa.th/to/foo/v1"
@@ -136,7 +150,7 @@ func TestCreatePackage(t *testing.T) {
} {
t.Run(tc.label, func(t *testing.T) {
pm := internal.PackageMetaFromLegacyPackage(&tc.pkg.LegacyPackage)
- got, err := createPackage(pm, &tc.pkg.ModuleInfo, false)
+ got, err := createPackage(pm, &tc.pkg.ModuleInfo, tc.linkVersion)
if err != nil {
t.Fatal(err)
}
