diff options
| author | Jonathan Amsterdam <jba@google.com> | 2021-09-05 18:21:11 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2021-09-07 14:57:29 +0000 |
| commit | f3da34a449bba5e9ee82f8111c7ed13daeb57824 (patch) | |
| tree | ef5792a6fda02eb8c586e542e1fbe55e31f8cf21 /internal/fetchdatasource | |
| parent | 68f9951c266a11ba307919a0ae193728a3aa74bf (diff) | |
| download | go-x-pkgsite-f3da34a449bba5e9ee82f8111c7ed13daeb57824.tar.xz | |
cmd/pkgsite,internal: serve source
- Set up a /files endpoint on the server that can serve
files from fs.FS implementations.
- Add source.FilesInfo, which returns a source.Info that links to
/files paths. Use it to implement the SourceInfo method of the local
ModuleGetters.
- Add a SourceFS method to the local MethodGetters so they can tell
the server how to serve their files.
- Improve the tests in cmd/pkgsite to verify the source links.
Fixes golang/go#47982
Change-Id: Iff42bad15c4abaf408a364e58b7c0f0dad60b40d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/347932
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/fetchdatasource')
| -rw-r--r-- | internal/fetchdatasource/fetchdatasource_test.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/internal/fetchdatasource/fetchdatasource_test.go b/internal/fetchdatasource/fetchdatasource_test.go index b274da17..7d5ed753 100644 --- a/internal/fetchdatasource/fetchdatasource_test.go +++ b/internal/fetchdatasource/fetchdatasource_test.go @@ -10,6 +10,7 @@ import ( "fmt" "log" "os" + "path" "testing" "time" @@ -339,8 +340,7 @@ func TestLocalGetUnitMeta(t *testing.T) { ctx, ds, teardown := setup(t, defaultTestModules, true) defer teardown() - // TODO(golang/go#47982): use the correct sourceInfo here. - var sourceInfo *source.Info + sourceInfo := source.FilesInfo("XXX") for _, test := range []struct { path, modulePath string @@ -441,9 +441,21 @@ func TestLocalGetUnitMeta(t *testing.T) { if err != nil { t.Fatal(err) } - if diff := cmp.Diff(test.want, got, cmp.AllowUnexported(source.Info{})); diff != "" { + var gotURL string + if got.SourceInfo != nil { + gotURL = got.SourceInfo.RepoURL() + } + wantURL := "/files/*/*/github.com/my/module/" + m, err := path.Match(wantURL, gotURL) + if err != nil { + t.Fatal(err) + } + if !m { + t.Errorf("RepoURL: got %q, want match of %q", gotURL, wantURL) + } + diff := cmp.Diff(test.want, got, cmp.AllowUnexported(source.Info{}), cmpopts.IgnoreFields(source.Info{}, "repoURL")) + if diff != "" { t.Errorf("mismatch (-want +got):\n%s", diff) - } } }) |
