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 1 commit
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
Prev Previous commit
alphabetize templates in tests and databasefake
  • Loading branch information
bpmct committed Aug 4, 2022
commit 10717542fec0a01d23ee2c498d1e4a9cdd9b2340
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