-
Notifications
You must be signed in to change notification settings - Fork 899
feat: sort users by username #7838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1579,10 +1579,7 @@ func TestPaginatedUsers(t *testing.T) { | |
err = eg.Wait() | ||
require.NoError(t, err, "create users failed") | ||
|
||
// Sorting the users will sort by (created_at, uuid). This is to handle | ||
// the off case that created_at is identical for 2 users. | ||
// This is a really rare case in production, but does happen in unit tests | ||
// due to the fake database being in memory and exceptionally quick. | ||
// Sorting the users will sort by username. | ||
sortUsers(allUsers) | ||
sortUsers(specialUsers) | ||
|
||
|
@@ -1697,10 +1694,7 @@ func assertPagination(ctx context.Context, t *testing.T, client *codersdk.Client | |
// sortUsers sorts by (created_at, id) | ||
func sortUsers(users []codersdk.User) { | ||
sort.Slice(users, func(i, j int) bool { | ||
if users[i].CreatedAt.Equal(users[j].CreatedAt) { | ||
return users[i].ID.String() < users[j].ID.String() | ||
} | ||
return users[i].CreatedAt.Before(users[j].CreatedAt) | ||
return sort.StringsAreSorted([]string{users[i].Username, users[j].Username}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: This is essentially just a
a.Username < b.Username
comparison, could be simplified.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed