mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
chore: alphabetize template list (#3363)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -1889,7 +1889,7 @@ func (q *sqlQuerier) GetTemplateByOrganizationAndName(ctx context.Context, arg G
|
||||
|
||||
const getTemplates = `-- name: GetTemplates :many
|
||||
SELECT id, created_at, updated_at, organization_id, deleted, name, provisioner, active_version_id, description, max_ttl, min_autostart_interval, created_by FROM templates
|
||||
ORDER BY (created_at, id) ASC
|
||||
ORDER BY (name, id) ASC
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetTemplates(ctx context.Context) ([]Template, error) {
|
||||
@@ -1954,7 +1954,7 @@ WHERE
|
||||
id = ANY($4)
|
||||
ELSE true
|
||||
END
|
||||
ORDER BY (created_at, id) ASC
|
||||
ORDER BY (name, id) ASC
|
||||
`
|
||||
|
||||
type GetTemplatesWithFilterParams struct {
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user