Skip to content

chore: alphabetize template list #3363

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

Merged
merged 2 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions cli/templatelist_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli_test

import (
"sort"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -36,10 +37,15 @@ func TestTemplateList(t *testing.T) {
errC <- cmd.Execute()
}()

// expect that templates are listed alphebetically
var templatesList = []string{firstTemplate.Name, secondTemplate.Name}
sort.Strings(templatesList)

require.NoError(t, <-errC)

pty.ExpectMatch(firstTemplate.Name)
pty.ExpectMatch(secondTemplate.Name)
for _, name := range templatesList {
pty.ExpectMatch(name)
}
})
t.Run("NoTemplates", func(t *testing.T) {
t.Parallel()
Expand Down
8 changes: 4 additions & 4 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,8 @@ func (q *fakeQuerier) GetTemplatesWithFilter(_ context.Context, arg database.Get
}
if len(templates) > 0 {
slices.SortFunc(templates, func(i, j database.Template) bool {
if !i.CreatedAt.Before(j.CreatedAt) {
return false
if i.Name != j.Name {
return i.Name < j.Name
}
return i.ID.String() < j.ID.String()
})
Expand Down Expand Up @@ -1080,8 +1080,8 @@ func (q *fakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro

templates := slices.Clone(q.templates)
slices.SortFunc(templates, func(i, j database.Template) bool {
if !i.CreatedAt.Before(j.CreatedAt) {
return false
if i.Name != j.Name {
return i.Name < j.Name
}
return i.ID.String() < j.ID.String()
})
Expand Down
4 changes: 2 additions & 2 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions coderd/database/queries/templates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ WHERE
id = ANY(@ids)
ELSE true
END
ORDER BY (created_at, id) ASC
ORDER BY (name, id) ASC
;

-- name: GetTemplateByOrganizationAndName :one
Expand All @@ -51,7 +51,7 @@ LIMIT

-- name: GetTemplates :many
SELECT * FROM templates
ORDER BY (created_at, id) ASC
ORDER BY (name, id) ASC
;

-- name: InsertTemplate :one
Expand Down