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>
diff --git a/internal/fetchdatasource/fetchdatasource.go b/internal/fetchdatasource/fetchdatasource.go
index 69f803e..fe2eacc 100644
--- a/internal/fetchdatasource/fetchdatasource.go
+++ b/internal/fetchdatasource/fetchdatasource.go
@@ -181,10 +181,12 @@
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 a1fc95c..995dfad 100644
--- a/internal/fetchdatasource/fetchdatasource_test.go
+++ b/internal/fetchdatasource/fetchdatasource_test.go
@@ -309,10 +309,9 @@
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 @@
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)