diff --git a/coderd/workspaceresources.go b/coderd/workspaceresources.go index f933753bd022b..61f5ff2f4101e 100644 --- a/coderd/workspaceresources.go +++ b/coderd/workspaceresources.go @@ -4,6 +4,7 @@ import ( "database/sql" "errors" "net/http" + "sort" "github.com/google/uuid" @@ -79,6 +80,9 @@ func (api *API) workspaceResource(rw http.ResponseWriter, r *http.Request) { } apiAgents = append(apiAgents, convertedAgent) } + sort.Slice(apiAgents, func(i, j int) bool { + return apiAgents[i].Name < apiAgents[j].Name + }) metadata, err := api.Database.GetWorkspaceResourceMetadataByResourceID(r.Context(), workspaceResource.ID) if err != nil { diff --git a/coderd/workspaceresources_test.go b/coderd/workspaceresources_test.go index 885c9a27b87c9..d1ca6517f3046 100644 --- a/coderd/workspaceresources_test.go +++ b/coderd/workspaceresources_test.go @@ -28,6 +28,11 @@ func TestWorkspaceResource(t *testing.T) { Type: "example", Agents: []*proto.Agent{{ Id: "something", + Name: "b", + Auth: &proto.Agent_Token{}, + }, { + Id: "another", + Name: "a", Auth: &proto.Agent_Token{}, }}, }}, @@ -41,8 +46,12 @@ func TestWorkspaceResource(t *testing.T) { coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID) resources, err := client.WorkspaceResourcesByBuild(context.Background(), workspace.LatestBuild.ID) require.NoError(t, err) - _, err = client.WorkspaceResource(context.Background(), resources[0].ID) + resource, err := client.WorkspaceResource(context.Background(), resources[0].ID) require.NoError(t, err) + require.Len(t, resource.Agents, 2) + // Ensure it's sorted alphabetically! + require.Equal(t, "a", resource.Agents[0].Name) + require.Equal(t, "b", resource.Agents[1].Name) }) t.Run("Apps", func(t *testing.T) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy