Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions agent_pool_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading