diff options
| author | Julie Qiu <julie@golang.org> | 2020-11-19 23:09:05 -0500 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-11-20 17:06:53 +0000 |
| commit | ff4efb1a4d232c4ac063ff38f5985661ea97b37e (patch) | |
| tree | 0dfc86951e16ff791f5f7d5beba7b461b60a44ff /internal/postgres | |
| parent | 6657ef22c5588415c202445532bd23498217f364 (diff) | |
| download | go-x-pkgsite-ff4efb1a4d232c4ac063ff38f5985661ea97b37e.tar.xz | |
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>
Diffstat (limited to 'internal/postgres')
| -rw-r--r-- | internal/postgres/details_test.go | 38 | ||||
| -rw-r--r-- | internal/postgres/insert_module_test.go | 22 | ||||
| -rw-r--r-- | internal/postgres/search_test.go | 30 | ||||
| -rw-r--r-- | internal/postgres/version_test.go | 24 |
4 files changed, 57 insertions, 57 deletions
diff --git a/internal/postgres/details_test.go b/internal/postgres/details_test.go index f1916cbf..8d719463 100644 --- a/internal/postgres/details_test.go +++ b/internal/postgres/details_test.go @@ -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) } }) } diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go index 3468bad2..fe616b8a 100644 --- a/internal/postgres/insert_module_test.go +++ b/internal/postgres/insert_module_test.go @@ -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) } } } diff --git a/internal/postgres/search_test.go b/internal/postgres/search_test.go index 6ca5d9f3..6a85cd80 100644 --- a/internal/postgres/search_test.go +++ b/internal/postgres/search_test.go @@ -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) } }) } diff --git a/internal/postgres/version_test.go b/internal/postgres/version_test.go index 694d9d54..3bae815f 100644 --- a/internal/postgres/version_test.go +++ b/internal/postgres/version_test.go @@ -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) } } } |
