aboutsummaryrefslogtreecommitdiff
path: root/internal/fetchdatasource
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-08-26 05:51:46 -0400
committerJonathan Amsterdam <jba@google.com>2021-08-26 13:55:09 +0000
commit0eeccf082fa68b8e061bdd376a923e04d6073d0f (patch)
tree57a860895f5cd76f83f18caf76cb7c27a68864fa /internal/fetchdatasource
parentac26f27d709d79ebdecdd54b17fb285579d96377 (diff)
downloadgo-x-pkgsite-0eeccf082fa68b8e061bdd376a923e04d6073d0f.tar.xz
internal/fetchdatasource: GetUnitMeta returns NotFound on missing package
If a module exists but the package path is not in it, return NotFound. For golang/go#47780 Change-Id: If3a6602df4b99c8470020e8538e01c685880d86d Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/345251 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/fetchdatasource')
-rw-r--r--internal/fetchdatasource/fetchdatasource.go8
-rw-r--r--internal/fetchdatasource/fetchdatasource_test.go13
2 files changed, 14 insertions, 7 deletions
diff --git a/internal/fetchdatasource/fetchdatasource.go b/internal/fetchdatasource/fetchdatasource.go
index 69f803eb..fe2eacca 100644
--- a/internal/fetchdatasource/fetchdatasource.go
+++ b/internal/fetchdatasource/fetchdatasource.go
@@ -181,10 +181,12 @@ func (ds *FetchDataSource) GetUnitMeta(ctx context.Context, path, requestedModul
Path: path,
ModuleInfo: module.ModuleInfo,
}
- if u := findUnit(module, path); u != nil {
- um.Name = u.Name
- um.IsRedistributable = u.IsRedistributable
+ u := findUnit(module, path)
+ if u == nil {
+ return nil, derrors.NotFound
}
+ um.Name = u.Name
+ um.IsRedistributable = u.IsRedistributable
return um, nil
}
diff --git a/internal/fetchdatasource/fetchdatasource_test.go b/internal/fetchdatasource/fetchdatasource_test.go
index a1fc95cf..995dfad9 100644
--- a/internal/fetchdatasource/fetchdatasource_test.go
+++ b/internal/fetchdatasource/fetchdatasource_test.go
@@ -309,10 +309,9 @@ func TestGetLatestInfo(t *testing.T) {
wantErr: derrors.NotFound,
},
{
- fullPath: "foo.com/bar/baz",
- modulePath: "foo.com/bar",
- wantModulePath: "foo.com/bar/v3",
- wantPackagePath: "foo.com/bar/v3",
+ fullPath: "foo.com/bar/baz",
+ modulePath: "foo.com/bar",
+ wantErr: derrors.NotFound,
},
{
fullPath: "incompatible.com/bar",
@@ -424,6 +423,12 @@ func TestLocalGetUnitMeta(t *testing.T) {
modulePath: stdlib.ModulePath,
wantErr: derrors.InvalidArgument,
},
+ {
+ // Module is known but path isn't in it.
+ path: "github.com/my/module/unk",
+ modulePath: "github.com/my/module",
+ wantErr: derrors.NotFound,
+ },
} {
t.Run(test.path, func(t *testing.T) {
got, err := ds.GetUnitMeta(ctx, test.path, test.modulePath, fetch.LocalVersion)