diff --git a/policy_set_integration_test.go b/policy_set_integration_test.go index 340c1c8ae..2cd02cd56 100644 --- a/policy_set_integration_test.go +++ b/policy_set_integration_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os" + "regexp" "testing" "github.com/stretchr/testify/assert" @@ -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) { @@ -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) { diff --git a/registry_module_integration_test.go b/registry_module_integration_test.go index 60cc5be8a..5e4711405 100644 --- a/registry_module_integration_test.go +++ b/registry_module_integration_test.go @@ -9,6 +9,7 @@ import ( "encoding/json" "fmt" "os" + "regexp" "strings" "testing" @@ -310,15 +311,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) @@ -791,6 +791,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{}{ @@ -824,6 +825,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) diff --git a/workspace.go b/workspace.go index d45646390..df627b811 100644 --- a/workspace.go +++ b/workspace.go @@ -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. diff --git a/workspace_integration_test.go b/workspace_integration_test.go index 43a5a89ea..b6f936366 100644 --- a/workspace_integration_test.go +++ b/workspace_integration_test.go @@ -1502,6 +1502,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, @@ -1537,6 +1538,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/*"})