diff options
| author | Julie Qiu <julie@golang.org> | 2019-04-02 16:00:29 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-03-27 16:46:34 -0400 |
| commit | bc4d221c928f2c71fd131d08492aaabb2c90a890 (patch) | |
| tree | 7e23402497b41fb2d8c27193c2fd371c99c2a899 /internal/postgres/postgres_test.go | |
| parent | c117934280014cba318e2888d0c21944270e9a49 (diff) | |
| download | go-x-pkgsite-bc4d221c928f2c71fd131d08492aaabb2c90a890.tar.xz | |
internal/postgres: fix errors in GetLatestPackageForPaths
GetLatestPackageForPaths originally was not pulling expected packages,
due to how the WHERE clause param was being passed in.
It is fixed in this CLs along with the tests.
Change-Id: Ia377175bd6a51fe4fd53ea3d8ccc2c1dfc377ecb
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/443360
Reviewed-by: Channing Kimble-Brown <ckimblebrown@google.com>
Diffstat (limited to 'internal/postgres/postgres_test.go')
| -rw-r--r-- | internal/postgres/postgres_test.go | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/internal/postgres/postgres_test.go b/internal/postgres/postgres_test.go index b382ee6e..ac6bc281 100644 --- a/internal/postgres/postgres_test.go +++ b/internal/postgres/postgres_test.go @@ -6,7 +6,6 @@ package postgres import ( "database/sql" - "fmt" "testing" "time" @@ -35,22 +34,6 @@ func versionsDiff(v1, v2 *internal.Version) string { "CreatedAt", "UpdatedAt", "Module.Series", "VersionType", "Packages", "Module.Versions")) } -// packagesDiff takes two packages, p1 and p2, and returns a string description -// of the difference between them. If they are the same they will be -// empty. -func packagesDiff(p1, p2 *internal.Package) string { - if p1 == nil && p2 == nil { - return "" - } - - if (p1 != nil && p2 == nil) || (p1 == nil && p2 != nil) { - return "not equal" - } - - return fmt.Sprintf("%v%v", cmp.Diff(*p1, *p2, cmpopts.IgnoreFields(internal.Package{}, "Version")), - versionsDiff(p1.Version, p2.Version)) -} - func TestPostgres_ReadAndWriteVersionAndPackages(t *testing.T) { var ( now = time.Now() @@ -211,8 +194,7 @@ func TestPostgres_ReadAndWriteVersionAndPackages(t *testing.T) { } - gotPkg.Version = nil - if diff := cmp.Diff(*gotPkg, *wantPkg); diff != "" { + if diff := cmp.Diff(gotPkg, wantPkg, cmpopts.IgnoreFields(internal.Package{}, "Version")); diff != "" { t.Errorf("db.GetPackage(%q, %q) Package mismatch (-want +got):\n%s", tc.pkgpath, tc.version, diff) } }) @@ -314,7 +296,7 @@ func TestPostgres_GetLatestPackage(t *testing.T) { t.Errorf("db.GetLatestPackage(%q): %v", tc.path, err) } - if diff := packagesDiff(gotPkg, tc.wantPkg); diff != "" { + if diff := cmp.Diff(gotPkg, tc.wantPkg, cmpopts.IgnoreFields(internal.Package{}, "Version.UpdatedAt", "Version.CreatedAt")); diff != "" { t.Errorf("db.GetLatestPackage(%q) = %v, want %v, diff is %v", tc.path, gotPkg, tc.wantPkg, diff) } @@ -586,11 +568,8 @@ func TestPostgres_GetLatestPackageForPaths(t *testing.T) { t.Errorf("db.GetLatestPackageForPaths(%q): %v", tc.paths, err) } - for i, gotPkg := range gotPkgs { - if diff := packagesDiff(gotPkg, tc.wantPkgs[i]); diff != "" { - t.Errorf("got %v at index %v, want %v, diff is %v", - gotPkg, i, tc.wantPkgs[i], diff) - } + if diff := cmp.Diff(gotPkgs, tc.wantPkgs); diff != "" { + t.Errorf("cmp.Diff(gotPkgs, tc.wantPkgs): %s", diff) } } |
