Skip to content

Commit f14efd1

Browse files
authored
chore: alphabetize template list (#3363)
1 parent 854bb5d commit f14efd1

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

cli/templatelist_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli_test
22

33
import (
4+
"sort"
45
"testing"
56

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

40+
// expect that templates are listed alphebetically
41+
var templatesList = []string{firstTemplate.Name, secondTemplate.Name}
42+
sort.Strings(templatesList)
43+
3944
require.NoError(t, <-errC)
4045

41-
pty.ExpectMatch(firstTemplate.Name)
42-
pty.ExpectMatch(secondTemplate.Name)
46+
for _, name := range templatesList {
47+
pty.ExpectMatch(name)
48+
}
4349
})
4450
t.Run("NoTemplates", func(t *testing.T) {
4551
t.Parallel()

coderd/database/databasefake/databasefake.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,8 @@ func (q *fakeQuerier) GetTemplatesWithFilter(_ context.Context, arg database.Get
897897
}
898898
if len(templates) > 0 {
899899
slices.SortFunc(templates, func(i, j database.Template) bool {
900-
if !i.CreatedAt.Before(j.CreatedAt) {
901-
return false
900+
if i.Name != j.Name {
901+
return i.Name < j.Name
902902
}
903903
return i.ID.String() < j.ID.String()
904904
})
@@ -1080,8 +1080,8 @@ func (q *fakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro
10801080

10811081
templates := slices.Clone(q.templates)
10821082
slices.SortFunc(templates, func(i, j database.Template) bool {
1083-
if !i.CreatedAt.Before(j.CreatedAt) {
1084-
return false
1083+
if i.Name != j.Name {
1084+
return i.Name < j.Name
10851085
}
10861086
return i.ID.String() < j.ID.String()
10871087
})

coderd/database/queries.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ WHERE
3434
id = ANY(@ids)
3535
ELSE true
3636
END
37-
ORDER BY (created_at, id) ASC
37+
ORDER BY (name, id) ASC
3838
;
3939

4040
-- name: GetTemplateByOrganizationAndName :one
@@ -51,7 +51,7 @@ LIMIT
5151

5252
-- name: GetTemplates :many
5353
SELECT * FROM templates
54-
ORDER BY (created_at, id) ASC
54+
ORDER BY (name, id) ASC
5555
;
5656

5757
-- name: InsertTemplate :one

0 commit comments

Comments
 (0)