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 4 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
34 changes: 16 additions & 18 deletions policy_set_integration_test.go
Expand Up @@ -165,15 +165,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, "^https://app\\.terraform\\.io/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", ps.VCSRepo.WebhookURL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I might change here is the host, given that someone can test against a Terraform Enterprise installation where the host might not necessarily match with app...terraform...io. The best choice here would be to stick the value of TFE_ADDRESS into the regexp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I see the problem. Is the rest of the URL for the webhook standard or can the endpoint and/or the UUID part also change on TFE?

Copy link
Contributor Author

@kgns kgns May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to easily access the Config object used to create the test client, so I called DefaultConfig() myself for its Address field. DefaultConfig() function handles all cases with TFE_ADDRESS and TFE_HOSTNAME env variables (or lack thereof) so I thought it would be best to use it instead of just TFE_ADDRESS. If there is a better/cleaner way, feel free to point me in the right direction

})

t.Run("with vcs policy updated", func(t *testing.T) {
Expand Down Expand Up @@ -203,15 +202,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, "^https://app\\.terraform\\.io/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", ps.VCSRepo.WebhookURL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, here as well!

})

t.Run("without a name provided", func(t *testing.T) {
Expand Down
19 changes: 10 additions & 9 deletions registry_module_integration_test.go
Expand Up @@ -265,15 +265,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, "^https://app\\.terraform\\.io/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", 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 +745,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 +779,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