Skip to content

Commit d530546

Browse files
committed
fix sort ordering bug in dmem
1 parent 99c7f96 commit d530546

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7738,9 +7738,12 @@ func (q *FakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
77387738
w2 := workspaces[j]
77397739

77407740
// Order by: favorite first
7741-
if w1.FavoriteOf == arg.OrderByFavorite {
7741+
if w1.FavoriteOf == arg.OrderByFavorite && w2.FavoriteOf != arg.OrderByFavorite {
77427742
return true
77437743
}
7744+
if w1.FavoriteOf != arg.OrderByFavorite && w2.FavoriteOf == arg.OrderByFavorite {
7745+
return false
7746+
}
77447747

77457748
// Order by: running
77467749
w1IsRunning := isRunning(preloadedWorkspaceBuilds[w1.ID], preloadedProvisionerJobs[w1.ID])
@@ -7755,12 +7758,12 @@ func (q *FakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
77557758
}
77567759

77577760
// Order by: usernames
7758-
if w1.ID != w2.ID {
7759-
return sort.StringsAreSorted([]string{preloadedUsers[w1.ID].Username, preloadedUsers[w2.ID].Username})
7761+
if strings.Compare(preloadedUsers[w1.ID].Username, preloadedUsers[w2.ID].Username) < 0 {
7762+
return true
77607763
}
77617764

77627765
// Order by: workspace names
7763-
return sort.StringsAreSorted([]string{w1.Name, w2.Name})
7766+
return strings.Compare(w1.Name, w2.Name) < 0
77647767
})
77657768

77667769
beforePageCount := len(workspaces)

coderd/workspaces_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,6 @@ func TestAdminViewAllWorkspaces(t *testing.T) {
479479
func TestWorkspacesSortOrder(t *testing.T) {
480480
t.Parallel()
481481

482-
if !dbtestutil.WillUsePostgres() {
483-
t.Skip("sort order is only tested on postgres")
484-
}
485-
486482
client, db := coderdtest.NewWithDatabase(t, nil)
487483
firstUser := coderdtest.CreateFirstUser(t, client)
488484
secondUserClient, secondUser := coderdtest.CreateAnotherUserMutators(t, client, firstUser.OrganizationID, []string{"owner"}, func(r *codersdk.CreateUserRequest) {
@@ -534,7 +530,7 @@ func TestWorkspacesSortOrder(t *testing.T) {
534530
// 2. Running workspaces
535531
// 3. Sort by usernames
536532
// 4. Sort by workspace names
537-
require.Equal(t, expectedNames, actualNames)
533+
assert.Equal(t, expectedNames, actualNames)
538534

539535
// Once again but this time as a different user. This time we do not expect to see another
540536
// user's favorites first.
@@ -561,7 +557,7 @@ func TestWorkspacesSortOrder(t *testing.T) {
561557
// 2. Running workspaces
562558
// 3. Sort by usernames
563559
// 4. Sort by workspace names
564-
require.Equal(t, expectedNames, actualNames)
560+
assert.Equal(t, expectedNames, actualNames)
565561
}
566562

567563
func TestPostWorkspacesByOrganization(t *testing.T) {

0 commit comments

Comments
 (0)