зеркало из https://github.com/golang/pkgsite.git
internal: rename tc to test
The variable tc is renamed to test when used to refer to a test case, for consistency throughout the rest of the codebase, which uses the variable test in most cases. Change-Id: I88a87aa020928af98e8579a299f3111718dfa044 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/271809 Run-TryBot: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Trust: Julie Qiu <julie@golang.org>
This commit is contained in:
Родитель
6657ef22c5
Коммит
ff4efb1a4d
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func TestValidateAppVersion(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
in string
|
||||
wantErr bool
|
||||
}{
|
||||
|
@ -23,9 +23,9 @@ func TestValidateAppVersion(t *testing.T) {
|
|||
{"2019-09-12t13070400", true},
|
||||
{"2019-09-11t22-14-0400-2f4680648b319545c55c6149536f0a74527901f6", false},
|
||||
} {
|
||||
err := ValidateAppVersion(tc.in)
|
||||
if (err != nil) != tc.wantErr {
|
||||
t.Errorf("ValidateAppVersion(%q) = %v, want error = %t", tc.in, err, tc.wantErr)
|
||||
err := ValidateAppVersion(test.in)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("ValidateAppVersion(%q) = %v, want error = %t", test.in, err, test.wantErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func TestMain(m *testing.M) {
|
|||
func TestBulkInsert(t *testing.T) {
|
||||
table := "test_bulk_insert"
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
columns []string
|
||||
values []interface{}
|
||||
|
@ -126,7 +126,7 @@ func TestBulkInsert(t *testing.T) {
|
|||
wantCount: 1,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
defer cancel()
|
||||
|
||||
|
@ -147,10 +147,10 @@ func TestBulkInsert(t *testing.T) {
|
|||
|
||||
var err error
|
||||
var returned []string
|
||||
if tc.wantReturned == nil {
|
||||
err = testDB.BulkInsert(ctx, table, tc.columns, tc.values, tc.conflictAction)
|
||||
if test.wantReturned == nil {
|
||||
err = testDB.BulkInsert(ctx, table, test.columns, test.values, test.conflictAction)
|
||||
} else {
|
||||
err = testDB.BulkInsertReturning(ctx, table, tc.columns, tc.values, tc.conflictAction,
|
||||
err = testDB.BulkInsertReturning(ctx, table, test.columns, test.values, test.conflictAction,
|
||||
[]string{"colA"}, func(rows *sql.Rows) error {
|
||||
var r string
|
||||
if err := rows.Scan(&r); err != nil {
|
||||
|
@ -160,13 +160,13 @@ func TestBulkInsert(t *testing.T) {
|
|||
return nil
|
||||
})
|
||||
}
|
||||
if tc.wantErr && err == nil || !tc.wantErr && err != nil {
|
||||
t.Errorf("got error %v, wantErr %t", err, tc.wantErr)
|
||||
if test.wantErr && err == nil || !test.wantErr && err != nil {
|
||||
t.Errorf("got error %v, wantErr %t", err, test.wantErr)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if tc.wantCount != 0 {
|
||||
if test.wantCount != 0 {
|
||||
var count int
|
||||
query := "SELECT COUNT(*) FROM " + table
|
||||
row := testDB.QueryRow(ctx, query)
|
||||
|
@ -174,14 +174,14 @@ func TestBulkInsert(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("testDB.queryRow(%q): %v", query, err)
|
||||
}
|
||||
if count != tc.wantCount {
|
||||
t.Errorf("testDB.queryRow(%q) = %d; want = %d", query, count, tc.wantCount)
|
||||
if count != test.wantCount {
|
||||
t.Errorf("testDB.queryRow(%q) = %d; want = %d", query, count, test.wantCount)
|
||||
}
|
||||
}
|
||||
if tc.wantReturned != nil {
|
||||
if test.wantReturned != nil {
|
||||
sort.Strings(returned)
|
||||
if !cmp.Equal(returned, tc.wantReturned) {
|
||||
t.Errorf("returned: got %v, want %v", returned, tc.wantReturned)
|
||||
if !cmp.Equal(returned, test.wantReturned) {
|
||||
t.Errorf("returned: got %v, want %v", returned, test.wantReturned)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -43,7 +43,7 @@ func TestFromHTTPStatus(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestToHTTPStatus(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
in error
|
||||
want int
|
||||
}{
|
||||
|
@ -56,9 +56,9 @@ func TestToHTTPStatus(t *testing.T) {
|
|||
{fmt.Errorf("wrapping: %w", NotFound), http.StatusNotFound},
|
||||
{io.ErrUnexpectedEOF, http.StatusInternalServerError},
|
||||
} {
|
||||
got := ToStatus(tc.in)
|
||||
if got != tc.want {
|
||||
t.Errorf("ToHTTPStatus(%v) = %d, want %d", tc.in, got, tc.want)
|
||||
got := ToStatus(test.in)
|
||||
if got != test.want {
|
||||
t.Errorf("ToHTTPStatus(%v) = %d, want %d", test.in, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestSeriesPathForModule(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
modulePath, wantSeriesPath string
|
||||
}{
|
||||
{
|
||||
|
@ -31,9 +31,9 @@ func TestSeriesPathForModule(t *testing.T) {
|
|||
wantSeriesPath: "gopkg.in/russross/blackfriday",
|
||||
},
|
||||
} {
|
||||
t.Run(tc.modulePath, func(t *testing.T) {
|
||||
if got := SeriesPathForModule(tc.modulePath); got != tc.wantSeriesPath {
|
||||
t.Errorf("SeriesPathForModule(%q) = %q; want = %q", tc.modulePath, got, tc.wantSeriesPath)
|
||||
t.Run(test.modulePath, func(t *testing.T) {
|
||||
if got := SeriesPathForModule(test.modulePath); got != test.wantSeriesPath {
|
||||
t.Errorf("SeriesPathForModule(%q) = %q; want = %q", test.modulePath, got, test.wantSeriesPath)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func TestFileSource(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
modulePath, version, filePath, want string
|
||||
}{
|
||||
{
|
||||
|
@ -35,9 +35,9 @@ func TestFileSource(t *testing.T) {
|
|||
want: fmt.Sprintf("go.googlesource.com/go/+/refs/heads/master/%s", "README.md"),
|
||||
},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("%s@%s/%s", tc.modulePath, tc.version, tc.filePath), func(t *testing.T) {
|
||||
if got := fileSource(tc.modulePath, tc.version, tc.filePath); got != tc.want {
|
||||
t.Errorf("fileSource(%q, %q, %q) = %q; want = %q", tc.modulePath, tc.version, tc.filePath, got, tc.want)
|
||||
t.Run(fmt.Sprintf("%s@%s/%s", test.modulePath, test.version, test.filePath), func(t *testing.T) {
|
||||
if got := fileSource(test.modulePath, test.version, test.filePath); got != test.want {
|
||||
t.Errorf("fileSource(%q, %q, %q) = %q; want = %q", test.modulePath, test.version, test.filePath, got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -102,12 +102,12 @@ func TestAbsoluteTime(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
absoluteTime := absoluteTime(tc.date)
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
absoluteTime := absoluteTime(test.date)
|
||||
|
||||
if absoluteTime != tc.absoluteTime {
|
||||
t.Errorf("absoluteTime(%q) = %s, want %s", tc.date, absoluteTime, tc.absoluteTime)
|
||||
if absoluteTime != test.absoluteTime {
|
||||
t.Errorf("absoluteTime(%q) = %s, want %s", test.date, absoluteTime, test.absoluteTime)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
func TestFetchImportsDetails(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
imports []string
|
||||
wantDetails *ImportsDetails
|
||||
|
@ -44,7 +44,7 @@ func TestFetchImportsDetails(t *testing.T) {
|
|||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
defer postgres.ResetTestDB(testDB, t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
|
@ -53,7 +53,7 @@ func TestFetchImportsDetails(t *testing.T) {
|
|||
module := sample.Module(sample.ModulePath, sample.VersionString, sample.Suffix)
|
||||
// The first unit is the module and the second one is the package.
|
||||
pkg := module.Units[1]
|
||||
pkg.Imports = tc.imports
|
||||
pkg.Imports = test.imports
|
||||
|
||||
if err := testDB.InsertModule(ctx, module); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -62,11 +62,11 @@ func TestFetchImportsDetails(t *testing.T) {
|
|||
got, err := fetchImportsDetails(ctx, testDB, pkg.Path, pkg.ModulePath, pkg.Version)
|
||||
if err != nil {
|
||||
t.Fatalf("fetchImportsDetails(ctx, db, %q, %q) = %v err = %v, want %v",
|
||||
module.Units[1].Path, module.Version, got, err, tc.wantDetails)
|
||||
module.Units[1].Path, module.Version, got, err, test.wantDetails)
|
||||
}
|
||||
|
||||
tc.wantDetails.ModulePath = module.ModulePath
|
||||
if diff := cmp.Diff(tc.wantDetails, got); diff != "" {
|
||||
test.wantDetails.ModulePath = module.ModulePath
|
||||
if diff := cmp.Diff(test.wantDetails, got); diff != "" {
|
||||
t.Errorf("fetchImportsDetails(ctx, %q, %q) mismatch (-want +got):\n%s", module.Units[1].Path, module.Version, diff)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestPagination(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
page, numResults, wantNumPages, wantOffset, wantPrev, wantNext int
|
||||
name string
|
||||
}{
|
||||
|
@ -70,29 +70,29 @@ func TestPagination(t *testing.T) {
|
|||
wantNext: 0,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
testLimit := 10
|
||||
if got := numPages(testLimit, tc.numResults); got != tc.wantNumPages {
|
||||
if got := numPages(testLimit, test.numResults); got != test.wantNumPages {
|
||||
t.Errorf("numPages(%d, %d) = %d; want = %d",
|
||||
testLimit, tc.numResults, got, tc.wantNumPages)
|
||||
testLimit, test.numResults, got, test.wantNumPages)
|
||||
}
|
||||
if got := offset(tc.page, testLimit); got != tc.wantOffset {
|
||||
if got := offset(test.page, testLimit); got != test.wantOffset {
|
||||
t.Errorf("offset(%d, %d) = %d; want = %d",
|
||||
tc.page, testLimit, got, tc.wantOffset)
|
||||
test.page, testLimit, got, test.wantOffset)
|
||||
}
|
||||
if got := prev(tc.page); got != tc.wantPrev {
|
||||
t.Errorf("prev(%d) = %d; want = %d", tc.page, got, tc.wantPrev)
|
||||
if got := prev(test.page); got != test.wantPrev {
|
||||
t.Errorf("prev(%d) = %d; want = %d", test.page, got, test.wantPrev)
|
||||
}
|
||||
if got := next(tc.page, testLimit, tc.numResults); got != tc.wantNext {
|
||||
if got := next(test.page, testLimit, test.numResults); got != test.wantNext {
|
||||
t.Errorf("next(%d, %d, %d) = %d; want = %d",
|
||||
tc.page, testLimit, tc.numResults, got, tc.wantNext)
|
||||
test.page, testLimit, test.numResults, got, test.wantNext)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPagesToDisplay(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
page, numPages, numToDisplay int
|
||||
wantPages []int
|
||||
|
@ -189,10 +189,10 @@ func TestPagesToDisplay(t *testing.T) {
|
|||
wantPages: []int{1, 2, 3, 4, 5, 6},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := pagesToLink(tc.page, tc.numPages, tc.numToDisplay)
|
||||
if diff := cmp.Diff(got, tc.wantPages); diff != "" {
|
||||
t.Errorf("pagesToLink(%d, %d, %d) = %v; want = %v", tc.page, tc.numPages, tc.numToDisplay, got, tc.wantPages)
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := pagesToLink(test.page, test.numPages, test.numToDisplay)
|
||||
if diff := cmp.Diff(got, test.wantPages); diff != "" {
|
||||
t.Errorf("pagesToLink(%d, %d, %d) = %v; want = %v", test.page, test.numPages, test.numToDisplay, got, test.wantPages)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -76,20 +76,20 @@ func main() {
|
|||
code: http.StatusInternalServerError,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
body := strings.NewReader(tc.body)
|
||||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
body := strings.NewReader(test.body)
|
||||
|
||||
req, err := http.NewRequest(tc.method, "/play", body)
|
||||
req, err := http.NewRequest(test.method, "/play", body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w := httptest.NewRecorder()
|
||||
makeFetchPlayRequest(w, req, tc.pgURL)
|
||||
makeFetchPlayRequest(w, req, test.pgURL)
|
||||
|
||||
res := w.Result()
|
||||
if got, want := res.StatusCode, tc.code; got != want {
|
||||
if got, want := res.StatusCode, test.code; got != want {
|
||||
t.Errorf("Status Code = %d; want %d", got, want)
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ func main() {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantID := tc.shareID
|
||||
wantID := test.shareID
|
||||
if !*playground {
|
||||
wantID = testShareID
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
func TestReadme(t *testing.T) {
|
||||
ctx := experiment.NewContext(context.Background(), internal.ExperimentGoldmark)
|
||||
unit := sample.UnitEmpty(sample.PackagePath, sample.ModulePath, sample.VersionString)
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
unit *internal.Unit
|
||||
readme *internal.Readme
|
||||
|
@ -332,18 +332,18 @@ func TestReadme(t *testing.T) {
|
|||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tc.unit.Readme = tc.readme
|
||||
html, gotOutline, err := Readme(ctx, tc.unit)
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
test.unit.Readme = test.readme
|
||||
html, gotOutline, err := Readme(ctx, test.unit)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gotHTML := strings.TrimSpace(html.String())
|
||||
if diff := cmp.Diff(tc.wantHTML, gotHTML); diff != "" {
|
||||
t.Errorf("Readme(%v) html mismatch (-want +got):\n%s", tc.unit.UnitMeta, diff)
|
||||
if diff := cmp.Diff(test.wantHTML, gotHTML); diff != "" {
|
||||
t.Errorf("Readme(%v) html mismatch (-want +got):\n%s", test.unit.UnitMeta, diff)
|
||||
}
|
||||
if diff := cmp.Diff(tc.wantOutline, gotOutline); diff != "" {
|
||||
t.Errorf("Readme(%v) outline mismatch (-want +got):\n%s", tc.unit.UnitMeta, diff)
|
||||
if diff := cmp.Diff(test.wantOutline, gotOutline); diff != "" {
|
||||
t.Errorf("Readme(%v) outline mismatch (-want +got):\n%s", test.unit.UnitMeta, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ func TestFetchSearchPage(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name, query string
|
||||
modules []*internal.Module
|
||||
wantSearchPage *SearchPage
|
||||
|
@ -149,10 +149,10 @@ func TestFetchSearchPage(t *testing.T) {
|
|||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := fetchSearchPage(ctx, testDB, tc.query, paginationParams{limit: 20, page: 1})
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := fetchSearchPage(ctx, testDB, test.query, paginationParams{limit: 20, page: 1})
|
||||
if err != nil {
|
||||
t.Fatalf("fetchSearchPage(db, %q): %v", tc.query, err)
|
||||
t.Fatalf("fetchSearchPage(db, %q): %v", test.query, err)
|
||||
}
|
||||
|
||||
opts := cmp.Options{
|
||||
|
@ -160,8 +160,8 @@ func TestFetchSearchPage(t *testing.T) {
|
|||
cmpopts.IgnoreFields(licenses.Metadata{}, "FilePath"),
|
||||
cmpopts.IgnoreFields(pagination{}, "Approximate"),
|
||||
}
|
||||
if diff := cmp.Diff(tc.wantSearchPage, got, opts...); diff != "" {
|
||||
t.Errorf("fetchSearchPage(db, %q) mismatch (-want +got):\n%s", tc.query, diff)
|
||||
if diff := cmp.Diff(test.wantSearchPage, got, opts...); diff != "" {
|
||||
t.Errorf("fetchSearchPage(db, %q) mismatch (-want +got):\n%s", test.query, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ func TestSearchRequestRedirectPath(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
query string
|
||||
want string
|
||||
|
@ -223,9 +223,9 @@ func TestSearchRequestRedirectPath(t *testing.T) {
|
|||
{"non-existent path does not redirect", "github.com/non-existent", ""},
|
||||
{"trim URL scheme from query", "https://golang.org/x/tools", "/mod/golang.org/x/tools"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := searchRequestRedirectPath(ctx, testDB, tc.query); got != tc.want {
|
||||
t.Errorf("searchRequestRedirectPath(ctx, %q) = %q; want = %q", tc.query, got, tc.want)
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := searchRequestRedirectPath(ctx, testDB, test.query); got != test.want {
|
||||
t.Errorf("searchRequestRedirectPath(ctx, %q) = %q; want = %q", test.query, got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -270,12 +270,12 @@ func TestElapsedTime(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
elapsedTime := elapsedTime(tc.date)
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
elapsedTime := elapsedTime(test.date)
|
||||
|
||||
if elapsedTime != tc.elapsedTime {
|
||||
t.Errorf("elapsedTime(%q) = %s, want %s", tc.date, elapsedTime, tc.elapsedTime)
|
||||
if elapsedTime != test.elapsedTime {
|
||||
t.Errorf("elapsedTime(%q) = %s, want %s", test.date, elapsedTime, test.elapsedTime)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestNextPrefixAccount(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
path, want1, want2 string
|
||||
}{
|
||||
{"", "", ""},
|
||||
|
@ -27,28 +27,28 @@ func TestNextPrefixAccount(t *testing.T) {
|
|||
{"example.com/foo", "example.com/", "example.com/foo"},
|
||||
{"example.com/foo/bar", "example.com/", "example.com/foo/"},
|
||||
} {
|
||||
got1 := nextPrefixAccount(tc.path, "")
|
||||
if got1 != tc.want1 {
|
||||
t.Errorf(`nextPrefixAccount(%q, "") = %q, want %q`, tc.path, got1, tc.want1)
|
||||
got1 := nextPrefixAccount(test.path, "")
|
||||
if got1 != test.want1 {
|
||||
t.Errorf(`nextPrefixAccount(%q, "") = %q, want %q`, test.path, got1, test.want1)
|
||||
continue
|
||||
}
|
||||
got2 := nextPrefixAccount(tc.path, got1)
|
||||
if got2 != tc.want2 {
|
||||
t.Errorf(`nextPrefixAccount(%q, %q) = %q, want %q`, tc.path, got1, got2, tc.want2)
|
||||
got2 := nextPrefixAccount(test.path, got1)
|
||||
if got2 != test.want2 {
|
||||
t.Errorf(`nextPrefixAccount(%q, %q) = %q, want %q`, test.path, got1, got2, test.want2)
|
||||
continue
|
||||
}
|
||||
if got2 == "" {
|
||||
continue
|
||||
}
|
||||
got3 := nextPrefixAccount(tc.path, got2)
|
||||
got3 := nextPrefixAccount(test.path, got2)
|
||||
if got3 != "" {
|
||||
t.Errorf(`nextPrefixAccount(%q, %q) = %q, want ""`, tc.path, got2, got3)
|
||||
t.Errorf(`nextPrefixAccount(%q, %q) = %q, want ""`, test.path, got2, got3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrefixSections(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
lines []string
|
||||
want []*Section
|
||||
}{
|
||||
|
@ -103,9 +103,9 @@ func TestPrefixSections(t *testing.T) {
|
|||
},
|
||||
},
|
||||
} {
|
||||
got := Sections(tc.lines, nextPrefixAccount)
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
t.Errorf("%v: mismatch (-want, +got):\n%s", tc.lines, diff)
|
||||
got := Sections(test.lines, nextPrefixAccount)
|
||||
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||
t.Errorf("%v: mismatch (-want, +got):\n%s", test.lines, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -731,21 +731,21 @@ func testServer(t *testing.T, testCases []serverTestCase, experimentNames ...str
|
|||
|
||||
experimentsSet := experiment.NewSet(experimentNames...)
|
||||
|
||||
for _, tc := range testCases {
|
||||
if !isSubset(tc.requiredExperiments, experimentsSet) {
|
||||
for _, test := range testCases {
|
||||
if !isSubset(test.requiredExperiments, experimentsSet) {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) { // remove initial '/' for name
|
||||
t.Run(test.name, func(t *testing.T) { // remove initial '/' for name
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, httptest.NewRequest("GET", tc.urlPath, nil))
|
||||
handler.ServeHTTP(w, httptest.NewRequest("GET", test.urlPath, nil))
|
||||
res := w.Result()
|
||||
if res.StatusCode != tc.wantStatusCode {
|
||||
t.Errorf("GET %q = %d, want %d", tc.urlPath, res.StatusCode, tc.wantStatusCode)
|
||||
if res.StatusCode != test.wantStatusCode {
|
||||
t.Errorf("GET %q = %d, want %d", test.urlPath, res.StatusCode, test.wantStatusCode)
|
||||
}
|
||||
if tc.wantLocation != "" {
|
||||
if got := res.Header.Get("Location"); got != tc.wantLocation {
|
||||
t.Errorf("Location: got %q, want %q", got, tc.wantLocation)
|
||||
if test.wantLocation != "" {
|
||||
if got := res.Header.Get("Location"); got != test.wantLocation {
|
||||
t.Errorf("Location: got %q, want %q", got, test.wantLocation)
|
||||
}
|
||||
}
|
||||
doc, err := html.Parse(res.Body)
|
||||
|
@ -754,8 +754,8 @@ func testServer(t *testing.T, testCases []serverTestCase, experimentNames ...str
|
|||
}
|
||||
_ = res.Body.Close()
|
||||
|
||||
if tc.want != nil {
|
||||
if err := tc.want(doc); err != nil {
|
||||
if test.want != nil {
|
||||
if err := test.want(doc); err != nil {
|
||||
if testing.Verbose() {
|
||||
html.Render(os.Stdout, doc)
|
||||
}
|
||||
|
|
|
@ -40,15 +40,15 @@ func TestParseStdLibURLPath(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := parseStdLibURLPath(tc.url)
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := parseStdLibURLPath(test.url)
|
||||
if err != nil {
|
||||
t.Fatalf("parseStdLibURLPath(%q): %v)", tc.url, err)
|
||||
t.Fatalf("parseStdLibURLPath(%q): %v)", test.url, err)
|
||||
}
|
||||
if tc.wantVersion != got.requestedVersion || tc.wantPath != got.fullPath {
|
||||
if test.wantVersion != got.requestedVersion || test.wantPath != got.fullPath {
|
||||
t.Fatalf("parseStdLibURLPath(%q): %q, %q, %v; want = %q, %q",
|
||||
tc.url, got.fullPath, got.requestedVersion, err, tc.wantPath, tc.wantVersion)
|
||||
test.url, got.fullPath, got.requestedVersion, err, test.wantPath, test.wantVersion)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestGetNestedModules(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
modulePath string
|
||||
want []*NestedModule
|
||||
}{
|
||||
|
@ -73,15 +73,15 @@ func TestGetNestedModules(t *testing.T) {
|
|||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.modulePath, func(t *testing.T) {
|
||||
t.Run(test.modulePath, func(t *testing.T) {
|
||||
got, err := getNestedModules(ctx, testDB, &internal.UnitMeta{
|
||||
Path: tc.modulePath,
|
||||
ModulePath: tc.modulePath,
|
||||
Path: test.modulePath,
|
||||
ModulePath: test.modulePath,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||
t.Errorf("mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
@ -123,7 +123,7 @@ func TestGetImportedByCount(t *testing.T) {
|
|||
|
||||
mainPageImportedByLimit = 2
|
||||
tabImportedByLimit = 3
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
pkg *internal.Unit
|
||||
want string
|
||||
}{
|
||||
|
@ -140,17 +140,17 @@ func TestGetImportedByCount(t *testing.T) {
|
|||
want: "2+",
|
||||
},
|
||||
} {
|
||||
t.Run(tc.pkg.Path, func(t *testing.T) {
|
||||
otherVersion := newModule(path.Dir(tc.pkg.Path), tc.pkg)
|
||||
t.Run(test.pkg.Path, func(t *testing.T) {
|
||||
otherVersion := newModule(path.Dir(test.pkg.Path), test.pkg)
|
||||
otherVersion.Version = "v1.0.5"
|
||||
pkg := otherVersion.Units[1]
|
||||
got, err := getImportedByCount(ctx, testDB, pkg)
|
||||
if err != nil {
|
||||
t.Fatalf("getImportedByCount(ctx, db, %q) = %v err = %v, want %v",
|
||||
tc.pkg.Path, got, err, tc.want)
|
||||
test.pkg.Path, got, err, test.want)
|
||||
}
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
t.Errorf("getImportedByCount(ctx, db, %q) mismatch (-want +got):\n%s", tc.pkg.Path, diff)
|
||||
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||
t.Errorf("getImportedByCount(ctx, db, %q) mismatch (-want +got):\n%s", test.pkg.Path, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -137,15 +137,15 @@ func TestExtractURLPathInfo_Errors(t *testing.T) {
|
|||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := extractURLPathInfo(tc.url)
|
||||
if (err != nil) != tc.wantErr {
|
||||
t.Fatalf("extractURLPathInfo(%q) error = (%v); want error %t)", tc.url, err, tc.wantErr)
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := extractURLPathInfo(test.url)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Fatalf("extractURLPathInfo(%q) error = (%v); want error %t)", test.url, err, test.wantErr)
|
||||
}
|
||||
if !tc.wantErr && (tc.wantModulePath != got.modulePath || tc.wantVersion != got.requestedVersion || tc.wantFullPath != got.fullPath) {
|
||||
if !test.wantErr && (test.wantModulePath != got.modulePath || test.wantVersion != got.requestedVersion || test.wantFullPath != got.fullPath) {
|
||||
t.Fatalf("extractURLPathInfo(%q): %q, %q, %q, %v; want = %q, %q, %q, want err %t",
|
||||
tc.url, got.fullPath, got.modulePath, got.requestedVersion, err, tc.wantFullPath, tc.wantModulePath, tc.wantVersion, tc.wantErr)
|
||||
test.url, got.fullPath, got.modulePath, got.requestedVersion, err, test.wantFullPath, test.wantModulePath, test.wantVersion, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -300,7 +300,7 @@ func mustParse(t *testing.T, fset *token.FileSet, filename, src string) *ast.Fil
|
|||
|
||||
func TestExampleCode(t *testing.T) {
|
||||
fset := token.NewFileSet()
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
example doc.Example
|
||||
want string
|
||||
|
@ -405,14 +405,14 @@ func main() {
|
|||
`,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
r := New(ctx, fset, pkgTime, nil)
|
||||
got, err := r.codeString(&tc.example)
|
||||
got, err := r.codeString(&test.example)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||
t.Errorf("mismatch (-want +got):%s", diff)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -25,19 +25,19 @@ var (
|
|||
func LoadTemplates(dir template.TrustedSource) {
|
||||
loadOnce.Do(func() {
|
||||
join := template.TrustedSourceJoin
|
||||
tc := template.TrustedSourceFromConstant
|
||||
test := template.TrustedSourceFromConstant
|
||||
|
||||
example := join(dir, tc("example.tmpl"))
|
||||
example := join(dir, test("example.tmpl"))
|
||||
legacyTemplate = template.Must(template.New("legacy.tmpl").
|
||||
Funcs(tmpl).
|
||||
ParseFilesFromTrustedSources(join(dir, tc("legacy.tmpl")), example))
|
||||
ParseFilesFromTrustedSources(join(dir, test("legacy.tmpl")), example))
|
||||
unitTemplate = template.Must(template.New("unit.tmpl").
|
||||
Funcs(tmpl).
|
||||
ParseFilesFromTrustedSources(
|
||||
join(dir, tc("unit.tmpl")),
|
||||
join(dir, tc("sidenav.tmpl")),
|
||||
join(dir, tc("sidenav-mobile.tmpl")),
|
||||
join(dir, tc("body.tmpl")),
|
||||
join(dir, test("unit.tmpl")),
|
||||
join(dir, test("sidenav.tmpl")),
|
||||
join(dir, test("sidenav-mobile.tmpl")),
|
||||
join(dir, test("body.tmpl")),
|
||||
example))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func TestGetVersions(t *testing.T) {
|
|||
{Path: "github.com/my/module/v2", Version: "v2.0.0"},
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
limit int
|
||||
versions []*internal.IndexVersion
|
||||
|
@ -44,16 +44,16 @@ func TestGetVersions(t *testing.T) {
|
|||
limit: 10,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
client, teardown := SetupTestIndex(t, tc.versions)
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client, teardown := SetupTestIndex(t, test.versions)
|
||||
defer teardown()
|
||||
|
||||
since := time.Time{}
|
||||
got, err := client.GetVersions(ctx, since, tc.limit)
|
||||
got, err := client.GetVersions(ctx, since, test.limit)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||
t.Errorf("client.GetVersions(ctx, %q) mismatch (-want +got):\n%s", since, diff)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -63,10 +63,10 @@ func TestGodocURL(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", tc.path, nil)
|
||||
for k, v := range tc.cookies {
|
||||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", test.path, nil)
|
||||
for k, v := range test.cookies {
|
||||
req.AddCookie(&http.Cookie{
|
||||
Name: k,
|
||||
Value: v,
|
||||
|
@ -76,7 +76,7 @@ func TestGodocURL(t *testing.T) {
|
|||
mwh.ServeHTTP(w, req)
|
||||
resp := w.Result()
|
||||
defer resp.Body.Close()
|
||||
if got, want := resp.StatusCode, tc.code; got != want {
|
||||
if got, want := resp.StatusCode, test.code; got != want {
|
||||
t.Errorf("Status code = %d; want %d", got, want)
|
||||
}
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
|
@ -84,11 +84,11 @@ func TestGodocURL(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("ioutil.ReadAll(resp.Body) = %v", err)
|
||||
}
|
||||
if got, want := body, tc.body; !bytes.Equal(got, want) {
|
||||
if got, want := body, test.body; !bytes.Equal(got, want) {
|
||||
t.Errorf("Response body = %q; want %q", got, want)
|
||||
}
|
||||
}
|
||||
for k, v := range tc.headers {
|
||||
for k, v := range test.headers {
|
||||
if _, ok := resp.Header[k]; !ok {
|
||||
t.Errorf("%q not present in response headers", k)
|
||||
continue
|
||||
|
@ -147,14 +147,14 @@ func TestGodoc(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
u, err := url.Parse(tc.from)
|
||||
for _, test := range testCases {
|
||||
u, err := url.Parse(test.from)
|
||||
if err != nil {
|
||||
t.Errorf("url.Parse(%q): %v", tc.from, err)
|
||||
t.Errorf("url.Parse(%q): %v", test.from, err)
|
||||
continue
|
||||
}
|
||||
to := godoc(u)
|
||||
if got, want := to, tc.to; got != want {
|
||||
if got, want := to, test.to; got != want {
|
||||
t.Errorf("godocURL(%q) = %q; want %q", u, got, want)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ func TestGetNestedModules(t *testing.T) {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
defer cancel()
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
path string
|
||||
modules []*internal.Module
|
||||
|
@ -68,15 +68,15 @@ func TestGetNestedModules(t *testing.T) {
|
|||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
defer ResetTestDB(testDB, t)
|
||||
for _, v := range tc.modules {
|
||||
for _, v := range test.modules {
|
||||
if err := testDB.InsertModule(ctx, v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
gotModules, err := testDB.GetNestedModules(ctx, tc.path)
|
||||
gotModules, err := testDB.GetNestedModules(ctx, test.path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func TestGetNestedModules(t *testing.T) {
|
|||
gotModulePaths = append(gotModulePaths, mod.ModulePath)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(tc.wantModulePaths, gotModulePaths); diff != "" {
|
||||
if diff := cmp.Diff(test.wantModulePaths, gotModulePaths); diff != "" {
|
||||
t.Errorf("mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
@ -181,28 +181,28 @@ func TestPostgres_GetModuleInfo(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
for _, v := range tc.modules {
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
for _, v := range test.modules {
|
||||
if err := testDB.InsertModule(ctx, v); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
gotVI, err := testDB.GetModuleInfo(ctx, tc.path, tc.version)
|
||||
gotVI, err := testDB.GetModuleInfo(ctx, test.path, test.version)
|
||||
if err != nil {
|
||||
if tc.wantErr == nil {
|
||||
if test.wantErr == nil {
|
||||
t.Fatalf("got unexpected error %v", err)
|
||||
}
|
||||
if !errors.Is(err, tc.wantErr) {
|
||||
t.Fatalf("got error %v, want Is(%v)", err, tc.wantErr)
|
||||
if !errors.Is(err, test.wantErr) {
|
||||
t.Fatalf("got error %v, want Is(%v)", err, test.wantErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
if tc.wantIndex >= len(tc.modules) {
|
||||
if test.wantIndex >= len(test.modules) {
|
||||
t.Fatal("wantIndex too large")
|
||||
}
|
||||
wantVI := &tc.modules[tc.wantIndex].ModuleInfo
|
||||
wantVI := &test.modules[test.wantIndex].ModuleInfo
|
||||
if diff := cmp.Diff(wantVI, gotVI, cmpopts.EquateEmpty(), cmp.AllowUnexported(source.Info{})); diff != "" {
|
||||
t.Errorf("mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ func TestGetImportedBy(t *testing.T) {
|
|||
pkg2.Imports = []string{pkg1.Path}
|
||||
pkg3.Imports = []string{pkg2.Path, pkg1.Path}
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name, path, modulePath, version string
|
||||
wantImports []string
|
||||
wantImportedBy []string
|
||||
|
@ -263,7 +263,7 @@ func TestGetImportedBy(t *testing.T) {
|
|||
wantImportedBy: []string{pkg3.Path},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
defer ResetTestDB(testDB, t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
|
@ -275,12 +275,12 @@ func TestGetImportedBy(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
gotImportedBy, err := testDB.GetImportedBy(ctx, tc.path, tc.modulePath, 100)
|
||||
gotImportedBy, err := testDB.GetImportedBy(ctx, test.path, test.modulePath, 100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(tc.wantImportedBy, gotImportedBy); diff != "" {
|
||||
t.Errorf("testDB.GetImportedBy(%q, %q) mismatch (-want +got):\n%s", tc.path, tc.modulePath, diff)
|
||||
if diff := cmp.Diff(test.wantImportedBy, gotImportedBy); diff != "" {
|
||||
t.Errorf("testDB.GetImportedBy(%q, %q) mismatch (-want +got):\n%s", test.path, test.modulePath, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -256,11 +256,11 @@ func TestInsertModuleErrors(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
defer ResetTestDB(testDB, t)
|
||||
if err := testDB.InsertModule(ctx, tc.module); !errors.Is(err, tc.wantWriteErr) {
|
||||
t.Errorf("error: %v, want write error: %v", err, tc.wantWriteErr)
|
||||
if err := testDB.InsertModule(ctx, test.module); !errors.Is(err, test.wantWriteErr) {
|
||||
t.Errorf("error: %v, want write error: %v", err, test.wantWriteErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ func TestLatestVersion(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
modulePath string
|
||||
wantVersion string
|
||||
|
@ -361,13 +361,13 @@ func TestLatestVersion(t *testing.T) {
|
|||
wantVersion: "v3.0.1-rc9",
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
isLatest, err := isLatestVersion(ctx, testDB.db, tc.modulePath, tc.wantVersion)
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
isLatest, err := isLatestVersion(ctx, testDB.db, test.modulePath, test.wantVersion)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !isLatest {
|
||||
t.Errorf("%s is not the latest version", tc.wantVersion)
|
||||
t.Errorf("%s is not the latest version", test.wantVersion)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ func TestLatestVersion_PreferIncompatibleOverPrerelease(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
modulePath string
|
||||
want string
|
||||
}{
|
||||
|
@ -408,12 +408,12 @@ func TestLatestVersion_PreferIncompatibleOverPrerelease(t *testing.T) {
|
|||
want: "v2.0.0+incompatible",
|
||||
},
|
||||
} {
|
||||
isLatest, err := isLatestVersion(ctx, testDB.db, tc.modulePath, tc.want)
|
||||
isLatest, err := isLatestVersion(ctx, testDB.db, test.modulePath, test.want)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !isLatest {
|
||||
t.Errorf("%s is not the latest version", tc.want)
|
||||
t.Errorf("%s is not the latest version", test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
)
|
||||
|
||||
func TestPathTokens(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
path string
|
||||
want []string
|
||||
}{
|
||||
|
@ -140,10 +140,10 @@ func TestPathTokens(t *testing.T) {
|
|||
want: nil,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.path, func(t *testing.T) {
|
||||
got := GeneratePathTokens(tc.path)
|
||||
if diff := cmp.Diff(tc.want, got); diff != "" {
|
||||
t.Errorf("generatePathTokens(%q) mismatch (-want +got):\n%s", tc.path, diff)
|
||||
t.Run(test.path, func(t *testing.T) {
|
||||
got := GeneratePathTokens(test.path)
|
||||
if diff := cmp.Diff(test.want, got); diff != "" {
|
||||
t.Errorf("generatePathTokens(%q) mismatch (-want +got):\n%s", test.path, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
|
|||
cloudScore = 0.8654518127441406
|
||||
)
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
packages map[string]*internal.Unit
|
||||
limit, offset int
|
||||
|
@ -541,13 +541,13 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
|
|||
},
|
||||
} {
|
||||
for method, searcher := range searchers {
|
||||
t.Run(tc.name+":"+method, func(t *testing.T) {
|
||||
t.Run(test.name+":"+method, func(t *testing.T) {
|
||||
defer ResetTestDB(testDB, t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
defer cancel()
|
||||
|
||||
for modulePath, pkg := range tc.packages {
|
||||
for modulePath, pkg := range test.packages {
|
||||
pkg.Licenses = sample.LicenseMetadata
|
||||
m := sample.Module(modulePath, sample.VersionString)
|
||||
sample.AddUnit(m, pkg)
|
||||
|
@ -556,11 +556,11 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
if tc.limit < 1 {
|
||||
tc.limit = 10
|
||||
if test.limit < 1 {
|
||||
test.limit = 10
|
||||
}
|
||||
|
||||
got := searcher(testDB, ctx, tc.searchQuery, tc.limit, tc.offset, 100)
|
||||
got := searcher(testDB, ctx, test.searchQuery, test.limit, test.offset, 100)
|
||||
if got.err != nil {
|
||||
t.Fatal(got.err)
|
||||
}
|
||||
|
@ -568,14 +568,14 @@ func TestInsertSearchDocumentAndSearch(t *testing.T) {
|
|||
if err := testDB.addPackageDataToSearchResults(ctx, got.results); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got.results) != len(tc.want) {
|
||||
t.Errorf("testDB.Search(%v, %d, %d) mismatch: len(got) = %d, want = %d\n", tc.searchQuery, tc.limit, tc.offset, len(got.results), len(tc.want))
|
||||
if len(got.results) != len(test.want) {
|
||||
t.Errorf("testDB.Search(%v, %d, %d) mismatch: len(got) = %d, want = %d\n", test.searchQuery, test.limit, test.offset, len(got.results), len(test.want))
|
||||
}
|
||||
|
||||
// The searchers differ in these two fields.
|
||||
opt := cmpopts.IgnoreFields(internal.SearchResult{}, "Approximate", "NumResults")
|
||||
if diff := cmp.Diff(tc.want, got.results, opt); diff != "" {
|
||||
t.Errorf("testDB.Search(%v, %d, %d) mismatch (-want +got):\n%s", tc.searchQuery, tc.limit, tc.offset, diff)
|
||||
if diff := cmp.Diff(test.want, got.results, opt); diff != "" {
|
||||
t.Errorf("testDB.Search(%v, %d, %d) mismatch (-want +got):\n%s", test.searchQuery, test.limit, test.offset, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -212,20 +212,20 @@ func TestGetVersions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var want []*internal.ModuleInfo
|
||||
for _, w := range tc.want {
|
||||
for _, w := range test.want {
|
||||
mod := sample.ModuleInfo(w.ModulePath, w.Version)
|
||||
want = append(want, mod)
|
||||
}
|
||||
|
||||
got, err := testDB.GetVersionsForPath(ctx, tc.path)
|
||||
got, err := testDB.GetVersionsForPath(ctx, test.path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(want, got, cmp.AllowUnexported(source.Info{})); diff != "" {
|
||||
t.Errorf("testDB.GetVersionsForPath(%q) mismatch (-want +got):\n%s", tc.path, diff)
|
||||
t.Errorf("testDB.GetVersionsForPath(%q) mismatch (-want +got):\n%s", test.path, diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ func TestGetLatestMajorVersion(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
seriesPath string
|
||||
wantVersion string
|
||||
wantErr error
|
||||
|
@ -266,17 +266,17 @@ func TestGetLatestMajorVersion(t *testing.T) {
|
|||
wantErr: sql.ErrNoRows,
|
||||
},
|
||||
} {
|
||||
gotVersion, err := testDB.GetLatestMajorVersion(ctx, tc.seriesPath)
|
||||
gotVersion, err := testDB.GetLatestMajorVersion(ctx, test.seriesPath)
|
||||
if err != nil {
|
||||
if tc.wantErr == nil {
|
||||
if test.wantErr == nil {
|
||||
t.Fatalf("got unexpected error %v", err)
|
||||
}
|
||||
if !errors.Is(err, tc.wantErr) {
|
||||
t.Errorf("got err = %v, want Is(%v)", err, tc.wantErr)
|
||||
if !errors.Is(err, test.wantErr) {
|
||||
t.Errorf("got err = %v, want Is(%v)", err, test.wantErr)
|
||||
}
|
||||
}
|
||||
if gotVersion != tc.wantVersion {
|
||||
t.Errorf("testDB.GetLatestMajorVersion(%v) = %v, want = %v", tc.seriesPath, gotVersion, tc.wantVersion)
|
||||
if gotVersion != test.wantVersion {
|
||||
t.Errorf("testDB.GetLatestMajorVersion(%v) = %v, want = %v", test.seriesPath, gotVersion, test.wantVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestTagForVersion(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
version string
|
||||
want string
|
||||
|
@ -76,14 +76,14 @@ func TestTagForVersion(t *testing.T) {
|
|||
wantErr: true,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := TagForVersion(tc.version)
|
||||
if (err != nil) != tc.wantErr {
|
||||
t.Errorf("TagForVersion(%q) = %q, %v, wantErr %v", tc.version, got, err, tc.wantErr)
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := TagForVersion(test.version)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("TagForVersion(%q) = %q, %v, wantErr %v", test.version, got, err, test.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tc.want {
|
||||
t.Errorf("TagForVersion(%q) = %q, %v, wanted %q, %v", tc.version, got, err, tc.want, nil)
|
||||
if got != test.want {
|
||||
t.Errorf("TagForVersion(%q) = %q, %v, wanted %q, %v", test.version, got, err, test.want, nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ func TestVersions(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestVersionForTag(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
for _, test := range []struct {
|
||||
in, want string
|
||||
}{
|
||||
{"", ""},
|
||||
|
@ -231,9 +231,9 @@ func TestVersionForTag(t *testing.T) {
|
|||
{"weekly.2012-02-14", ""},
|
||||
{"latest", "latest"},
|
||||
} {
|
||||
got := VersionForTag(tc.in)
|
||||
if got != tc.want {
|
||||
t.Errorf("VersionForTag(%q) = %q, want %q", tc.in, got, tc.want)
|
||||
got := VersionForTag(test.in)
|
||||
if got != test.want {
|
||||
t.Errorf("VersionForTag(%q) = %q, want %q", test.in, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,18 +139,18 @@ func XTestParentFinishesChild(t testingT) {
|
|||
// The parent's children should contain the two cancelable children.
|
||||
pc := parent.(*cancelCtx)
|
||||
cc := cancelChild.(*cancelCtx)
|
||||
tc := timerChild.(*timerCtx)
|
||||
test := timerChild.(*timerCtx)
|
||||
pc.mu.Lock()
|
||||
if len(pc.children) != 2 || !contains(pc.children, cc) || !contains(pc.children, tc) {
|
||||
if len(pc.children) != 2 || !contains(pc.children, cc) || !contains(pc.children, test) {
|
||||
t.Errorf("bad linkage: pc.children = %v, want %v and %v",
|
||||
pc.children, cc, tc)
|
||||
pc.children, cc, test)
|
||||
}
|
||||
pc.mu.Unlock()
|
||||
|
||||
if p, ok := parentCancelCtx(cc.Context); !ok || p != pc {
|
||||
t.Errorf("bad linkage: parentCancelCtx(cancelChild.Context) = %v, %v want %v, true", p, ok, pc)
|
||||
}
|
||||
if p, ok := parentCancelCtx(tc.Context); !ok || p != pc {
|
||||
if p, ok := parentCancelCtx(test.Context); !ok || p != pc {
|
||||
t.Errorf("bad linkage: parentCancelCtx(timerChild.Context) = %v, %v want %v, true", p, ok, pc)
|
||||
}
|
||||
|
||||
|
|
|
@ -143,10 +143,10 @@ func TestParseVersionType(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if gotVt, err := ParseType(tc.version); (tc.wantErr == (err != nil)) && tc.wantVersionType != gotVt {
|
||||
t.Errorf("parseVersionType(%v) = %v, want %v", tc.version, gotVt, tc.wantVersionType)
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if gotVt, err := ParseType(test.version); (test.wantErr == (err != nil)) && test.wantVersionType != gotVt {
|
||||
t.Errorf("parseVersionType(%v) = %v, want %v", test.version, gotVt, test.wantVersionType)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче