Skip to content

Commit

Permalink
SCALRCORE-26056 - Provider > Add sharing VCS to environments feature
Browse files Browse the repository at this point in the history
  • Loading branch information
soltysss committed Apr 27, 2023
1 parent 4fe76f0 commit ab2356d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 5 additions & 1 deletion vcs_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type VcsProvider struct {
OAuth *OAuth `jsonapi:"attr,oauth"`
Token *string `jsonapi:"attr,token"`
Username *string `jsonapi:"attr,username"`
IsShared bool `jsonapi:"attr,is-shared"`

// Relations
Environments []*Environment `jsonapi:"relation,environments"`
Expand Down Expand Up @@ -126,6 +127,7 @@ type VcsProviderCreateOptions struct {
Token string `jsonapi:"attr,token"`
Url *string `jsonapi:"attr,url"`
Username *string `jsonapi:"attr,username"`
IsShared bool `jsonapi:"attr,is-shared,omitempty"`

// Relations
Environments []*Environment `jsonapi:"relation,environments,omitempty"`
Expand Down Expand Up @@ -181,9 +183,11 @@ type VcsProviderUpdateOptions struct {
Token *string `jsonapi:"attr,token,omitempty"`
Url *string `jsonapi:"attr,url,omitempty"`
Username *string `jsonapi:"attr,username,omitempty"`
IsShared bool `jsonapi:"attr,is-shared,omitempty"`

// Relations
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
Environments []*Environment `jsonapi:"relation,environments"`
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
}

// Update settings of an existing vcs provider.
Expand Down
29 changes: 27 additions & 2 deletions vcs_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,32 @@ func TestVcsProvidersCreate(t *testing.T) {
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, options.VcsType, item.VcsType)
assert.Equal(t, options.AuthType, item.AuthType)
assert.Equal(t, false, item.IsShared)
}
})

t.Run("shared provider", func(t *testing.T) {
options := VcsProviderCreateOptions{
Name: String("vcs-" + randomString(t)),
VcsType: Github,
AuthType: PersonalToken,
Token: os.Getenv("GITHUB_TOKEN"),
IsShared: true,

Account: &Account{ID: defaultAccountID},
}

vcs, err := client.VcsProviders.Create(ctx, options)
require.NoError(t, err)

assert.NotEmpty(t, vcs.ID)
assert.Equal(t, *options.Name, vcs.Name)
assert.Equal(t, options.VcsType, vcs.VcsType)
assert.Equal(t, options.AuthType, vcs.AuthType)
assert.Equal(t, options.IsShared, vcs.IsShared)

})

t.Run("with agent-pool attr vcs-enabled: false", func(t *testing.T) {
ap, apCleanup := createAgentPool(t, client, false)
defer apCleanup()
Expand Down Expand Up @@ -125,7 +148,7 @@ func TestVcsProvidersCreate(t *testing.T) {
t,
ResourceNotFoundError{
Message: fmt.Sprintf(
"Invalid Relationship\n\nEnvironment with ID '%s' not found or user unauthorized",
"Relationship 'environments' with ID '%s' not found or user unauthorized",
badIdentifier,
),
}.Error(),
Expand Down Expand Up @@ -186,14 +209,16 @@ func TestVcsProvidersUpdate(t *testing.T) {

t.Run("when updating a subset of values", func(t *testing.T) {
options := VcsProviderUpdateOptions{
Name: String(randomString(t)),
Name: String(randomString(t)),
IsShared: true,
}

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

assert.Equal(t, vcsTest.AuthType, vcsAfter.AuthType)
assert.Equal(t, vcsTest.VcsType, vcsAfter.VcsType)
assert.True(t, vcsTest.IsShared != vcsAfter.IsShared)
})

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

0 comments on commit ab2356d

Please sign in to comment.