Skip to content

Commit

Permalink
fix: add second order to ensure order consistency (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3r authored Aug 18, 2021
1 parent 1c014de commit a132a3c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions database/postgres/build_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (c *client) GetOrgBuildList(org string, filters map[string]string, page, pe
Joins("JOIN repos ON builds.repo_id = repos.id and repos.org = ?", org).
Where(filters).
Order("created DESC").
Order("id").
Limit(perPage).
Offset(offset).
Scan(b).Error
Expand Down
6 changes: 3 additions & 3 deletions database/postgres/build_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestPostgres_Client_GetOrgBuildList(t *testing.T) {
AddRow(2, 1, 2, 0, "", "", "", 0, 0, 0, 0, "", nil, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 0)

// ensure the mock expects the query
_mock.ExpectQuery("SELECT builds.* FROM \"builds\" JOIN repos ON builds.repo_id = repos.id and repos.org = $1 ORDER BY created DESC LIMIT 10").WillReturnRows(_rows)
_mock.ExpectQuery("SELECT builds.* FROM \"builds\" JOIN repos ON builds.repo_id = repos.id and repos.org = $1 ORDER BY created DESC,id LIMIT 10").WillReturnRows(_rows)

// setup tests
tests := []struct {
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestPostgres_Client_GetOrgBuildList_NonAdmin(t *testing.T) {
).AddRow(1, 1, 1, 0, "", "", "", 0, 0, 0, 0, "", nil, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 0)

// ensure the mock expects the query
_mock.ExpectQuery("SELECT builds.* FROM \"builds\" JOIN repos ON builds.repo_id = repos.id and repos.org = $1 WHERE \"visibility\" = $2 ORDER BY created DESC LIMIT 10").WillReturnRows(_rows)
_mock.ExpectQuery("SELECT builds.* FROM \"builds\" JOIN repos ON builds.repo_id = repos.id and repos.org = $1 WHERE \"visibility\" = $2 ORDER BY created DESC,id LIMIT 10").WillReturnRows(_rows)

// setup tests
tests := []struct {
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestPostgres_Client_GetOrgBuildListByEvent(t *testing.T) {
AddRow(2, 1, 2, 0, "", "", "", 0, 0, 0, 0, "", nil, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 0)

// ensure the mock expects the query
_mock.ExpectQuery("SELECT builds.* FROM \"builds\" JOIN repos ON builds.repo_id = repos.id and repos.org = $1 WHERE \"event\" = $2 ORDER BY created DESC LIMIT 10").WillReturnRows(_rows)
_mock.ExpectQuery("SELECT builds.* FROM \"builds\" JOIN repos ON builds.repo_id = repos.id and repos.org = $1 WHERE \"event\" = $2 ORDER BY created DESC,id LIMIT 10").WillReturnRows(_rows)

// setup tests
tests := []struct {
Expand Down
1 change: 1 addition & 0 deletions database/sqlite/build_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (c *client) GetOrgBuildList(org string, filters map[string]string, page int
Joins("JOIN repos ON builds.repo_id = repos.id AND repos.org = ?", org).
Where(filters).
Order("created DESC").
Order("id").
Limit(perPage).
Offset(offset).
Scan(b).Error
Expand Down

0 comments on commit a132a3c

Please sign in to comment.