Skip to content

Commit

Permalink
update TFC_ADDRESS to the TFE_ADDRESS used in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenolivia committed Jul 27, 2022
1 parent d856854 commit 84413bc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 96 deletions.
18 changes: 0 additions & 18 deletions agent.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
63 changes: 0 additions & 63 deletions agent_integration_test.go
Expand Up @@ -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())
})

}
20 changes: 5 additions & 15 deletions helper_test.go
Expand Up @@ -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)
Expand All @@ -111,27 +110,21 @@ 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() {
output, err := cmd.CombinedOutput()
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() {
Expand Down Expand Up @@ -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()
}
}
}
Expand Down

0 comments on commit 84413bc

Please sign in to comment.