Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WebhookURL to VCSRepo struct #413

Merged
merged 5 commits into from Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 17 additions & 18 deletions policy_set_integration_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"os"
"regexp"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -165,15 +166,14 @@ func TestPolicySetsCreate(t *testing.T) {
assert.Equal(t, ps.Description, "")
assert.False(t, ps.Global)
assert.Equal(t, ps.PoliciesPath, "/policy-sets/foo")
assert.Equal(t, ps.VCSRepo, &VCSRepo{
Branch: "policies",
DisplayIdentifier: githubIdentifier,
Identifier: githubIdentifier,
OAuthTokenID: oc.ID,
IngressSubmodules: true,
RepositoryHTTPURL: fmt.Sprintf("https://github.com/%s", githubIdentifier),
ServiceProvider: string(ServiceProviderGithub),
})
assert.Equal(t, ps.VCSRepo.Branch, "policies")
assert.Equal(t, ps.VCSRepo.DisplayIdentifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.IngressSubmodules, true)
assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID)
assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier))
assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub))
assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL)
})

t.Run("with vcs policy updated", func(t *testing.T) {
Expand Down Expand Up @@ -203,15 +203,14 @@ func TestPolicySetsCreate(t *testing.T) {
assert.Equal(t, ps.Description, "")
assert.False(t, ps.Global)
assert.Equal(t, ps.PoliciesPath, "/policy-sets/bar")
assert.Equal(t, ps.VCSRepo, &VCSRepo{
Branch: "policies",
DisplayIdentifier: githubIdentifier,
Identifier: githubIdentifier,
OAuthTokenID: oc.ID,
IngressSubmodules: false,
RepositoryHTTPURL: fmt.Sprintf("https://github.com/%s", githubIdentifier),
ServiceProvider: string(ServiceProviderGithub),
})
assert.Equal(t, ps.VCSRepo.Branch, "policies")
assert.Equal(t, ps.VCSRepo.DisplayIdentifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.IngressSubmodules, false)
assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID)
assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier))
assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub))
assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL)
})

t.Run("without a name provided", func(t *testing.T) {
Expand Down
20 changes: 11 additions & 9 deletions registry_module_integration_test.go
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"os"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -265,15 +266,14 @@ func TestRegistryModulesCreateWithVCSConnection(t *testing.T) {
assert.NotEmpty(t, rm.ID)
assert.Equal(t, registryModuleName, rm.Name)
assert.Equal(t, registryModuleProvider, rm.Provider)
assert.Equal(t, &VCSRepo{
Branch: "",
Identifier: githubIdentifier,
OAuthTokenID: oauthTokenTest.ID,
DisplayIdentifier: githubIdentifier,
IngressSubmodules: true,
RepositoryHTTPURL: fmt.Sprintf("https://github.com/%s", githubIdentifier),
ServiceProvider: string(ServiceProviderGithub),
}, rm.VCSRepo)
assert.Equal(t, rm.VCSRepo.Branch, "")
assert.Equal(t, rm.VCSRepo.DisplayIdentifier, githubIdentifier)
assert.Equal(t, rm.VCSRepo.Identifier, githubIdentifier)
assert.Equal(t, rm.VCSRepo.IngressSubmodules, true)
assert.Equal(t, rm.VCSRepo.OAuthTokenID, oauthTokenTest.ID)
assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier))
assert.Equal(t, rm.VCSRepo.ServiceProvider, string(ServiceProviderGithub))
assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), rm.VCSRepo.WebhookURL)

t.Run("permissions are properly decoded", func(t *testing.T) {
assert.True(t, rm.Permissions.CanDelete)
Expand Down Expand Up @@ -746,6 +746,7 @@ func TestRegistryModule_Unmarshal(t *testing.T) {
"oauth-token-id": "token",
"repository-http-url": "github.com",
"service-provider": "github",
"webhook-url": "https://app.terraform.io/webhooks/vcs/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
},
"version-statuses": []interface{}{
map[string]interface{}{
Expand Down Expand Up @@ -779,6 +780,7 @@ func TestRegistryModule_Unmarshal(t *testing.T) {
assert.Equal(t, rm.VCSRepo.OAuthTokenID, "token")
assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, "github.com")
assert.Equal(t, rm.VCSRepo.ServiceProvider, "github")
assert.Equal(t, rm.VCSRepo.WebhookURL, "https://app.terraform.io/webhooks/vcs/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
assert.Equal(t, rm.Status, RegistryModuleStatusPending)
assert.Equal(t, rm.VersionStatuses[0].Version, "1.1.1")
assert.Equal(t, rm.VersionStatuses[0].Status, RegistryModuleVersionStatusPending)
Expand Down
1 change: 1 addition & 0 deletions workspace.go
Expand Up @@ -182,6 +182,7 @@ type VCSRepo struct {
OAuthTokenID string `jsonapi:"attr,oauth-token-id"`
RepositoryHTTPURL string `jsonapi:"attr,repository-http-url"`
ServiceProvider string `jsonapi:"attr,service-provider"`
WebhookURL string `jsonapi:"attr,webhook-url"`
}

// WorkspaceActions represents the workspace actions.
Expand Down
2 changes: 2 additions & 0 deletions workspace_integration_test.go
Expand Up @@ -1446,6 +1446,7 @@ func TestWorkspace_Unmarshal(t *testing.T) {
"oauth-token-id": "token",
"repository-http-url": "github.com",
"service-provider": "github",
"webhook-url": "https://app.terraform.io/webhooks/vcs/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
},
"actions": map[string]interface{}{
"is-destroyable": true,
Expand Down Expand Up @@ -1481,6 +1482,7 @@ func TestWorkspace_Unmarshal(t *testing.T) {
assert.Equal(t, ws.VCSRepo.OAuthTokenID, "token")
assert.Equal(t, ws.VCSRepo.RepositoryHTTPURL, "github.com")
assert.Equal(t, ws.VCSRepo.ServiceProvider, "github")
assert.Equal(t, ws.VCSRepo.WebhookURL, "https://app.terraform.io/webhooks/vcs/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
assert.Equal(t, ws.Actions.IsDestroyable, true)
assert.Equal(t, ws.TriggerPrefixes, []string{"prefix-"})
assert.Equal(t, ws.TriggerPatterns, []string{"pattern1/**/*", "pattern2/**/submodule/*"})
Expand Down