Skip to content

Commit

Permalink
Merge pull request #417 from hashicorp/jspiker/agent-pool-search
Browse files Browse the repository at this point in the history
Add query option to agent pool list options
  • Loading branch information
sebasslash committed Jul 13, 2022
2 parents 0568f29 + 62d1a46 commit 833ec49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# Unreleased

* [beta] Add support for triggering Workspace runs through matching Git tags [#434](https://github.com/hashicorp/go-tfe/pull/434)
* Add `Query` param field to `AgentPoolListOptions` to allow searching based on agent pool name, by @JarrettSpiker [#417](https://github.com/hashicorp/go-tfe/pull/417)
* Add organization scope and allowed workspaces field for scope agents by @Netra2104 [#453](https://github.com/hashicorp/go-tfe/pull/453)

## Bug fixes
Expand Down
3 changes: 3 additions & 0 deletions agent_pool.go
Expand Up @@ -72,6 +72,9 @@ type AgentPoolListOptions struct {
// Optional: A list of relations to include. See available resources
// https://www.terraform.io/cloud-docs/api-docs/agents#available-related-resources
Include []AgentPoolIncludeOpt `url:"include,omitempty"`

// Optional: A search query string used to filter agent pool. Agent pools are searchable by name
Query string `url:"q,omitempty"`
}

// AgentPoolCreateOptions represents the options for creating an agent pool.
Expand Down
15 changes: 15 additions & 0 deletions agent_pool_integration_test.go
Expand Up @@ -68,6 +68,21 @@ func TestAgentPoolsList(t *testing.T) {
assert.Nil(t, pools)
assert.EqualError(t, err, ErrInvalidOrg.Error())
})

t.Run("with query options", func(t *testing.T) {

pools, err := client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{
Query: agentPool.Name,
})
require.NoError(t, err)
assert.Equal(t, len(pools.Items), 1)

pools, err = client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{
Query: agentPool.Name + "not_going_to_match",
})
require.NoError(t, err)
assert.Empty(t, pools.Items)
})
}

func TestAgentPoolsCreate(t *testing.T) {
Expand Down

0 comments on commit 833ec49

Please sign in to comment.