internal/worker: replace legacy structs in TestReFetch
TestReFetch now uses Unit and UnitMeta instead of LegacyPackage and
LegacyVersionedPackage.
For golang/go#39629
Change-Id: I028c3b7900bb8259734aa694f60803fe158914f3
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258309
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>
diff --git a/internal/worker/refetch_test.go b/internal/worker/refetch_test.go
index efcf519..862798e 100644
--- a/internal/worker/refetch_test.go
+++ b/internal/worker/refetch_test.go
@@ -64,7 +64,7 @@
t.Fatalf("FetchAndUpdateState(%q, %q, %v, %v, %v): %v", sample.ModulePath, version, proxyClient, sourceClient, testDB, err)
}
- if _, err := testDB.LegacyGetPackage(ctx, pkgFoo, internal.UnknownModulePath, version); err != nil {
+ if _, err := testDB.GetUnitMeta(ctx, pkgFoo, internal.UnknownModulePath, version); err != nil {
t.Error(err)
}
@@ -81,39 +81,52 @@
if _, err := FetchAndUpdateState(ctx, sample.ModulePath, version, proxyClient, sourceClient, testDB, testAppVersion); err != nil {
t.Fatalf("FetchAndUpdateState(%q, %q, %v, %v, %v): %v", modulePath, version, proxyClient, sourceClient, testDB, err)
}
- want := &internal.LegacyVersionedPackage{
- LegacyModuleInfo: internal.LegacyModuleInfo{
- ModuleInfo: internal.ModuleInfo{
- ModulePath: sample.ModulePath,
- Version: version,
- CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC),
- IsRedistributable: true,
- HasGoMod: false,
- SourceInfo: source.NewGitHubInfo("https://"+sample.ModulePath, "", sample.VersionString),
- },
- LegacyReadmeFilePath: "README.md",
- LegacyReadmeContents: "This is a readme",
- },
- LegacyPackage: internal.LegacyPackage{
+ want := &internal.Unit{
+ UnitMeta: internal.UnitMeta{
+ ModulePath: sample.ModulePath,
+ Version: version,
+ CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC),
+ IsRedistributable: true,
+ SourceInfo: source.NewGitHubInfo("https://"+sample.ModulePath, "", sample.VersionString),
Path: sample.ModulePath + "/bar",
Name: "bar",
- Synopsis: "Package bar",
- DocumentationHTML: html("Bar returns the string "bar"."),
- V1Path: sample.ModulePath + "/bar",
Licenses: []*licenses.Metadata{
{Types: []string{"MIT"}, FilePath: "LICENSE"},
},
- IsRedistributable: true,
- GOOS: "linux",
- GOARCH: "amd64",
+ },
+ Readme: &internal.Readme{
+ Filepath: "README.md",
+ Contents: "This is a readme",
+ },
+ Documentation: &internal.Documentation{
+ Synopsis: "Package bar",
+ HTML: html("Bar returns the string "bar"."),
+ GOOS: "linux",
+ GOARCH: "amd64",
},
}
- got, err := testDB.LegacyGetPackage(ctx, pkgBar, internal.UnknownModulePath, version)
+ got, err := testDB.GetUnitMeta(ctx, pkgBar, internal.UnknownModulePath, version)
if err != nil {
t.Fatal(err)
}
- if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(internal.LegacyPackage{}, "DocumentationHTML"), cmp.AllowUnexported(source.Info{})); diff != "" {
- t.Errorf("testDB.LegacyGetPackage(ctx, %q, %q) mismatch (-want +got):\n%s", pkgBar, version, diff)
+ if diff := cmp.Diff(want.UnitMeta, *got, cmp.AllowUnexported(source.Info{})); diff != "" {
+ t.Fatalf("testDB.GetUnitMeta(ctx, %q, %q) mismatch (-want +got):\n%s", want.ModulePath, want.Version, diff)
+ }
+
+ gotPkg, err := testDB.GetUnit(ctx, got, internal.WithReadme|internal.WithDocumentation)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if diff := cmp.Diff(want, gotPkg,
+ cmp.AllowUnexported(source.Info{}),
+ cmpopts.IgnoreFields(internal.Unit{}, "Documentation")); diff != "" {
+ t.Errorf("mismatch on readme (-want +got):\n%s", diff)
+ }
+ if got, want := gotPkg.Documentation, want.Documentation; got == nil || want == nil {
+ if got != want {
+ t.Fatalf("mismatch on documentation: got: %v\nwant: %v", got, want)
+ }
+ return
}
// Now re-fetch and verify that contents were overwritten.