Skip to content

Commit 28c2316

Browse files
committed
add sorting to agent list and agent pool list
1 parent 9797b31 commit 28c2316

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type AgentListOptions struct {
4949

5050
//Optional:
5151
LastPingSince time.Time `url:"filter[last-ping-since],omitempty,iso8601"`
52+
53+
// Optional: Allows sorting the agents by "created-by"
54+
Sort string `url:"sort,omitempty"`
5255
}
5356

5457
// Read a single agent by its ID

agent_integration_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestAgentsRead(t *testing.T) {
2323
upgradeOrganizationSubscription(t, client, org)
2424

2525
agent, _, agentCleanup := createAgent(t, client, org)
26+
agent2, _, agentCleanup := createAgent(t, client, org)
2627

2728
t.Cleanup(agentCleanup)
2829

@@ -67,6 +68,24 @@ func TestAgentsList(t *testing.T) {
6768
assert.NotEmpty(t, agent.Items[0].ID)
6869
})
6970

71+
t.Run("with sorting", func(t *testing.T) {
72+
agents, err := client.Agents.List(ctx, agentPool.ID, &AgentListOptions{
73+
Sort: "created-at",
74+
})
75+
require.NoError(t, err)
76+
require.NotNil(t, agents)
77+
require.Len(t, agents.Items, 2)
78+
require.Equal(t, []string{agent1.ID, agent2.ID}, []string{agents.Items[0].ID, agents.Items[1].ID})
79+
80+
agents, err = client.Agents.List(ctx, agentPool.ID, &AgentListOptions{
81+
Sort: "-created-at",
82+
})
83+
require.NoError(t, err)
84+
require.NotNil(t, agents)
85+
require.Len(t, agents.Items, 2)
86+
require.Equal(t, []string{agent2.ID, agent1.ID}, []string{agents.Items[0].ID, agents.Items[1].ID})
87+
})
88+
7089
t.Run("without a valid agent pool ID", func(t *testing.T) {
7190
agent, err := client.Agents.List(ctx, badIdentifier, nil)
7291
assert.Nil(t, agent)

agent_pool.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ type AgentPoolListOptions struct {
8585

8686
// Optional: String (workspace name) used to filter the results.
8787
AllowedWorkspacesName string `url:"filter[allowed_workspaces][name],omitempty"`
88+
89+
// Optional: Allows sorting the agent pools by "created-by" or "name"
90+
Sort string `url:"sort,omitempty"`
8891
}
8992

9093
// AgentPoolCreateOptions represents the options for creating an agent pool.

agent_pool_integration_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func TestAgentPoolsList(t *testing.T) {
2222

2323
agentPool, agentPoolCleanup := createAgentPool(t, client, orgTest)
2424
defer agentPoolCleanup()
25+
agentPool2, agentPoolCleanup2 := createAgentPool(t, client, orgTest)
26+
defer agentPoolCleanup2()
2527

2628
t.Run("without list options", func(t *testing.T) {
2729
pools, err := client.AgentPools.List(ctx, orgTest.Name, nil)
@@ -64,6 +66,23 @@ func TestAgentPoolsList(t *testing.T) {
6466
assert.Equal(t, 999, pools.CurrentPage)
6567
assert.Equal(t, 1, pools.TotalCount)
6668
})
69+
t.Run("with sorting", func(t *testing.T) {
70+
pools, err := client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{
71+
Sort: "created-at",
72+
})
73+
require.NoError(t, err)
74+
require.NotNil(t, pools)
75+
require.Len(t, pools.Items, 2)
76+
require.Equal(t, []string{agentPool.ID, agentPool2.ID}, []string{pools.Items[0].ID, pools.Items[1].ID})
77+
78+
pools, err = client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{
79+
Sort: "-created-at",
80+
})
81+
require.NoError(t, err)
82+
require.NotNil(t, pools)
83+
require.Len(t, pools.Items, 2)
84+
require.Equal(t, []string{agentPool2.ID, agentPool.ID}, []string{pools.Items[0].ID, pools.Items[1].ID})
85+
})
6786

6887
t.Run("without a valid organization", func(t *testing.T) {
6988
pools, err := client.AgentPools.List(ctx, badIdentifier, nil)

0 commit comments

Comments
 (0)