Skip to content

Commit 9543c78

Browse files
committed
add sort option for agent list and agent pool list
1 parent 05fd1dc commit 9543c78

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-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_pool.go

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

103103
// Optional: String (project name) used to filter the results.
104104
AllowedProjectsName string `url:"filter[allowed_projects][name],omitempty"`
105+
106+
// Optional: Allows sorting the agent pools by "created-by" or "name"
107+
Sort string `url:"sort,omitempty"`
105108
}
106109

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

agent_pool_integration_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,27 @@ func TestAgentPoolsList(t *testing.T) {
6464
assert.Equal(t, 1, pools.TotalCount)
6565
})
6666

67+
t.Run("with sorting", func(t *testing.T) {
68+
agentPool2, agentPoolCleanup2 := createAgentPool(t, client, orgTest)
69+
t.Cleanup(agentPoolCleanup2)
70+
71+
pools, err := client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{
72+
Sort: "created-at",
73+
})
74+
require.NoError(t, err)
75+
require.NotNil(t, pools)
76+
require.Len(t, pools.Items, 2)
77+
require.Equal(t, []string{agentPool.ID, agentPool2.ID}, []string{pools.Items[0].ID, pools.Items[1].ID})
78+
79+
pools, err = client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{
80+
Sort: "-created-at",
81+
})
82+
require.NoError(t, err)
83+
require.NotNil(t, pools)
84+
require.Len(t, pools.Items, 2)
85+
require.Equal(t, []string{agentPool2.ID, agentPool.ID}, []string{pools.Items[0].ID, pools.Items[1].ID})
86+
})
87+
6788
t.Run("without a valid organization", func(t *testing.T) {
6889
pools, err := client.AgentPools.List(ctx, badIdentifier, nil)
6990
assert.Nil(t, pools)

0 commit comments

Comments
 (0)