Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Add sorting to databasefake as well
  • Loading branch information
mafredri committed Jul 27, 2022
commit c0498a9c1586b3d1b030ac2675fbca994b1dfd15
13 changes: 11 additions & 2 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ func (q *fakeQuerier) GetLatestWorkspaceBuildsByWorkspaceIDs(_ context.Context,
}

func (q *fakeQuerier) GetWorkspaceBuildByWorkspaceID(_ context.Context,
params database.GetWorkspaceBuildByWorkspaceIDParams) ([]database.WorkspaceBuild, error) {
params database.GetWorkspaceBuildByWorkspaceIDParams,
) ([]database.WorkspaceBuild, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

Expand Down Expand Up @@ -893,6 +894,9 @@ func (q *fakeQuerier) GetTemplatesWithFilter(_ context.Context, arg database.Get
templates = append(templates, template)
}
if len(templates) > 0 {
slices.SortFunc(templates, func(i, j database.Template) bool {
return i.CreatedAt.Before(j.CreatedAt) && i.ID.String() < j.ID.String()
})
return templates, nil
}

Expand Down Expand Up @@ -1069,7 +1073,12 @@ func (q *fakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro
q.mutex.RLock()
defer q.mutex.RUnlock()

return q.templates[:], nil
templates := slices.Clone(q.templates)
slices.SortFunc(templates, func(i, j database.Template) bool {
return i.CreatedAt.Before(j.CreatedAt) && i.ID.String() < j.ID.String()
})

return templates, nil
}

func (q *fakeQuerier) GetOrganizationMemberByUserID(_ context.Context, arg database.GetOrganizationMemberByUserIDParams) (database.OrganizationMember, error) {
Expand Down