diff --git a/agent.go b/agent.go index f0760bba6..1299b9649 100644 --- a/agent.go +++ b/agent.go @@ -21,9 +21,6 @@ type Agents interface { // List all the agents of the given pool. List(ctx context.Context, agentPoolID string, options *AgentListOptions) (*AgentList, error) - - // Delete an agent by its ID. - Delete(ctx context.Context, agentPoolID string) error } // agents implements Agents. @@ -122,21 +119,6 @@ func (s *agents) List(ctx context.Context, agentPoolID string, options *AgentLis return agentList, nil } -// Delete an agent by its ID. -func (s *agents) Delete(ctx context.Context, agentID string) error { - if !validStringID(&agentID) { - return ErrInvalidAgentID - } - - u := fmt.Sprintf("agents/%s", url.QueryEscape(agentID)) - req, err := s.client.NewRequest("DELETE", u, nil) - if err != nil { - return err - } - - return req.Do(ctx, nil) -} - func (o *AgentReadOptions) valid() error { if o == nil { return nil // nothing to validate diff --git a/agent_integration_test.go b/agent_integration_test.go index cf712c779..bbdfedb7b 100644 --- a/agent_integration_test.go +++ b/agent_integration_test.go @@ -61,67 +61,4 @@ func TestAgentsList(t *testing.T) { assert.Nil(t, agents) assert.EqualError(t, err, ErrInvalidOrg.Error()) }) - - //Write tests that expect 0 - //Test expects - - // t.Run("exepct agents in list") - - // t.Run("without list options", func(t *testing.T) { - // agentList, err := client.Agents.List(ctx, agentPool.ID, nil) - // require.NoError(t, err) - // assert.Contains(t, agentList.Items, agent) - - // assert.Equal(t, 1, agentList.CurrentPage) - // assert.Equal(t, 1, agentList.TotalCount) - // }) - - // t.Run("with list options", func(t *testing.T) { - // // Request a page number which is out of range. The result should - // // be successful, but return no results if the paging options are - // // properly passed along. - // agents, err := client.Agents.List(ctx, agent.Organization.Name, &AgentListOptions{ - // ListOptions: ListOptions{ - // PageNumber: 999, - // PageSize: 100, - // }, - // }) - // require.NoError(t, err) - // assert.Empty(t, agents.Items) - // assert.Equal(t, 999, agents.CurrentPage) - // assert.Equal(t, 1, agents.TotalCount) - // }) - -} - -func TestAgentsDelete(t *testing.T) { - client := testClient(t) - ctx := context.Background() - - agent, _, agentCleanup := createAgent(t, client, nil, nil, nil) - defer agentCleanup() - t.Log("log agent: ", agent) - // t.Log("log pool: ", pool) - - // t.Run("with valid options", func(t *testing.T) { - // err := client.Agents.Delete(ctx, agent.ID) - // //agent status cannot be idle, to be deleted - // //need to account for various statuses - // require.NoError(t, err) - - // // Try loading the agent - it should fail. - // _, err = client.Agents.Read(ctx, agent.ID) - // assert.Equal(t, err, ErrResourceNotFound) - // }) - - // t.Run("when the agent does not exist", func(t *testing.T) { - // err := client.Agents.Delete(ctx, agent.ID) - // assert.Equal(t, err, ErrResourceNotFound) - // }) - - t.Run("when the agent ID is invalid", func(t *testing.T) { - err := client.Agents.Delete(ctx, badIdentifier) - assert.EqualError(t, err, ErrInvalidAgentID.Error()) - }) - } diff --git a/helper_test.go b/helper_test.go index 304d42576..8277c024c 100644 --- a/helper_test.go +++ b/helper_test.go @@ -94,7 +94,6 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age var agentPoolCleanup func() var agentPoolTokenCleanup func() var agent *Agent - // var pool *AgentPool if org == nil { org, orgCleanup = createOrganization(t, client) @@ -111,17 +110,12 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age agentPoolToken, agentPoolTokenCleanup = createAgentToken(t, client, agentPool) } - // s := "abcdefghijklmnopqrstuvwxyz0123456789" - // containerName := base64.StdEncoding.EncodeToString([]byte(s)) - // t.Log("containerName: ", containerName) - - // containerName := "container-name-test" ctx := context.Background() cmd := exec.Command("docker", "run", "-d", "--env", "TFC_AGENT_TOKEN="+agentPoolToken.Token, "--env", "TFC_AGENT_NAME="+"this-is-a-test-agent", - "--env", "TFC_ADDRESS="+"https://tfcdev-2c13224a.ngrok.io", + "--env", "TFC_ADDRESS="+DefaultConfig().Address, "docker.mirror.hashicorp.services/hashicorp/tfc-agent:latest") go func() { @@ -129,9 +123,8 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age if err != nil { t.Logf("Could not run container: %s", err) } - // t.Log("cmd", cmd) + t.Log("Logging container output: ", (string)(output)) - t.Log("log agent inside container output: ", agent) }() defer func() { @@ -162,18 +155,15 @@ func createAgent(t *testing.T, client *Client, org *Organization, agentPool *Age return agent, agentPool, func() { if agentPoolTokenCleanup != nil { - // agentPoolTokenCleanup() - t.Log("agentPoolTooken not nil inside helper fn") + agentPoolTokenCleanup() } if agentPoolCleanup != nil { - // agentPoolCleanup() - t.Log("agentPool not nil") + agentPoolCleanup() } if orgCleanup != nil { - // orgCleanup() - t.Log("org not nil") + orgCleanup() } } }