/
agent_integration_test.go
114 lines (92 loc) · 3.07 KB
/
agent_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//go:build integration
// +build integration
package tfe
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAgentsRead(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("when the agent exists", func(t *testing.T) {
k, err := client.Agents.Read(ctx, agent.ID)
require.NoError(t, err)
assert.Equal(t, agent, k)
})
t.Run("when the agent does not exist", func(t *testing.T) {
k, err := client.Agents.Read(ctx, "nonexisting")
assert.Nil(t, k)
assert.Equal(t, err, ErrResourceNotFound)
})
t.Run("without a valid agent ID", func(t *testing.T) {
k, err := client.Agents.Read(ctx, badIdentifier)
assert.Nil(t, k)
assert.EqualError(t, err, ErrInvalidAgentID.Error())
})
}
func TestAgentsList(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("without list options", func(t *testing.T) {
agentList, err := client.Agents.List(ctx, agent.Organization.Name, 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)
})
t.Run("without a valid organization", func(t *testing.T) {
agents, err := client.Agents.List(ctx, badIdentifier, nil)
assert.Nil(t, agents)
assert.EqualError(t, err, ErrInvalidOrg.Error())
})
}
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())
})
}