Stephen McQuay (smcquay)
479ef2b786
This allows godoc.org to work on nested packages. As it stood gddo would fail trying to find nested packages. Let's say we have a vaind with this route: go.mcquay.me/vain -> https://s.mcquay.me/sm/vain Asking godoc for go.mcquay.me/vain would work fine. However trying to get documentation for go.mcquay.me/vain/errors (nested package) would return 404 since it wouldn't match known paths exactly. Since now we match and return "go.mcquay.me/vain" for the full path, gddo is able to use local caches for its information. Change-Id: I599a75898493734fc652e507f477c11b1b1b13e8
81 lines
1.2 KiB
Go
81 lines
1.2 KiB
Go
package vain
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestPartialPackage(t *testing.T) {
|
|
db, done := TestDB(t)
|
|
if db == nil {
|
|
t.Fatalf("could not create temp db")
|
|
}
|
|
defer done()
|
|
|
|
paths := []path{
|
|
"a/b",
|
|
"a/c",
|
|
"a/d/c",
|
|
"a/d/e",
|
|
|
|
"f/b/c/d",
|
|
"f/b/c/e",
|
|
}
|
|
|
|
for _, p := range paths {
|
|
db.Packages[p] = Package{Path: string(p)}
|
|
}
|
|
|
|
tests := []struct {
|
|
pth string
|
|
pkg Package
|
|
err error
|
|
}{
|
|
// obvious
|
|
{
|
|
pth: "a/b",
|
|
pkg: db.Packages["a/b"],
|
|
},
|
|
{
|
|
pth: "a/d/c",
|
|
pkg: db.Packages["a/d/c"],
|
|
},
|
|
|
|
// here we exercise the code that matches closest submatch
|
|
{
|
|
pth: "a/b/c",
|
|
pkg: db.Packages["a/b"],
|
|
},
|
|
{
|
|
pth: "f/b/c/d/e/f/g",
|
|
pkg: db.Packages["f/b/c/d"],
|
|
},
|
|
|
|
// some errors
|
|
{
|
|
pth: "foo",
|
|
err: errors.New("shouldn't find"),
|
|
},
|
|
|
|
{
|
|
pth: "a/d/f",
|
|
err: errors.New("shouldn't find"),
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
p, err := db.Package(test.pth)
|
|
|
|
if got, want := p, test.pkg; got != want {
|
|
t.Errorf("bad package fetched: got %+v, want %+v", got, want)
|
|
}
|
|
|
|
got := err
|
|
want := test.err
|
|
if (got == nil) != (want == nil) {
|
|
t.Errorf("unexpected error; got %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
}
|