Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query option to agent pool list options #417

Merged
merged 2 commits into from Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"`
JarrettSpiker marked this conversation as resolved.
Show resolved Hide resolved
}

// 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) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I believe you mentioned this query param was sitting behind a feature flag... in which case skipIfBeta(t) test helper will need to be added to this subtest otherwise the test will fail in CI... I don't think tflocal has the flag enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebasslash sorry, took a vacation and let this review sit for a bit. The flag is now on in production, and it looks like we are seeing the tests pass!

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