Skip to content

Commit 25c6b92

Browse files
committed
internal: embed ModuleInfo into UnitMeta
UnitMeta had most of the fields of ModuleInfo, but did not embed it. Now that we have added four more fields to ModuleInfo for deprecation and retraction, it makes sense to embed it rather than duplicate those fields. For golang/go#43265 For golang/go#41321 Change-Id: I20e2b922b49c7873a5535745d644631123de37cd Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/296209 Trust: Jonathan Amsterdam <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Julie Qiu <[email protected]>
1 parent 9e8d18f commit 25c6b92

22 files changed

+321
-288
lines changed

internal/fetch/fetch_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type fetchFunc func(t *testing.T, withLicenseDetector bool, ctx context.Context,
4343
func TestMain(m *testing.M) {
4444
dochtml.LoadTemplates(templateSource)
4545
testModules = proxy.LoadTestModules("../proxy/testdata")
46+
licenses.OmitExceptions = true
4647
os.Exit(m.Run())
4748
}
4849

internal/fetch/fetchdata_test.go

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ var moduleOnePackage = &testModule{
7373
fr: &FetchResult{
7474
Module: &internal.Module{
7575
ModuleInfo: internal.ModuleInfo{
76-
ModulePath: "example.com/single",
77-
HasGoMod: true,
78-
SourceInfo: source.NewGitHubInfo("https://example.com/single", "", "v1.0.0"),
76+
ModulePath: "example.com/single",
77+
HasGoMod: true,
78+
SourceInfo: source.NewGitHubInfo("https://example.com/single", "", "v1.0.0"),
79+
IsRedistributable: true,
7980
},
8081
Units: singleUnits,
8182
},
@@ -91,9 +92,10 @@ var moduleNoGoMod = &testModule{
9192
fr: &FetchResult{
9293
Module: &internal.Module{
9394
ModuleInfo: internal.ModuleInfo{
94-
ModulePath: "example.com/nogo",
95-
HasGoMod: false,
96-
SourceInfo: source.NewGitHubInfo("https://example.com/nogo", "", "v1.0.0"),
95+
ModulePath: "example.com/nogo",
96+
HasGoMod: false,
97+
SourceInfo: source.NewGitHubInfo("https://example.com/nogo", "", "v1.0.0"),
98+
IsRedistributable: true,
9799
},
98100
Units: []*internal.Unit{
99101
{
@@ -126,9 +128,10 @@ var moduleMultiPackage = &testModule{
126128
fr: &FetchResult{
127129
Module: &internal.Module{
128130
ModuleInfo: internal.ModuleInfo{
129-
ModulePath: "example.com/multi",
130-
HasGoMod: true,
131-
SourceInfo: source.NewGitHubInfo("https://example.com/multi", "", "v1.0.0"),
131+
ModulePath: "example.com/multi",
132+
HasGoMod: true,
133+
SourceInfo: source.NewGitHubInfo("https://example.com/multi", "", "v1.0.0"),
134+
IsRedistributable: true,
132135
},
133136
Units: []*internal.Unit{
134137
{
@@ -216,7 +219,8 @@ var moduleBadPackages = &testModule{
216219
Status: derrors.ToStatus(derrors.HasIncompletePackages),
217220
Module: &internal.Module{
218221
ModuleInfo: internal.ModuleInfo{
219-
ModulePath: "bad.mod/module",
222+
ModulePath: "bad.mod/module",
223+
IsRedistributable: true,
220224
},
221225
Units: []*internal.Unit{
222226
{
@@ -275,9 +279,10 @@ var moduleBuildConstraints = &testModule{
275279
Status: derrors.ToStatus(derrors.HasIncompletePackages),
276280
Module: &internal.Module{
277281
ModuleInfo: internal.ModuleInfo{
278-
ModulePath: "example.com/build-constraints",
279-
HasGoMod: true,
280-
SourceInfo: source.NewGitHubInfo("https://example.com/build-constraints", "", "v1.0.0"),
282+
ModulePath: "example.com/build-constraints",
283+
HasGoMod: true,
284+
SourceInfo: source.NewGitHubInfo("https://example.com/build-constraints", "", "v1.0.0"),
285+
IsRedistributable: true,
281286
},
282287
Units: []*internal.Unit{
283288
{
@@ -364,9 +369,10 @@ var moduleNonRedist = &testModule{
364369
fr: &FetchResult{
365370
Module: &internal.Module{
366371
ModuleInfo: internal.ModuleInfo{
367-
ModulePath: "example.com/nonredist",
368-
HasGoMod: true,
369-
SourceInfo: source.NewGitHubInfo("https://example.com/nonredist", "", "v1.0.0"),
372+
ModulePath: "example.com/nonredist",
373+
HasGoMod: true,
374+
SourceInfo: source.NewGitHubInfo("https://example.com/nonredist", "", "v1.0.0"),
375+
IsRedistributable: true,
370376
},
371377
Units: []*internal.Unit{
372378
{
@@ -508,8 +514,9 @@ var moduleDocTest = &testModule{
508514
GoModPath: "doc.test",
509515
Module: &internal.Module{
510516
ModuleInfo: internal.ModuleInfo{
511-
ModulePath: "doc.test",
512-
HasGoMod: false,
517+
ModulePath: "doc.test",
518+
HasGoMod: false,
519+
IsRedistributable: true,
513520
},
514521
Units: []*internal.Unit{
515522
{
@@ -554,8 +561,9 @@ var moduleDocTooLarge = &testModule{
554561
GoModPath: "bigdoc.test",
555562
Module: &internal.Module{
556563
ModuleInfo: internal.ModuleInfo{
557-
ModulePath: "bigdoc.test",
558-
HasGoMod: false,
564+
ModulePath: "bigdoc.test",
565+
HasGoMod: false,
566+
IsRedistributable: true,
559567
},
560568
Units: []*internal.Unit{
561569
{
@@ -602,8 +610,9 @@ var moduleWasm = &testModule{
602610
fr: &FetchResult{
603611
Module: &internal.Module{
604612
ModuleInfo: internal.ModuleInfo{
605-
ModulePath: "github.com/my/module/js",
606-
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "js", "js/v1.0.0"),
613+
ModulePath: "github.com/my/module/js",
614+
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "js", "js/v1.0.0"),
615+
IsRedistributable: true,
607616
},
608617
Units: []*internal.Unit{
609618
{
@@ -654,20 +663,24 @@ var moduleStdMaster = &testModule{
654663
ResolvedVersion: stdlib.TestVersion,
655664
Module: &internal.Module{
656665
ModuleInfo: internal.ModuleInfo{
657-
ModulePath: stdlib.ModulePath,
658-
Version: stdlib.TestVersion,
659-
CommitTime: stdlib.TestCommitTime,
660-
HasGoMod: true,
661-
SourceInfo: source.NewStdlibInfo("master"),
666+
ModulePath: stdlib.ModulePath,
667+
Version: stdlib.TestVersion,
668+
CommitTime: stdlib.TestCommitTime,
669+
HasGoMod: true,
670+
SourceInfo: source.NewStdlibInfo("master"),
671+
IsRedistributable: true,
662672
},
663673
Units: []*internal.Unit{
664674
{
665675
UnitMeta: internal.UnitMeta{
666676
Path: "errors",
667677
Name: "errors",
668678
IsRedistributable: true,
669-
Version: stdlib.TestVersion,
670-
ModulePath: stdlib.ModulePath,
679+
ModuleInfo: internal.ModuleInfo{
680+
Version: stdlib.TestVersion,
681+
ModulePath: stdlib.ModulePath,
682+
IsRedistributable: true,
683+
},
671684
},
672685
Documentation: []*internal.Documentation{
673686
{
@@ -691,8 +704,11 @@ var moduleStdMaster = &testModule{
691704
UnitMeta: internal.UnitMeta{
692705
Path: "std",
693706
IsRedistributable: true,
694-
Version: stdlib.TestVersion,
695-
ModulePath: "std",
707+
ModuleInfo: internal.ModuleInfo{
708+
Version: stdlib.TestVersion,
709+
ModulePath: "std",
710+
IsRedistributable: true,
711+
},
696712
},
697713
Readme: &internal.Readme{Filepath: "README.md", Contents: "# The Go Programming Language\n"},
698714
},
@@ -719,11 +735,12 @@ var moduleStd = &testModule{
719735
fr: &FetchResult{
720736
Module: &internal.Module{
721737
ModuleInfo: internal.ModuleInfo{
722-
ModulePath: "std",
723-
Version: "v1.12.5",
724-
CommitTime: stdlib.TestCommitTime,
725-
HasGoMod: true,
726-
SourceInfo: source.NewStdlibInfo("v1.12.5"),
738+
ModulePath: "std",
739+
Version: "v1.12.5",
740+
CommitTime: stdlib.TestCommitTime,
741+
HasGoMod: true,
742+
SourceInfo: source.NewStdlibInfo("v1.12.5"),
743+
IsRedistributable: true,
727744
},
728745
Units: []*internal.Unit{
729746
{
@@ -2365,8 +2382,9 @@ package example_test
23652382
GoModPath: path,
23662383
Module: &internal.Module{
23672384
ModuleInfo: internal.ModuleInfo{
2368-
ModulePath: path,
2369-
HasGoMod: false,
2385+
ModulePath: path,
2386+
HasGoMod: false,
2387+
IsRedistributable: true,
23702388
},
23712389
Units: []*internal.Unit{
23722390
{

internal/fetch/helper_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ func cleanFetchResult(t *testing.T, fr *FetchResult) *FetchResult {
5353
shouldSetPVS := (fr.PackageVersionStates == nil)
5454
for _, u := range fr.Module.Units {
5555
u.UnitMeta = internal.UnitMeta{
56-
ModulePath: fr.Module.ModulePath,
57-
Version: fr.Module.Version,
56+
ModuleInfo: internal.ModuleInfo{
57+
ModulePath: fr.Module.ModulePath,
58+
Version: fr.Module.Version,
59+
IsRedistributable: fr.Module.IsRedistributable,
60+
},
5861
Path: u.Path,
5962
Name: u.Name,
6063
IsRedistributable: u.IsRedistributable,

internal/fetch/unit.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ func moduleUnits(modulePath, version string,
4848
}
4949
dir := &internal.Unit{
5050
UnitMeta: internal.UnitMeta{
51-
ModulePath: modulePath,
52-
Version: version,
51+
ModuleInfo: internal.ModuleInfo{
52+
ModulePath: modulePath,
53+
Version: version,
54+
IsRedistributable: d.ModuleIsRedistributable(),
55+
},
5356
Path: dirPath,
5457
IsRedistributable: isRedist,
5558
Licenses: meta,

internal/frontend/imports.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ type ImportsDetails struct {
3636
// pkgPath, modulePath and version from the database and returns a ImportsDetails.
3737
func fetchImportsDetails(ctx context.Context, ds internal.DataSource, pkgPath, modulePath, resolvedVersion string) (_ *ImportsDetails, err error) {
3838
u, err := ds.GetUnit(ctx, &internal.UnitMeta{
39-
Path: pkgPath,
40-
ModulePath: modulePath,
41-
Version: resolvedVersion,
39+
Path: pkgPath,
40+
ModuleInfo: internal.ModuleInfo{
41+
ModulePath: modulePath,
42+
Version: resolvedVersion,
43+
},
4244
}, internal.WithImports)
4345
if err != nil {
4446
return nil, err

internal/frontend/license_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ func TestFetchLicensesDetails(t *testing.T) {
142142
wantDetails := &LicensesDetails{Licenses: transformLicenses(
143143
test.modulePath, test.version, test.want)}
144144
got, err := fetchLicensesDetails(ctx, testDB, &internal.UnitMeta{
145-
Path: test.fullPath,
146-
ModulePath: test.modulePath,
147-
Version: test.version,
145+
Path: test.fullPath,
146+
ModuleInfo: internal.ModuleInfo{
147+
ModulePath: test.modulePath,
148+
Version: test.version,
149+
},
148150
})
149151
if err != nil {
150152
t.Fatal(err)

internal/frontend/readme_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ func TestReadme(t *testing.T) {
190190
{
191191
name: "relative image markdown is made absolute for GitHub",
192192
unit: &internal.Unit{
193-
UnitMeta: internal.UnitMeta{SourceInfo: source.NewGitHubInfo("http://github.com/golang/go", "", "master")},
193+
UnitMeta: internal.UnitMeta{
194+
ModuleInfo: internal.ModuleInfo{
195+
SourceInfo: source.NewGitHubInfo("http://github.com/golang/go", "", "master"),
196+
},
197+
},
194198
},
195199
readme: &internal.Readme{
196200
Filepath: "README.md",
@@ -202,7 +206,11 @@ func TestReadme(t *testing.T) {
202206
{
203207
name: "relative image markdown is made absolute for GitHub, .git removed from repo URL",
204208
unit: &internal.Unit{
205-
UnitMeta: internal.UnitMeta{SourceInfo: source.NewGitHubInfo("https://github.com/robpike/ivy.git", "", "v0.1.0")},
209+
UnitMeta: internal.UnitMeta{
210+
ModuleInfo: internal.ModuleInfo{
211+
SourceInfo: source.NewGitHubInfo("https://github.com/robpike/ivy.git", "", "v0.1.0"),
212+
},
213+
},
206214
},
207215
readme: &internal.Readme{
208216
Filepath: "README.md",
@@ -294,8 +302,10 @@ func TestReadme(t *testing.T) {
294302
name: "image link with bad URL",
295303
unit: &internal.Unit{
296304
UnitMeta: internal.UnitMeta{
297-
Version: "v1.2.3",
298-
SourceInfo: source.NewGitHubInfo("https://github.com/some/<script>", "", "v1.2.3"),
305+
ModuleInfo: internal.ModuleInfo{
306+
Version: "v1.2.3",
307+
SourceInfo: source.NewGitHubInfo("https://github.com/some/<script>", "", "v1.2.3"),
308+
},
299309
},
300310
},
301311
readme: &internal.Readme{

internal/frontend/search_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ func TestFetchSearchPage(t *testing.T) {
3434
Units: []*internal.Unit{
3535
{
3636
UnitMeta: internal.UnitMeta{
37+
ModuleInfo: internal.ModuleInfo{
38+
ModulePath: "github.com/mod/foo",
39+
Version: "v1.0.0",
40+
CommitTime: now,
41+
IsRedistributable: true,
42+
},
3743
Name: "foo",
3844
Path: "github.com/mod/foo",
3945
Licenses: sample.LicenseMetadata(),
40-
CommitTime: now,
41-
ModulePath: "github.com/mod/foo",
42-
Version: "v1.0.0",
4346
IsRedistributable: true,
4447
},
4548
Documentation: []*internal.Documentation{{
@@ -65,12 +68,15 @@ func TestFetchSearchPage(t *testing.T) {
6568
Units: []*internal.Unit{
6669
{
6770
UnitMeta: internal.UnitMeta{
71+
ModuleInfo: internal.ModuleInfo{
72+
CommitTime: now,
73+
ModulePath: "github.com/mod/bar",
74+
Version: "v1.0.0",
75+
IsRedistributable: true,
76+
},
6877
Name: "bar",
6978
Path: "github.com/mod/bar",
7079
Licenses: sample.LicenseMetadata(),
71-
CommitTime: now,
72-
ModulePath: "github.com/mod/bar",
73-
Version: "v1.0.0",
7480
IsRedistributable: true,
7581
},
7682
Documentation: []*internal.Documentation{{

internal/frontend/unit_main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestGetNestedModules(t *testing.T) {
105105
t.Run(test.modulePath, func(t *testing.T) {
106106
got, err := getNestedModules(ctx, testDB, &internal.UnitMeta{
107107
Path: test.modulePath,
108-
ModulePath: test.modulePath,
108+
ModuleInfo: internal.ModuleInfo{ModulePath: test.modulePath},
109109
}, test.subdirectories)
110110
if err != nil {
111111
t.Fatal(err)

internal/frontend/unit_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ func TestCanonicalURLPath(t *testing.T) {
6464
} {
6565
um := &internal.UnitMeta{
6666
Path: test.path,
67-
ModulePath: test.modpath,
68-
Version: test.version,
67+
ModuleInfo: internal.ModuleInfo{ModulePath: test.modpath, Version: test.version},
6968
}
7069
got := canonicalURLPath(um)
7170
if got != test.want {

internal/localdatasource/datasource.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ func (ds *DataSource) GetUnitMeta(ctx context.Context, path, requestedModulePath
137137
ds.mu.Unlock()
138138

139139
um := &internal.UnitMeta{
140-
Path: path,
141-
ModulePath: requestedModulePath,
142-
Version: fetch.LocalVersion,
143-
CommitTime: fetch.LocalCommitTime,
140+
Path: path,
141+
ModuleInfo: internal.ModuleInfo{
142+
ModulePath: requestedModulePath,
143+
Version: fetch.LocalVersion,
144+
CommitTime: fetch.LocalCommitTime,
145+
IsRedistributable: module.IsRedistributable,
146+
},
144147
}
145148

146149
for _, u := range module.Units {

0 commit comments

Comments
 (0)