Skip to content

Commit

Permalink
Use shadow variables for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol committed Nov 17, 2023
1 parent e885028 commit c2df4c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion prefetch_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestCreatePrefetchDB(t *testing.T) {
require.NoError(t, err)
for res.Next() {
var pkg Package
err = res.Scan(&pkg.PackageName, &pkg.Version, &pkg.Arch, &pkg.RepoName, &pkg.LastTimeDownloaded, &pkg.LastTimeRepoUpdated)
err := res.Scan(&pkg.PackageName, &pkg.Version, &pkg.Arch, &pkg.RepoName, &pkg.LastTimeDownloaded, &pkg.LastTimeRepoUpdated)
require.NoError(t, err)
require.Failf(t, "createPrefetchDB shouldn't create entries in %v\n", table)
}
Expand Down
7 changes: 3 additions & 4 deletions prefetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ func TestUpdateDBRequestedFile(t *testing.T) {
if res.Next() {
var got Package
now := time.Now()
err = res.Scan(&got.PackageName, &got.Version, &got.Arch, &got.RepoName, &got.LastTimeDownloaded, &got.LastTimeRepoUpdated)
err := res.Scan(&got.PackageName, &got.Version, &got.Arch, &got.RepoName, &got.LastTimeDownloaded, &got.LastTimeRepoUpdated)
require.NoError(t, err)

want := Package{PackageName: "webkit", Version: "2.3.1-1", Arch: "x86_64", RepoName: "foo", LastTimeDownloaded: &now, LastTimeRepoUpdated: &now}
require.True(t, cmp.Equal(got, want, cmpopts.IgnoreFields(Package{}, "LastTimeDownloaded", "LastTimeRepoUpdated")))
// require.Equal(t, want, got)
dist := want.LastTimeDownloaded.Sub(*got.LastTimeDownloaded)
require.Greater(t, dist, -5*time.Second)
require.Less(t, dist, 5*time.Second)
Expand Down Expand Up @@ -145,7 +144,8 @@ func TestUpdateDBPrefetchedFile(t *testing.T) {
for res.Next() {
var got Package
now := time.Now()
err = res.Scan(&got.PackageName, &got.Version, &got.Arch, &got.RepoName, &got.LastTimeDownloaded, &got.LastTimeRepoUpdated)
err := res.Scan(&got.PackageName, &got.Version, &got.Arch, &got.RepoName, &got.LastTimeDownloaded, &got.LastTimeRepoUpdated)
require.NoError(t, err)

want := Package{PackageName: "webkit", Version: "2.5.10-4", Arch: "x86_64", RepoName: "foo", LastTimeDownloaded: &now, LastTimeRepoUpdated: &now}
require.True(t, cmp.Equal(got, want, cmpopts.IgnoreFields(Package{}, "LastTimeDownloaded", "LastTimeRepoUpdated")))
Expand All @@ -156,7 +156,6 @@ func TestUpdateDBPrefetchedFile(t *testing.T) {
dist = want.LastTimeRepoUpdated.Sub(*got.LastTimeRepoUpdated)
require.Greater(t, dist, -5*time.Second)
require.Less(t, dist, 5*time.Second)
require.NoError(t, err)
counter++
}
require.Equal(t, 1, counter, "Too many entries")
Expand Down

0 comments on commit c2df4c9

Please sign in to comment.