Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Use wiremock in custom domain verification test
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Jan 26, 2022
1 parent 1ce30a7 commit 7a7ecd1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@ jobs:
- name: Build
run: make build

- name: Start containers
run: docker-compose up -d --build

- name: Test
run: make testacc OPTS=-coverprofile=c.out
env:
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
AUTH0_CLIENT_ID: ${{ secrets.AUTH0_CLIENT_ID }}
AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_CLIENT_SECRET }}
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Send code coverage report
uses: aktions/codeclimate-test-reporter@v1
with:
codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
command: after-build --prefix github.com/alexkappa/terraform-provider-auth0

- name: Stop containers
if: always()
run: docker-compose down
38 changes: 38 additions & 0 deletions auth0/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,49 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"

"gopkg.in/auth0.v5/management"
)

func providerWithWiremock() *schema.Provider {
return &schema.Provider{
ResourcesMap: map[string]*schema.Resource{
"auth0_client": newClient(),
"auth0_global_client": newGlobalClient(),
"auth0_client_grant": newClientGrant(),
"auth0_connection": newConnection(),
"auth0_custom_domain": newCustomDomain(),
"auth0_custom_domain_verification": newCustomDomainVerification(),
"auth0_resource_server": newResourceServer(),
"auth0_rule": newRule(),
"auth0_rule_config": newRuleConfig(),
"auth0_hook": newHook(),
"auth0_prompt": newPrompt(),
"auth0_prompt_custom_text": newPromptCustomText(),
"auth0_email": newEmail(),
"auth0_email_template": newEmailTemplate(),
"auth0_user": newUser(),
"auth0_tenant": newTenant(),
"auth0_role": newRole(),
"auth0_log_stream": newLogStream(),
"auth0_branding": newBranding(),
"auth0_guardian": newGuardian(),
"auth0_organization": newOrganization(),
"auth0_action": newAction(),
"auth0_trigger_binding": newTriggerBinding(),
},
ConfigureFunc: func(data *schema.ResourceData) (interface{}, error) {
return management.New(
"localhost:8080",
management.WithInsecure(),
management.WithDebug(true),
)
},
}
}

func Auth0() (*management.Management, error) {
c := terraform.NewResourceConfigRaw(nil)
p := Provider()
Expand Down
26 changes: 4 additions & 22 deletions auth0/resource_auth0_custom_domain_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,36 @@ package auth0
import (
"testing"

"github.com/alexkappa/terraform-provider-auth0/auth0/internal/digitalocean"
"github.com/alexkappa/terraform-provider-auth0/auth0/internal/random"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccCustomDomainVerification(t *testing.T) {

rand := random.String(6)

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
"auth0": Provider(),
"digitalocean": digitalocean.Provider(),
"auth0": providerWithWiremock(),
},
Steps: []resource.TestStep{
{
Config: random.Template(testAccCustomDomainVerification, rand),
Config: testAccCustomDomainVerification,
Check: resource.ComposeTestCheckFunc(
random.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "domain", "{{.random}}.auth.uat.alexkappa.com", rand),
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "domain", "terraform-provider.auth0.com"),
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "type", "auth0_managed_certs"),
resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "custom_domain_id"),
),
},
{
Config: random.Template(testAccCustomDomainVerification, rand),
},
},
})
}

const testAccCustomDomainVerification = `
resource "digitalocean_record" "auth0_domain" {
domain = "alexkappa.com"
type = upper(auth0_custom_domain.my_custom_domain.verification[0].methods[0].name)
name = "{{.random}}.auth.uat.alexkappa.com."
value = "${auth0_custom_domain.my_custom_domain.verification[0].methods[0].record}."
}
resource "auth0_custom_domain" "my_custom_domain" {
domain = "{{.random}}.auth.uat.alexkappa.com"
domain = "terraform-provider.auth0.com"
type = "auth0_managed_certs"
}
resource "auth0_custom_domain_verification" "my_custom_domain_verification" {
custom_domain_id = auth0_custom_domain.my_custom_domain.id
timeouts { create = "15m" }
depends_on = [ digitalocean_record.auth0_domain ]
}
`

0 comments on commit 7a7ecd1

Please sign in to comment.