Skip to content

Commit

Permalink
Go the TF config route
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Christenson II committed Feb 2, 2024
1 parent bf26f60 commit c5d9234
Show file tree
Hide file tree
Showing 2 changed files with 346 additions and 74 deletions.
82 changes: 16 additions & 66 deletions internal/auth0/prompt/resource_partials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ package prompt_test

import (
"context"
"os"
"testing"
"time"

"github.com/auth0/go-auth0"
"github.com/auth0/go-auth0/management"
"github.com/auth0/terraform-provider-auth0/internal/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/stretchr/testify/assert"
"os"
"testing"
)

var (
Expand All @@ -21,13 +17,6 @@ var (
)

func TestAccPromptPartials(t *testing.T) {
_ = givenACustomDomain(t)
_ = givenAUniversalLogin(t)

t.Cleanup(func() {
cleanupPartialsPrompt(t, management.PartialsPromptSegment("login"))
})

acctest.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
Expand All @@ -48,72 +37,33 @@ func TestAccPromptPartials(t *testing.T) {
})
}

func givenACustomDomain(t *testing.T) *management.CustomDomain {
t.Helper()

customDomain := &management.CustomDomain{
Domain: auth0.Stringf("%d.auth.uat.auth0.com", time.Now().UTC().Unix()),
Type: auth0.String("auth0_managed_certs"),
TLSPolicy: auth0.String("recommended"),
}

err := manager.CustomDomain.Create(context.Background(), customDomain)
assert.NoError(t, err)

t.Cleanup(func() {
cleanupCustomDomain(t, customDomain.GetID())
})

return customDomain
const testAccGivenACustomDomain = `
resource "auth0_custom_domain" "my_custom_domain" {
domain = "auth.terraform-provider-auth0.com"
type = "auth0_managed_certs"
}
`

func givenAUniversalLogin(t *testing.T) *management.BrandingUniversalLogin {
t.Helper()
const testGivenABrandingTemplate = `
resource "auth0_branding" "my_brand" {
depends_on = [ auth0_custom_domain.my_custom_domain ]
body := `<!DOCTYPE html><html><head>{%- auth0:head -%}</head><body>{%- auth0:widget -%}</body></html>`
ul := &management.BrandingUniversalLogin{
Body: auth0.String(body),
universal_login {
body = "<!DOCTYPE html><html><head>{%- auth0:head -%}</head><body>{%- auth0:widget -%}</body></html>"
}

err := manager.Branding.SetUniversalLogin(context.Background(), ul)
assert.NoError(t, err)

t.Cleanup(func() {
cleanupUniversalLogin(t)
})

return ul
}

func cleanupCustomDomain(t *testing.T, customDomainID string) {
t.Helper()

err := manager.CustomDomain.Delete(context.Background(), customDomainID)
assert.NoError(t, err)
}

func cleanupUniversalLogin(t *testing.T) {
t.Helper()

err := manager.Branding.DeleteUniversalLogin(context.Background())
assert.NoError(t, err)
}
`

func cleanupPartialsPrompt(t *testing.T, prompt management.PartialsPromptSegment) {
t.Helper()

err := manager.Prompt.DeletePartials(context.Background(), &management.PartialsPrompt{Segment: prompt})
assert.NoError(t, err)
}
const testAccGivenPrerequisites = testAccGivenACustomDomain + testGivenABrandingTemplate

const testAccPromptPartialsCreate = `
const testAccPromptPartialsCreate = testAccGivenPrerequisites + `
resource "auth0_prompt_partials" "prompt_partials" {
prompt = "login"
form_content_start = "<div>Test Header</div>"
}
`

const testAccPromptPartialsUpdate = `
const testAccPromptPartialsUpdate = testAccGivenPrerequisites + `
resource "auth0_prompt_partials" "prompt_partials" {
prompt = "login"
form_content_start = "<div>Updated Test Header</div>"
Expand Down
Loading

0 comments on commit c5d9234

Please sign in to comment.