Skip to content

Commit 4fe76f0

Browse files
authored
Merged automatically by CI pipeline
Revert "Revert "Provider > Add link API between on-prem VCS and Agent-Pool ""
2 parents 39bde2c + 5437ed6 commit 4fe76f0

File tree

9 files changed

+101
-27
lines changed

9 files changed

+101
-27
lines changed

access_token_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestAccessTokenRead(t *testing.T) {
1313
client := testClient(t)
1414
ctx := context.Background()
1515

16-
ap, apCleanup := createAgentPool(t, client)
16+
ap, apCleanup := createAgentPool(t, client, false)
1717
defer apCleanup()
1818

1919
atTest, atTestCleanup := createAgentPoolToken(t, client, ap.ID)
@@ -40,7 +40,7 @@ func TestAccessTokenUpdate(t *testing.T) {
4040
client := testClient(t)
4141
ctx := context.Background()
4242

43-
ap, apCleanup := createAgentPool(t, client)
43+
ap, apCleanup := createAgentPool(t, client, false)
4444
defer apCleanup()
4545

4646
apt, aptCleanup := createAgentPoolToken(t, client, ap.ID)
@@ -75,7 +75,7 @@ func TestAccessTokenDelete(t *testing.T) {
7575
client := testClient(t)
7676
ctx := context.Background()
7777

78-
ap, apCleanup := createAgentPool(t, client)
78+
ap, apCleanup := createAgentPool(t, client, false)
7979
defer apCleanup()
8080

8181
apt, _ := createAgentPoolToken(t, client, ap.ID)

agent_pool.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ type AgentPoolList struct {
3434

3535
// AgentPool represents a Scalr agent pool.
3636
type AgentPool struct {
37-
ID string `jsonapi:"primary,agent-pools"`
38-
Name string `jsonapi:"attr,name"`
39-
37+
ID string `jsonapi:"primary,agent-pools"`
38+
Name string `jsonapi:"attr,name"`
39+
VcsEnabled bool `jsonapi:"attr,vcs-enabled"`
4040
// Relations
4141

4242
// The agent pool's scope
@@ -51,8 +51,9 @@ type AgentPool struct {
5151

5252
// AgentPoolCreateOptions represents the options for creating a new AgentPool.
5353
type AgentPoolCreateOptions struct {
54-
ID string `jsonapi:"primary,agent-pools"`
55-
Name *string `jsonapi:"attr,name"`
54+
ID string `jsonapi:"primary,agent-pools"`
55+
Name *string `jsonapi:"attr,name"`
56+
VcsEnabled *bool `jsonapi:"attr,vcs-enabled,omitempty"`
5657

5758
// The agent pool's scope
5859
Account *Account `jsonapi:"relation,account"`
@@ -96,6 +97,7 @@ type AgentPoolListOptions struct {
9697
Environment *string `url:"filter[environment],omitempty"`
9798
Name string `url:"filter[name],omitempty"`
9899
AgentPool string `url:"filter[agent-pool],omitempty"`
100+
VcsEnabled *bool `url:"filter[vcs-enabled],omitempty"`
99101
Include string `url:"include,omitempty"`
100102
}
101103

agent_pool_test.go

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ func TestAgentPoolsList(t *testing.T) {
1313
client := testClient(t)
1414
ctx := context.Background()
1515

16-
agentPoolTest1, agentPoolTest1Cleanup := createAgentPool(t, client)
16+
agentPoolTest1, agentPoolTest1Cleanup := createAgentPool(t, client, false)
1717
defer agentPoolTest1Cleanup()
18-
agentPoolTest2, agentPoolTest2Cleanup := createAgentPool(t, client)
18+
agentPoolTest2, agentPoolTest2Cleanup := createAgentPool(t, client, true)
1919
defer agentPoolTest2Cleanup()
20+
agentPoolTest3, agentPoolTest3Cleanup := createAgentPool(t, client, true)
21+
defer agentPoolTest3Cleanup()
2022

2123
t.Run("without options", func(t *testing.T) {
2224
apList, err := client.AgentPools.List(ctx, AgentPoolListOptions{})
@@ -27,6 +29,7 @@ func TestAgentPoolsList(t *testing.T) {
2729
}
2830
assert.Contains(t, apListIDs, agentPoolTest1.ID)
2931
assert.Contains(t, apListIDs, agentPoolTest2.ID)
32+
assert.Contains(t, apListIDs, agentPoolTest3.ID)
3033
})
3134
t.Run("with account filter", func(t *testing.T) {
3235
apList, err := client.AgentPools.List(ctx, AgentPoolListOptions{Account: String(defaultAccountID)})
@@ -37,6 +40,7 @@ func TestAgentPoolsList(t *testing.T) {
3740
}
3841
assert.Contains(t, apListIDs, agentPoolTest1.ID)
3942
assert.Contains(t, apListIDs, agentPoolTest2.ID)
43+
assert.Contains(t, apListIDs, agentPoolTest3.ID)
4044
})
4145
t.Run("with account and name filter", func(t *testing.T) {
4246
apList, err := client.AgentPools.List(ctx, AgentPoolListOptions{Account: String(defaultAccountID), Name: agentPoolTest1.Name})
@@ -50,6 +54,18 @@ func TestAgentPoolsList(t *testing.T) {
5054
assert.Len(t, apList.Items, 1)
5155
assert.Equal(t, apList.Items[0].ID, agentPoolTest2.ID)
5256
})
57+
t.Run("with vcs-enabled filter", func(t *testing.T) {
58+
var vcsEnabledFiler = true
59+
apList, err := client.AgentPools.List(ctx, AgentPoolListOptions{VcsEnabled: &vcsEnabledFiler})
60+
require.NoError(t, err)
61+
apListIDs := make([]string, 0)
62+
for _, agentPool := range apList.Items {
63+
apListIDs = append(apListIDs, agentPool.ID)
64+
}
65+
assert.Len(t, apListIDs, 2)
66+
assert.Contains(t, apListIDs, agentPoolTest2.ID)
67+
assert.Contains(t, apListIDs, agentPoolTest3.ID)
68+
})
5369
}
5470

5571
func TestAgentPoolsCreate(t *testing.T) {
@@ -58,8 +74,9 @@ func TestAgentPoolsCreate(t *testing.T) {
5874

5975
t.Run("when account and name are provided", func(t *testing.T) {
6076
options := AgentPoolCreateOptions{
61-
Account: &Account{ID: defaultAccountID},
62-
Name: String("test-provider-pool-" + randomString(t)),
77+
Account: &Account{ID: defaultAccountID},
78+
Name: String("test-provider-pool-" + randomString(t)),
79+
VcsEnabled: Bool(true),
6380
}
6481

6582
agentPool, err := client.AgentPools.Create(ctx, options)
@@ -76,6 +93,31 @@ func TestAgentPoolsCreate(t *testing.T) {
7693
assert.NotEmpty(t, item.ID)
7794
assert.Equal(t, *options.Name, item.Name)
7895
assert.Equal(t, options.Account, item.Account)
96+
assert.Equal(t, *options.VcsEnabled, item.VcsEnabled)
97+
}
98+
err = client.AgentPools.Delete(ctx, agentPool.ID)
99+
require.NoError(t, err)
100+
})
101+
102+
t.Run("when create without vcs_enabled", func(t *testing.T) {
103+
options := AgentPoolCreateOptions{
104+
Account: &Account{ID: defaultAccountID},
105+
Name: String("test-provider-pool-" + randomString(t)),
106+
}
107+
108+
agentPool, err := client.AgentPools.Create(ctx, options)
109+
require.NoError(t, err)
110+
111+
// Get a refreshed view from the API.
112+
refreshed, err := client.AgentPools.Read(ctx, agentPool.ID)
113+
require.NoError(t, err)
114+
115+
for _, item := range []*AgentPool{
116+
agentPool,
117+
refreshed,
118+
} {
119+
assert.NotEmpty(t, item.ID)
120+
assert.Equal(t, item.VcsEnabled, false)
79121
}
80122
err = client.AgentPools.Delete(ctx, agentPool.ID)
81123
require.NoError(t, err)
@@ -90,6 +132,7 @@ func TestAgentPoolsCreate(t *testing.T) {
90132
Account: &Account{ID: defaultAccountID},
91133
Environment: &Environment{ID: env.ID},
92134
Name: String("test-provider-pool-" + randomString(t)),
135+
VcsEnabled: Bool(false),
93136
}
94137

95138
agentPool, err := client.AgentPools.Create(ctx, options)
@@ -123,6 +166,7 @@ func TestAgentPoolsCreate(t *testing.T) {
123166
Environment: &Environment{ID: env.ID},
124167
Workspaces: []*Workspace{{ID: ws.ID}},
125168
Name: String("test-provider-pool-" + randomString(t)),
169+
VcsEnabled: Bool(false),
126170
}
127171

128172
agentPool, err := client.AgentPools.Create(ctx, options)
@@ -241,7 +285,7 @@ func TestAgentPoolsRead(t *testing.T) {
241285
client := testClient(t)
242286
ctx := context.Background()
243287

244-
agentPoolTest, agentPoolTestCleanup := createAgentPool(t, client)
288+
agentPoolTest, agentPoolTestCleanup := createAgentPool(t, client, false)
245289
defer agentPoolTestCleanup()
246290

247291
t.Run("when the agentPool exists", func(t *testing.T) {
@@ -278,7 +322,7 @@ func TestAgentPoolsUpdate(t *testing.T) {
278322
client := testClient(t)
279323
ctx := context.Background()
280324

281-
agentPoolTest, agentPoolTestCleanup := createAgentPool(t, client)
325+
agentPoolTest, agentPoolTestCleanup := createAgentPool(t, client, false)
282326
defer agentPoolTestCleanup()
283327

284328
t.Run("when updating a name", func(t *testing.T) {
@@ -337,7 +381,7 @@ func TestAgentPoolsDelete(t *testing.T) {
337381
client := testClient(t)
338382
ctx := context.Background()
339383

340-
pool, _ := createAgentPool(t, client)
384+
pool, _ := createAgentPool(t, client, false)
341385

342386
t.Run("with valid agent pool id", func(t *testing.T) {
343387
err := client.AgentPools.Delete(ctx, pool.ID)

agent_pool_token_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestAgentPoolTokenList(t *testing.T) {
1313
client := testClient(t)
1414
ctx := context.Background()
1515

16-
ap, apCleanup := createAgentPool(t, client)
16+
ap, apCleanup := createAgentPool(t, client, false)
1717
defer apCleanup()
1818

1919
apt, aptCleanup := createAgentPoolToken(t, client, ap.ID)
@@ -41,7 +41,7 @@ func TestAgentPoolTokenCreate(t *testing.T) {
4141
client := testClient(t)
4242
ctx := context.Background()
4343

44-
ap, apCleanup := createAgentPool(t, client)
44+
ap, apCleanup := createAgentPool(t, client, false)
4545
defer apCleanup()
4646

4747
t.Run("when description is provided", func(t *testing.T) {

helper_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ func createEnvironment(t *testing.T, client *Client) (*Environment, func()) {
4444
}
4545
}
4646

47-
func createAgentPool(t *testing.T, client *Client) (*AgentPool, func()) {
47+
func createAgentPool(t *testing.T, client *Client, vcsEnabled bool) (*AgentPool, func()) {
4848
ctx := context.Background()
4949
ap, err := client.AgentPools.Create(ctx, AgentPoolCreateOptions{
50-
Name: String("provider-tst-pool-" + randomString(t)),
51-
Account: &Account{ID: defaultAccountID},
50+
Name: String("provider-tst-pool-" + randomString(t)),
51+
Account: &Account{ID: defaultAccountID},
52+
VcsEnabled: Bool(vcsEnabled),
5253
})
5354
if err != nil {
5455
t.Fatal(err)

run_triggers_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@ func TestRunTriggersRead(t *testing.T) {
8888
Downstream: &Downstream{ID: wsTest1.ID},
8989
Upstream: &Upstream{ID: wsTest2.ID},
9090
}
91-
created_trigger, err := client.RunTriggers.Create(ctx, options)
91+
createdTrigger, err := client.RunTriggers.Create(ctx, options)
9292
require.NoError(t, err)
93-
assert.NotEmpty(t, created_trigger.ID)
93+
assert.NotEmpty(t, createdTrigger.ID)
9494

9595
t.Run("get run trigger by id", func(t *testing.T) {
96-
trigger, err := client.RunTriggers.Read(ctx, created_trigger.ID)
96+
trigger, err := client.RunTriggers.Read(ctx, createdTrigger.ID)
9797
require.NoError(t, err)
98-
assert.Equal(t, created_trigger, trigger)
98+
assert.Equal(t, createdTrigger.ID, trigger.ID)
99+
assert.Equal(t, createdTrigger.Upstream.ID, trigger.Upstream.ID)
100+
assert.Equal(t, createdTrigger.Downstream.ID, trigger.Downstream.ID)
99101
})
100102

101103
t.Run("try to get run trigger with not valid ID", func(t *testing.T) {

vcs_provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type VcsProvider struct {
7575
// Relations
7676
Environments []*Environment `jsonapi:"relation,environments"`
7777
Account *Account `jsonapi:"relation,account"`
78+
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
7879
}
7980

8081
// VcsProvidersListOptions represents the options for listing vcs providers.
@@ -96,6 +97,7 @@ type VcsProvidersListOptions struct {
9697
// Scope filters.
9798
Environment *string `url:"filter[environment],omitempty"`
9899
Account *string `url:"filter[account],omitempty"`
100+
AgentPool *string `url:"filter[agent-pool],omitempty"`
99101
}
100102

101103
// List the vcs providers.
@@ -128,6 +130,7 @@ type VcsProviderCreateOptions struct {
128130
// Relations
129131
Environments []*Environment `jsonapi:"relation,environments,omitempty"`
130132
Account *Account `jsonapi:"relation,account,omitempty"`
133+
AgentPool *AgentPool `jsonapi:"relation,agent-pool,omitempty"`
131134
}
132135

133136
// Create is used to create a new vcs provider.
@@ -178,6 +181,9 @@ type VcsProviderUpdateOptions struct {
178181
Token *string `jsonapi:"attr,token,omitempty"`
179182
Url *string `jsonapi:"attr,url,omitempty"`
180183
Username *string `jsonapi:"attr,username,omitempty"`
184+
185+
// Relations
186+
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
181187
}
182188

183189
// Update settings of an existing vcs provider.

vcs_provider_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestVcsProvidersCreate(t *testing.T) {
6868

6969
t.Run("with valid options", func(t *testing.T) {
7070
options := VcsProviderCreateOptions{
71-
Name: String("foo"),
71+
Name: String("vcs-" + randomString(t)),
7272
VcsType: Github,
7373
AuthType: PersonalToken,
7474
Token: os.Getenv("GITHUB_TOKEN"),
@@ -95,6 +95,25 @@ func TestVcsProvidersCreate(t *testing.T) {
9595
}
9696
})
9797

98+
t.Run("with agent-pool attr vcs-enabled: false", func(t *testing.T) {
99+
ap, apCleanup := createAgentPool(t, client, false)
100+
defer apCleanup()
101+
102+
options := VcsProviderCreateOptions{
103+
Name: String("vcs-" + randomString(t)),
104+
VcsType: Github,
105+
AuthType: PersonalToken,
106+
Token: os.Getenv("GITHUB_TOKEN"),
107+
108+
Environments: []*Environment{envTest},
109+
Account: &Account{ID: defaultAccountID},
110+
AgentPool: ap,
111+
}
112+
113+
_, err := client.VcsProviders.Create(ctx, options)
114+
require.Error(t, err)
115+
})
116+
98117
t.Run("when options has an invalid environment", func(t *testing.T) {
99118
_, err := client.VcsProviders.Create(ctx, VcsProviderCreateOptions{
100119
Name: String("test-vcs"),

workspace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestWorkspacesCreate(t *testing.T) {
7474
envTest, envTestCleanup := createEnvironment(t, client)
7575
defer envTestCleanup()
7676

77-
pool, poolCleanup := createAgentPool(t, client)
77+
pool, poolCleanup := createAgentPool(t, client, false)
7878
defer poolCleanup()
7979

8080
t.Run("with valid options", func(t *testing.T) {
@@ -272,7 +272,7 @@ func TestWorkspacesUpdate(t *testing.T) {
272272
envTest, envTestCleanup := createEnvironment(t, client)
273273
defer envTestCleanup()
274274

275-
pool, poolCleanup := createAgentPool(t, client)
275+
pool, poolCleanup := createAgentPool(t, client, false)
276276
defer poolCleanup()
277277

278278
wsTest, _ := createWorkspace(t, client, envTest)

0 commit comments

Comments
 (0)