From 3d771ca33ff1d123b1ed727ca972aedefd3f25dd Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Thu, 21 Aug 2025 10:04:59 -0400 Subject: [PATCH 01/23] add sorting to agent list and agent pool list --- agent.go | 3 +++ agent_integration_test.go | 19 +++++++++++++++++++ agent_pool.go | 3 +++ agent_pool_integration_test.go | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+) 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_integration_test.go b/agent_integration_test.go index 3b4689e62..0ab38cc25 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -23,6 +23,7 @@ func TestAgentsRead(t *testing.T) { upgradeOrganizationSubscription(t, client, org) agent, _, agentCleanup := createAgent(t, client, org) + agent2, _, agentCleanup := createAgent(t, client, org) t.Cleanup(agentCleanup) @@ -67,6 +68,24 @@ func TestAgentsList(t *testing.T) { assert.NotEmpty(t, agent.Items[0].ID) }) + t.Run("with sorting", func(t *testing.T) { + agents, err := client.Agents.List(ctx, agentPool.ID, &AgentListOptions{ + Sort: "created-at", + }) + require.NoError(t, err) + require.NotNil(t, agents) + require.Len(t, agents.Items, 2) + require.Equal(t, []string{agent1.ID, agent2.ID}, []string{agents.Items[0].ID, agents.Items[1].ID}) + + agents, err = client.Agents.List(ctx, agentPool.ID, &AgentListOptions{ + Sort: "-created-at", + }) + require.NoError(t, err) + require.NotNil(t, agents) + require.Len(t, agents.Items, 2) + require.Equal(t, []string{agent2.ID, agent1.ID}, []string{agents.Items[0].ID, agents.Items[1].ID}) + }) + t.Run("without a valid agent pool ID", func(t *testing.T) { agent, err := client.Agents.List(ctx, badIdentifier, nil) assert.Nil(t, agent) diff --git a/agent_pool.go b/agent_pool.go index 47778820b..f33efcd0c 100644 --- a/agent_pool.go +++ b/agent_pool.go @@ -98,6 +98,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 2bad0c15e..4b978a502 100644 --- a/agent_pool_integration_test.go +++ b/agent_pool_integration_test.go @@ -20,6 +20,8 @@ func TestAgentPoolsList(t *testing.T) { agentPool, agentPoolCleanup := createAgentPool(t, client, orgTest) t.Cleanup(agentPoolCleanup) + agentPool2, agentPoolCleanup2 := createAgentPool(t, client, orgTest) + defer agentPoolCleanup2() t.Run("without list options", func(t *testing.T) { pools, err := client.AgentPools.List(ctx, orgTest.Name, nil) @@ -62,6 +64,23 @@ func TestAgentPoolsList(t *testing.T) { assert.Equal(t, 999, pools.CurrentPage) assert.Equal(t, 1, pools.TotalCount) }) + t.Run("with sorting", func(t *testing.T) { + 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) From 9680a10804c399c257bc3b6950f554dd90cf9880 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Thu, 21 Aug 2025 10:13:35 -0400 Subject: [PATCH 02/23] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8b745dc4..db0946c53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Unreleased +## Enhancements +* Add `Sort` option to `Agents` and `AgentPools`, by @twitnithegirl [#1193](https://github.com/hashicorp/go-tfe/pull/1193) + # v1.91.0 ## Enhancements @@ -14,6 +17,7 @@ * Adds `IconUrl`, `InstallationType`, and `InstallationURL` to githubAppInstallation, by @jpadrianoGo [#1191](https://github.com/hashicorp/go-tfe/pull/1191) * Adds support for `Workspace` VCSRepoOptions source_directory and tag_prefix, by @jillrami [#1194] (https://github.com/hashicorp/go-tfe/pull/1194) + # v1.90.0 ## Bug Fixes From 4831aa5b168562fdbf843e97a38563d949018339 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Thu, 21 Aug 2025 10:16:00 -0400 Subject: [PATCH 03/23] update integration test --- agent_integration_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/agent_integration_test.go b/agent_integration_test.go index 0ab38cc25..84d86d082 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -23,7 +23,6 @@ func TestAgentsRead(t *testing.T) { upgradeOrganizationSubscription(t, client, org) agent, _, agentCleanup := createAgent(t, client, org) - agent2, _, agentCleanup := createAgent(t, client, org) t.Cleanup(agentCleanup) @@ -57,8 +56,10 @@ func TestAgentsList(t *testing.T) { upgradeOrganizationSubscription(t, client, org) - _, agentPool, agentCleanup := createAgent(t, client, org) + agent1, agentPool, agentCleanup := createAgent(t, client, org) t.Cleanup(agentCleanup) + agent2, agentPool, agentCleanup2 := createAgent(t, client, org) + t.Cleanup(agentCleanup2) t.Run("expect an agent to exist", func(t *testing.T) { agent, err := client.Agents.List(ctx, agentPool.ID, nil) From f850519a15bd0b019912ffe6346d0f426e4bf270 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Thu, 21 Aug 2025 10:18:10 -0400 Subject: [PATCH 04/23] appease linting gods --- agent_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent_integration_test.go b/agent_integration_test.go index 84d86d082..284601420 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -58,7 +58,7 @@ func TestAgentsList(t *testing.T) { agent1, agentPool, agentCleanup := createAgent(t, client, org) t.Cleanup(agentCleanup) - agent2, agentPool, agentCleanup2 := createAgent(t, client, org) + agent2, _, agentCleanup2 := createAgent(t, client, org) t.Cleanup(agentCleanup2) t.Run("expect an agent to exist", func(t *testing.T) { From 7a3534e2048cc7995eadf0835e150172937ddff1 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Mon, 25 Aug 2025 13:57:53 -0400 Subject: [PATCH 05/23] correct agent pool integration test --- agent_pool_integration_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/agent_pool_integration_test.go b/agent_pool_integration_test.go index 4b978a502..787e9e047 100644 --- a/agent_pool_integration_test.go +++ b/agent_pool_integration_test.go @@ -20,8 +20,6 @@ func TestAgentPoolsList(t *testing.T) { agentPool, agentPoolCleanup := createAgentPool(t, client, orgTest) t.Cleanup(agentPoolCleanup) - agentPool2, agentPoolCleanup2 := createAgentPool(t, client, orgTest) - defer agentPoolCleanup2() t.Run("without list options", func(t *testing.T) { pools, err := client.AgentPools.List(ctx, orgTest.Name, nil) @@ -65,6 +63,9 @@ 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", }) From c1f1eab2ec906954b50ed3f938358da5c23981b8 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Tue, 26 Aug 2025 12:56:56 -0400 Subject: [PATCH 06/23] correct agent integration test --- CHANGELOG.md | 1 - agent_integration_test.go | 7 +++---- helper_test.go | 7 +++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db0946c53..2360fe458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,6 @@ * Adds `IconUrl`, `InstallationType`, and `InstallationURL` to githubAppInstallation, by @jpadrianoGo [#1191](https://github.com/hashicorp/go-tfe/pull/1191) * Adds support for `Workspace` VCSRepoOptions source_directory and tag_prefix, by @jillrami [#1194] (https://github.com/hashicorp/go-tfe/pull/1194) - # v1.90.0 ## Bug Fixes diff --git a/agent_integration_test.go b/agent_integration_test.go index 284601420..b99427e52 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -22,8 +22,7 @@ func TestAgentsRead(t *testing.T) { upgradeOrganizationSubscription(t, client, org) - agent, _, agentCleanup := createAgent(t, client, org) - + agent, _, agentCleanup := createAgent(t, client, org, nil) t.Cleanup(agentCleanup) t.Run("when the agent exists", func(t *testing.T) { @@ -56,9 +55,9 @@ func TestAgentsList(t *testing.T) { upgradeOrganizationSubscription(t, client, org) - agent1, agentPool, agentCleanup := createAgent(t, client, org) + agent1, agentPool, agentCleanup := createAgent(t, client, org, nil) t.Cleanup(agentCleanup) - agent2, _, agentCleanup2 := createAgent(t, client, org) + agent2, _, agentCleanup2 := createAgent(t, client, org, agentPool) t.Cleanup(agentCleanup2) t.Run("expect an agent to exist", func(t *testing.T) { diff --git a/helper_test.go b/helper_test.go index 2ec5cfd6d..862e98da4 100644 --- a/helper_test.go +++ b/helper_test.go @@ -261,9 +261,10 @@ func downloadTFCAgent(t *testing.T) (string, error) { return fmt.Sprintf("%s/tfc-agent", tmpDir), nil } -func createAgent(t *testing.T, client *Client, org *Organization) (*Agent, *AgentPool, func()) { +func createAgent(t *testing.T, client *Client, org *Organization, agentPool *AgentPool) (*Agent, *AgentPool, func()) { var orgCleanup func() var agentPoolTokenCleanup func() + var agentPoolCleanup func() var agent *Agent var ok bool @@ -271,7 +272,9 @@ func createAgent(t *testing.T, client *Client, org *Organization) (*Agent, *Agen org, orgCleanup = createOrganization(t, client) } - agentPool, agentPoolCleanup := createAgentPool(t, client, org) + if agentPool == nil { + agentPool, agentPoolCleanup := createAgentPool(t, client, org) + } upgradeOrganizationSubscription(t, client, org) From 83883d9c7af56d7d0ebd1480737ae57c9d811f2f Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Tue, 26 Aug 2025 14:03:13 -0400 Subject: [PATCH 07/23] correct linting in helper_test.go --- helper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper_test.go b/helper_test.go index 862e98da4..29874a456 100644 --- a/helper_test.go +++ b/helper_test.go @@ -273,7 +273,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age } if agentPool == nil { - agentPool, agentPoolCleanup := createAgentPool(t, client, org) + agentPool, agentPoolCleanup = createAgentPool(t, client, org) } upgradeOrganizationSubscription(t, client, org) From 853d272791656dafff0273295ace231c6fb9205c Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Tue, 26 Aug 2025 14:29:46 -0400 Subject: [PATCH 08/23] debugging output --- agent_integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/agent_integration_test.go b/agent_integration_test.go index b99427e52..902d0996e 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -75,6 +75,7 @@ func TestAgentsList(t *testing.T) { require.NoError(t, err) require.NotNil(t, agents) require.Len(t, agents.Items, 2) + t.Log(agents) require.Equal(t, []string{agent1.ID, agent2.ID}, []string{agents.Items[0].ID, agents.Items[1].ID}) agents, err = client.Agents.List(ctx, agentPool.ID, &AgentListOptions{ From 9b4922b2671a7e06ba5792d68c8df428e8249609 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Tue, 26 Aug 2025 15:17:08 -0400 Subject: [PATCH 09/23] debuggering --- agent_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent_integration_test.go b/agent_integration_test.go index 902d0996e..a5424ce5a 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -75,7 +75,7 @@ func TestAgentsList(t *testing.T) { require.NoError(t, err) require.NotNil(t, agents) require.Len(t, agents.Items, 2) - t.Log(agents) + t.Log(agents.Items) require.Equal(t, []string{agent1.ID, agent2.ID}, []string{agents.Items[0].ID, agents.Items[1].ID}) agents, err = client.Agents.List(ctx, agentPool.ID, &AgentListOptions{ From 1d453b65baad867c5d1f969456965e65fda018df Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 27 Aug 2025 15:41:09 -0400 Subject: [PATCH 10/23] return correct agent in test helper --- agent_integration_test.go | 5 ++--- helper_test.go | 13 ++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/agent_integration_test.go b/agent_integration_test.go index a5424ce5a..21a2461a4 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -55,9 +55,9 @@ func TestAgentsList(t *testing.T) { upgradeOrganizationSubscription(t, client, org) - agent1, agentPool, agentCleanup := createAgent(t, client, org, nil) + agent1, agentPool, agentCleanup := createAgent(t, client, org, nil, String("agent1")) t.Cleanup(agentCleanup) - agent2, _, agentCleanup2 := createAgent(t, client, org, agentPool) + agent2, _, agentCleanup2 := createAgent(t, client, org, agentPool, String("agent2")) t.Cleanup(agentCleanup2) t.Run("expect an agent to exist", func(t *testing.T) { @@ -75,7 +75,6 @@ func TestAgentsList(t *testing.T) { require.NoError(t, err) require.NotNil(t, agents) require.Len(t, agents.Items, 2) - t.Log(agents.Items) require.Equal(t, []string{agent1.ID, agent2.ID}, []string{agents.Items[0].ID, agents.Items[1].ID}) agents, err = client.Agents.List(ctx, agentPool.ID, &AgentListOptions{ diff --git a/helper_test.go b/helper_test.go index 29874a456..f557253c2 100644 --- a/helper_test.go +++ b/helper_test.go @@ -261,7 +261,7 @@ func downloadTFCAgent(t *testing.T) (string, error) { return fmt.Sprintf("%s/tfc-agent", tmpDir), nil } -func createAgent(t *testing.T, client *Client, org *Organization, agentPool *AgentPool) (*Agent, *AgentPool, func()) { +func createAgent(t *testing.T, client *Client, org *Organization, agentPool *AgentPool, name *string) (*Agent, *AgentPool, func()) { var orgCleanup func() var agentPoolTokenCleanup func() var agentPoolCleanup func() @@ -299,11 +299,14 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age ctx := context.Background() + if name == nil { + *name = "test-agent" + } cmd := exec.Command(agentPath) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "TFC_AGENT_TOKEN="+agentPoolToken.Token, - "TFC_AGENT_NAME="+"test-agent", + "TFC_AGENT_NAME="+*name, "TFC_ADDRESS="+DefaultConfig().Address, ) @@ -327,7 +330,11 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age } if agentList != nil && len(agentList.Items) > 0 { - return agentList.Items[0], nil + for _, value := range agentList.Items { + if value.Name == *name { + return value, nil + } + } } return nil, errors.New("no agent found") }) From 13f91213be66bbda2d521b448e36f5741bdbc0f9 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 27 Aug 2025 16:43:35 -0400 Subject: [PATCH 11/23] correct number of calls --- agent_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent_integration_test.go b/agent_integration_test.go index 21a2461a4..f1012c003 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -22,7 +22,7 @@ func TestAgentsRead(t *testing.T) { upgradeOrganizationSubscription(t, client, org) - agent, _, agentCleanup := createAgent(t, client, org, nil) + agent, _, agentCleanup := createAgent(t, client, org, nil, nil) t.Cleanup(agentCleanup) t.Run("when the agent exists", func(t *testing.T) { From 25872a62074175e0f0229f011fbfc7020e08fa6d Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Tue, 2 Sep 2025 11:34:05 -0400 Subject: [PATCH 12/23] attempt string pointer success --- helper_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/helper_test.go b/helper_test.go index f557253c2..c57f0470e 100644 --- a/helper_test.go +++ b/helper_test.go @@ -276,6 +276,11 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age agentPool, agentPoolCleanup = createAgentPool(t, client, org) } + if name == nil { + defaultName := "test-agent" + name = &defaultName + } + upgradeOrganizationSubscription(t, client, org) agentPoolToken, agentPoolTokenCleanup := createAgentToken(t, client, agentPool) @@ -299,9 +304,6 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age ctx := context.Background() - if name == nil { - *name = "test-agent" - } cmd := exec.Command(agentPath) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, From f15d957e25d7355f34f87792f8f9abb6d57f674c Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Tue, 2 Sep 2025 12:16:37 -0400 Subject: [PATCH 13/23] sanity check --- helper_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/helper_test.go b/helper_test.go index c57f0470e..b5dc081d3 100644 --- a/helper_test.go +++ b/helper_test.go @@ -334,6 +334,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if agentList != nil && len(agentList.Items) > 0 { for _, value := range agentList.Items { if value.Name == *name { + fmt.Println("sanity") return value, nil } } From cc2f610fd46eae5ec1492674ea592c055f69c16d Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 09:09:09 -0400 Subject: [PATCH 14/23] sanity check --- helper_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/helper_test.go b/helper_test.go index b5dc081d3..1d7571678 100644 --- a/helper_test.go +++ b/helper_test.go @@ -280,6 +280,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age defaultName := "test-agent" name = &defaultName } + fmt.Println(name) upgradeOrganizationSubscription(t, client, org) From 6ea0fe9b01a722127d6629a35373d46b1c48760d Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 10:57:54 -0400 Subject: [PATCH 15/23] sanity check --- helper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper_test.go b/helper_test.go index 1d7571678..c83345429 100644 --- a/helper_test.go +++ b/helper_test.go @@ -280,7 +280,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age defaultName := "test-agent" name = &defaultName } - fmt.Println(name) + fmt.Println(*name) upgradeOrganizationSubscription(t, client, org) From 1aff19eb8634d21cd25609c761f9be85cea88960 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 11:40:04 -0400 Subject: [PATCH 16/23] please work --- helper_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helper_test.go b/helper_test.go index c83345429..6a629225e 100644 --- a/helper_test.go +++ b/helper_test.go @@ -280,7 +280,6 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age defaultName := "test-agent" name = &defaultName } - fmt.Println(*name) upgradeOrganizationSubscription(t, client, org) @@ -333,12 +332,13 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age } if agentList != nil && len(agentList.Items) > 0 { + var result *Agent = nil for _, value := range agentList.Items { if value.Name == *name { - fmt.Println("sanity") - return value, nil + result = value } } + return result, nil } return nil, errors.New("no agent found") }) From 148b96f94ca6af0df22e904e79e0677713cb3ccd Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 11:57:59 -0400 Subject: [PATCH 17/23] maybe this --- helper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper_test.go b/helper_test.go index 6a629225e..bc4b8b5de 100644 --- a/helper_test.go +++ b/helper_test.go @@ -332,7 +332,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age } if agentList != nil && len(agentList.Items) > 0 { - var result *Agent = nil + var result *Agent for _, value := range agentList.Items { if value.Name == *name { result = value From 2e315c5e6d9a6648a6a127f9c7ddf2e9372dc663 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 16:20:12 -0400 Subject: [PATCH 18/23] plz give answers --- agent_integration_test.go | 15 ++++++++++++--- helper_test.go | 11 +++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/agent_integration_test.go b/agent_integration_test.go index f1012c003..213bb4a77 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -5,6 +5,7 @@ package tfe import ( "context" + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -22,7 +23,7 @@ func TestAgentsRead(t *testing.T) { upgradeOrganizationSubscription(t, client, org) - agent, _, agentCleanup := createAgent(t, client, org, nil, nil) + agent, _, agentCleanup := createAgent(t, client, org, nil, "") t.Cleanup(agentCleanup) t.Run("when the agent exists", func(t *testing.T) { @@ -55,9 +56,9 @@ func TestAgentsList(t *testing.T) { upgradeOrganizationSubscription(t, client, org) - agent1, agentPool, agentCleanup := createAgent(t, client, org, nil, String("agent1")) + agent1, agentPool, agentCleanup := createAgent(t, client, org, nil, "agent1") t.Cleanup(agentCleanup) - agent2, _, agentCleanup2 := createAgent(t, client, org, agentPool, String("agent2")) + agent2, _, agentCleanup2 := createAgent(t, client, org, agentPool, "agent2") t.Cleanup(agentCleanup2) t.Run("expect an agent to exist", func(t *testing.T) { @@ -75,6 +76,14 @@ func TestAgentsList(t *testing.T) { require.NoError(t, err) require.NotNil(t, agents) require.Len(t, agents.Items, 2) + fmt.Println(agent1) + fmt.Println(agent1.Name) + fmt.Println(agent2) + fmt.Println(agent2.Name) + fmt.Println(agents) + fmt.Println(agents.Items[0].Name) + fmt.Println(agents.Items[1].Name) + require.Equal(t, []string{agent1.ID, agent2.ID}, []string{agents.Items[0].ID, agents.Items[1].ID}) agents, err = client.Agents.List(ctx, agentPool.ID, &AgentListOptions{ diff --git a/helper_test.go b/helper_test.go index bc4b8b5de..130310303 100644 --- a/helper_test.go +++ b/helper_test.go @@ -261,7 +261,7 @@ func downloadTFCAgent(t *testing.T) (string, error) { return fmt.Sprintf("%s/tfc-agent", tmpDir), nil } -func createAgent(t *testing.T, client *Client, org *Organization, agentPool *AgentPool, name *string) (*Agent, *AgentPool, func()) { +func createAgent(t *testing.T, client *Client, org *Organization, agentPool *AgentPool, name string) (*Agent, *AgentPool, func()) { var orgCleanup func() var agentPoolTokenCleanup func() var agentPoolCleanup func() @@ -276,9 +276,8 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age agentPool, agentPoolCleanup = createAgentPool(t, client, org) } - if name == nil { - defaultName := "test-agent" - name = &defaultName + if name == "" { + name = "test-agent" } upgradeOrganizationSubscription(t, client, org) @@ -308,7 +307,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "TFC_AGENT_TOKEN="+agentPoolToken.Token, - "TFC_AGENT_NAME="+*name, + "TFC_AGENT_NAME="+name, "TFC_ADDRESS="+DefaultConfig().Address, ) @@ -334,7 +333,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if agentList != nil && len(agentList.Items) > 0 { var result *Agent for _, value := range agentList.Items { - if value.Name == *name { + if value.Name == name { result = value } } From 98314bd86db86135b142820a28f52edd7a09034e Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 16:28:29 -0400 Subject: [PATCH 19/23] puts debuggerer --- agent_integration_test.go | 10 +++++++--- helper_test.go | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/agent_integration_test.go b/agent_integration_test.go index 213bb4a77..e9de0fda6 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -58,7 +58,10 @@ func TestAgentsList(t *testing.T) { agent1, agentPool, agentCleanup := createAgent(t, client, org, nil, "agent1") t.Cleanup(agentCleanup) - agent2, _, agentCleanup2 := createAgent(t, client, org, agentPool, "agent2") + agent2, agentPool2, agentCleanup2 := createAgent(t, client, org, agentPool, "agent2") + fmt.Println("agent pool stuff") + fmt.Println(agentPool2.ID) + fmt.Println(agentPool.ID) t.Cleanup(agentCleanup2) t.Run("expect an agent to exist", func(t *testing.T) { @@ -73,6 +76,9 @@ func TestAgentsList(t *testing.T) { agents, err := client.Agents.List(ctx, agentPool.ID, &AgentListOptions{ Sort: "created-at", }) + fmt.Println("line 78") + fmt.Println(agents.Items[0].Name) + fmt.Println(agents.Items[1].Name) require.NoError(t, err) require.NotNil(t, agents) require.Len(t, agents.Items, 2) @@ -81,8 +87,6 @@ func TestAgentsList(t *testing.T) { fmt.Println(agent2) fmt.Println(agent2.Name) fmt.Println(agents) - fmt.Println(agents.Items[0].Name) - fmt.Println(agents.Items[1].Name) require.Equal(t, []string{agent1.ID, agent2.ID}, []string{agents.Items[0].ID, agents.Items[1].ID}) diff --git a/helper_test.go b/helper_test.go index 130310303..12807bd21 100644 --- a/helper_test.go +++ b/helper_test.go @@ -333,6 +333,9 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if agentList != nil && len(agentList.Items) > 0 { var result *Agent for _, value := range agentList.Items { + fmt.Println("the names") + fmt.Println(name) + fmt.Println(value.Name) if value.Name == name { result = value } From 5c6d2493334d159cffef2cd2ada2b9dc55b20243 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 16:36:50 -0400 Subject: [PATCH 20/23] help --- agent_integration_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agent_integration_test.go b/agent_integration_test.go index e9de0fda6..48514316e 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -78,7 +78,9 @@ func TestAgentsList(t *testing.T) { }) fmt.Println("line 78") fmt.Println(agents.Items[0].Name) + fmt.Println(agents.Items[0].ID) fmt.Println(agents.Items[1].Name) + fmt.Println(agents.Items[1].ID) require.NoError(t, err) require.NotNil(t, agents) require.Len(t, agents.Items, 2) From f8edf89ee62bffad37f2ba1c0416dee7e870405d Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 16:40:45 -0400 Subject: [PATCH 21/23] omg --- helper_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helper_test.go b/helper_test.go index 12807bd21..333adfa38 100644 --- a/helper_test.go +++ b/helper_test.go @@ -279,6 +279,8 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if name == "" { name = "test-agent" } + fmt.Println("the names") + fmt.Println(name) upgradeOrganizationSubscription(t, client, org) @@ -333,8 +335,6 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if agentList != nil && len(agentList.Items) > 0 { var result *Agent for _, value := range agentList.Items { - fmt.Println("the names") - fmt.Println(name) fmt.Println(value.Name) if value.Name == name { result = value From 487231dbfaab6f4a3b751549e21f2fd22e0f28b4 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Wed, 3 Sep 2025 16:51:30 -0400 Subject: [PATCH 22/23] yay --- helper_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/helper_test.go b/helper_test.go index 333adfa38..dcf5cadba 100644 --- a/helper_test.go +++ b/helper_test.go @@ -279,7 +279,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if name == "" { name = "test-agent" } - fmt.Println("the names") + fmt.Println("the name passed into createAgent") fmt.Println(name) upgradeOrganizationSubscription(t, client, org) @@ -298,6 +298,21 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age } } + xctx := context.Background() + + agentList, err := client.Agents.List(xctx, agentPool.ID, nil) + if err != nil { + fmt.Println("OMG!") + } + + if agentList != nil && len(agentList.Items) > 0 { + for _, value := range agentList.Items { + fmt.Println("the before times") + fmt.Println(value.Name) + fmt.Println(value.ID) + } + } + agentPath, err := downloadTFCAgent(t) if err != nil { return agent, agentPool, cleanup @@ -335,7 +350,9 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if agentList != nil && len(agentList.Items) > 0 { var result *Agent for _, value := range agentList.Items { + fmt.Println("value.Name for agent in list") fmt.Println(value.Name) + fmt.Println(value.ID) if value.Name == name { result = value } From 2d91901b3839f1e4c847af3a6b0db3f5f6d7e871 Mon Sep 17 00:00:00 2001 From: Britni Alexander Date: Mon, 22 Sep 2025 14:30:54 -0400 Subject: [PATCH 23/23] more info --- helper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper_test.go b/helper_test.go index dcf5cadba..0c247fc5a 100644 --- a/helper_test.go +++ b/helper_test.go @@ -370,7 +370,7 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if !ok { t.Fatalf("Expected type to be *Agent but got %T", agent) } - + require.NotNil(t, agent) return agent, agentPool, cleanup }