diff --git a/CHANGELOG.md b/CHANGELOG.md index ea102592d..7ee8fafed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Unreleased +## Enhancements + * Add BETA support for Action invocations via `CreateRunOptions` by @mutahhir [#1206](https://github.com/hashicorp/go-tfe/pull/1206) +* Add `Sort` option to `Agents` and `AgentPools`, by @twitnithegirl [#1229](https://github.com/hashicorp/go-tfe/pull/1229) # v1.93.0 diff --git a/agent.go b/agent.go index 379b67a65..1a61393d4 100644 --- a/agent.go +++ b/agent.go @@ -49,6 +49,9 @@ type AgentListOptions struct { //Optional: LastPingSince time.Time `url:"filter[last-ping-since],omitempty,iso8601"` + + // Optional: Allows sorting the agents by "created-by" + Sort string `url:"sort,omitempty"` } // Read a single agent by its ID diff --git a/agent_pool.go b/agent_pool.go index a9c92e0ff..3d5a5c082 100644 --- a/agent_pool.go +++ b/agent_pool.go @@ -102,6 +102,9 @@ type AgentPoolListOptions struct { // Optional: String (project name) used to filter the results. AllowedProjectsName string `url:"filter[allowed_projects][name],omitempty"` + + // Optional: Allows sorting the agent pools by "created-by" or "name" + Sort string `url:"sort,omitempty"` } // AgentPoolCreateOptions represents the options for creating an agent pool. diff --git a/agent_pool_integration_test.go b/agent_pool_integration_test.go index 3e06cc554..f77999fc0 100644 --- a/agent_pool_integration_test.go +++ b/agent_pool_integration_test.go @@ -64,6 +64,27 @@ func TestAgentPoolsList(t *testing.T) { assert.Equal(t, 1, pools.TotalCount) }) + t.Run("with sorting", func(t *testing.T) { + agentPool2, agentPoolCleanup2 := createAgentPool(t, client, orgTest) + t.Cleanup(agentPoolCleanup2) + + pools, err := client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{ + Sort: "created-at", + }) + require.NoError(t, err) + require.NotNil(t, pools) + require.Len(t, pools.Items, 2) + require.Equal(t, []string{agentPool.ID, agentPool2.ID}, []string{pools.Items[0].ID, pools.Items[1].ID}) + + pools, err = client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{ + Sort: "-created-at", + }) + require.NoError(t, err) + require.NotNil(t, pools) + require.Len(t, pools.Items, 2) + require.Equal(t, []string{agentPool2.ID, agentPool.ID}, []string{pools.Items[0].ID, pools.Items[1].ID}) + }) + t.Run("without a valid organization", func(t *testing.T) { pools, err := client.AgentPools.List(ctx, badIdentifier, nil) assert.Nil(t, pools)