2020-05-15 18:53:24 +03:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package frontend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/pkgsite/internal/postgres"
|
|
|
|
"golang.org/x/pkgsite/internal/stdlib"
|
|
|
|
"golang.org/x/pkgsite/internal/testing/sample"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStdlibPathForShortcut(t *testing.T) {
|
|
|
|
defer postgres.ResetTestDB(testDB, t)
|
|
|
|
|
|
|
|
m := sample.Module(stdlib.ModulePath, "v1.2.3",
|
|
|
|
"encoding/json", // one match for "json"
|
|
|
|
"text/template", "html/template", // two matches for "template"
|
|
|
|
)
|
2020-07-07 23:46:42 +03:00
|
|
|
ctx := context.Background()
|
2020-05-15 18:53:24 +03:00
|
|
|
if err := testDB.InsertModule(ctx, m); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-06-02 16:12:32 +03:00
|
|
|
s, _, _ := newTestServer(t, nil)
|
2020-05-15 18:53:24 +03:00
|
|
|
for _, test := range []struct {
|
|
|
|
path string
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{"foo", ""},
|
|
|
|
{"json", "encoding/json"},
|
|
|
|
{"template", ""},
|
|
|
|
} {
|
2020-07-22 16:12:04 +03:00
|
|
|
got, err := stdlibPathForShortcut(ctx, s.getDataSource(ctx), test.path)
|
2020-05-15 18:53:24 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%q: %v", test.path, err)
|
|
|
|
}
|
|
|
|
if got != test.want {
|
|
|
|
t.Errorf("%q: got %q, want %q", test.path, got, test.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|