aboutsummaryrefslogtreecommitdiff
path: root/internal/worker/refetch_test.go
diff options
context:
space:
mode:
authorJulie Qiu <julie@golang.org>2020-09-29 23:51:25 -0400
committerJulie Qiu <julie@golang.org>2020-09-30 16:39:24 +0000
commit59efc33da339b3591d07f96a26d6ce525f07cf52 (patch)
tree7502d517fe7bc14d4fba05fcb9fbc7281d739293 /internal/worker/refetch_test.go
parent63c987f4fa01f6be7305b508529c7d7bf5256cba (diff)
downloadgo-x-pkgsite-59efc33da339b3591d07f96a26d6ce525f07cf52.tar.xz
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>
Diffstat (limited to 'internal/worker/refetch_test.go')
-rw-r--r--internal/worker/refetch_test.go61
1 files changed, 37 insertions, 24 deletions
diff --git a/internal/worker/refetch_test.go b/internal/worker/refetch_test.go
index efcf5199..862798e3 100644
--- a/internal/worker/refetch_test.go
+++ b/internal/worker/refetch_test.go
@@ -64,7 +64,7 @@ func TestReFetch(t *testing.T) {
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 @@ func TestReFetch(t *testing.T) {
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 &#34;bar&#34;."),
- 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 &#34;bar&#34;."),
+ 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.