diff --git a/database/integration_test.go b/database/integration_test.go index 778c30849..d85442d98 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -539,8 +539,8 @@ func testLogs(t *testing.T, db Interface, resources *Resources) { if int(count) != len(resources.Logs) { t.Errorf("ListLogsForBuild() is %v, want %v", count, len(resources.Logs)) } - if !reflect.DeepEqual(list, []*library.Log{resources.Logs[2], resources.Logs[3], resources.Logs[0], resources.Logs[1]}) { - t.Errorf("ListLogsForBuild() is %v, want %v", list, []*library.Log{resources.Logs[2], resources.Logs[3], resources.Logs[0], resources.Logs[1]}) + if !reflect.DeepEqual(list, resources.Logs) { + t.Errorf("ListLogsForBuild() is %v, want %v", list, resources.Logs) } counter++ diff --git a/database/log/list_build.go b/database/log/list_build.go index 58ca12111..ab083a706 100644 --- a/database/log/list_build.go +++ b/database/log/list_build.go @@ -37,6 +37,7 @@ func (e *engine) ListLogsForBuild(b *library.Build, page, perPage int) ([]*libra err = e.client. Table(constants.TableLog). Where("build_id = ?", b.GetID()). + Order("service_id ASC NULLS LAST"). Order("step_id ASC"). Limit(perPage). Offset(offset). diff --git a/database/log/list_build_test.go b/database/log/list_build_test.go index fb08236e9..cf20fb50e 100644 --- a/database/log/list_build_test.go +++ b/database/log/list_build_test.go @@ -49,7 +49,7 @@ func TestLog_Engine_ListLogsForBuild(t *testing.T) { AddRow(1, 1, 1, 1, 0, []byte{}).AddRow(2, 1, 1, 0, 1, []byte{}) // ensure the mock expects the query - _mock.ExpectQuery(`SELECT * FROM "logs" WHERE build_id = $1 ORDER BY step_id ASC LIMIT 10`).WithArgs(1).WillReturnRows(_rows) + _mock.ExpectQuery(`SELECT * FROM "logs" WHERE build_id = $1 ORDER BY service_id ASC NULLS LAST,step_id ASC LIMIT 10`).WithArgs(1).WillReturnRows(_rows) _sqlite := testSqlite(t) defer func() { _sql, _ := _sqlite.client.DB(); _sql.Close() }()