Skip to content

Commit e257255

Browse files
authored
Merge pull request #108 from Scalr/feature/SCALRCORE-26056
SCALRCORE-26056 - Provider > Add sharing VCS to environments feature
2 parents 178ddf7 + ed40065 commit e257255

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

vcs_provider.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type VcsProvider struct {
7171
OAuth *OAuth `jsonapi:"attr,oauth"`
7272
Token *string `jsonapi:"attr,token"`
7373
Username *string `jsonapi:"attr,username"`
74+
IsShared bool `jsonapi:"attr,is-shared"`
7475

7576
// Relations
7677
Environments []*Environment `jsonapi:"relation,environments"`
@@ -126,6 +127,7 @@ type VcsProviderCreateOptions struct {
126127
Token string `jsonapi:"attr,token"`
127128
Url *string `jsonapi:"attr,url"`
128129
Username *string `jsonapi:"attr,username"`
130+
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
129131

130132
// Relations
131133
Environments []*Environment `jsonapi:"relation,environments,omitempty"`
@@ -181,9 +183,11 @@ type VcsProviderUpdateOptions struct {
181183
Token *string `jsonapi:"attr,token,omitempty"`
182184
Url *string `jsonapi:"attr,url,omitempty"`
183185
Username *string `jsonapi:"attr,username,omitempty"`
186+
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
184187

185188
// Relations
186-
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
189+
Environments []*Environment `jsonapi:"relation,environments"`
190+
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
187191
}
188192

189193
// Update settings of an existing vcs provider.

vcs_provider_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,32 @@ func TestVcsProvidersCreate(t *testing.T) {
9292
assert.Equal(t, *options.Name, item.Name)
9393
assert.Equal(t, options.VcsType, item.VcsType)
9494
assert.Equal(t, options.AuthType, item.AuthType)
95+
assert.Equal(t, false, item.IsShared)
9596
}
9697
})
9798

99+
t.Run("shared provider", func(t *testing.T) {
100+
options := VcsProviderCreateOptions{
101+
Name: String("vcs-" + randomString(t)),
102+
VcsType: Github,
103+
AuthType: PersonalToken,
104+
Token: os.Getenv("GITHUB_TOKEN"),
105+
IsShared: Bool(true),
106+
107+
Account: &Account{ID: defaultAccountID},
108+
}
109+
110+
vcs, err := client.VcsProviders.Create(ctx, options)
111+
require.NoError(t, err)
112+
113+
assert.NotEmpty(t, vcs.ID)
114+
assert.Equal(t, *options.Name, vcs.Name)
115+
assert.Equal(t, options.VcsType, vcs.VcsType)
116+
assert.Equal(t, options.AuthType, vcs.AuthType)
117+
assert.Equal(t, *options.IsShared, vcs.IsShared)
118+
119+
})
120+
98121
t.Run("with agent-pool attr vcs-enabled: false", func(t *testing.T) {
99122
ap, apCleanup := createAgentPool(t, client, false)
100123
defer apCleanup()
@@ -186,14 +209,16 @@ func TestVcsProvidersUpdate(t *testing.T) {
186209

187210
t.Run("when updating a subset of values", func(t *testing.T) {
188211
options := VcsProviderUpdateOptions{
189-
Name: String(randomString(t)),
212+
Name: String(randomString(t)),
213+
IsShared: Bool(true),
190214
}
191215

192216
vcsAfter, err := client.VcsProviders.Update(ctx, vcsTest.ID, options)
193217
require.NoError(t, err)
194218

195219
assert.Equal(t, vcsTest.AuthType, vcsAfter.AuthType)
196220
assert.Equal(t, vcsTest.VcsType, vcsAfter.VcsType)
221+
assert.True(t, vcsTest.IsShared != vcsAfter.IsShared)
197222
})
198223

199224
t.Run("with valid options", func(t *testing.T) {

0 commit comments

Comments
 (0)