From 579ac30e6e89d7e37b6a24eeb0009ad0c236ebc7 Mon Sep 17 00:00:00 2001 From: Jarrett Spiker Date: Tue, 31 May 2022 16:22:27 -0400 Subject: [PATCH 1/2] Add query option to agent pool list options --- agent_pool.go | 2 ++ agent_pool_integration_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/agent_pool.go b/agent_pool.go index 8905cc4b7..d9f08052f 100644 --- a/agent_pool.go +++ b/agent_pool.go @@ -72,6 +72,8 @@ 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"` + + Query string `url:"q,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 ee2ddf5d2..1eb0abf4d 100644 --- a/agent_pool_integration_test.go +++ b/agent_pool_integration_test.go @@ -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) { From 62d1a460a3e4a26c25f5d6f1a143acd975a2910e Mon Sep 17 00:00:00 2001 From: Jarrett Spiker Date: Wed, 1 Jun 2022 10:26:10 -0400 Subject: [PATCH 2/2] Update changelog with agent pool query parameter enhancement --- CHANGELOG.md | 1 + agent_pool.go | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29884dbd6..4dc8e2504 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/agent_pool.go b/agent_pool.go index d9f08052f..1606b3d31 100644 --- a/agent_pool.go +++ b/agent_pool.go @@ -73,6 +73,7 @@ type AgentPoolListOptions struct { // 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"` }