Skip to content

Commit 6bfded1

Browse files
Merge branch 'weirdian2k3/main'
2 parents ae64da3 + 59ab48f commit 6bfded1

File tree

4 files changed

+213
-2
lines changed

4 files changed

+213
-2
lines changed

docs/auth0_terraform_generate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ auth0 terraform generate [flags]
3333
```
3434
--force Skip confirmation.
3535
-o, --output-dir string Output directory for the generated Terraform config files. If not provided, the files will be saved in the current working directory. (default "./")
36-
-r, --resources strings Resource types to generate Terraform config for. If not provided, config files for all available resources will be generated. (default [auth0_action,auth0_attack_protection,auth0_branding,auth0_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_email_provider,auth0_guardian,auth0_organization,auth0_pages,auth0_prompt,auth0_prompt_custom_text,auth0_resource_server,auth0_role,auth0_tenant,auth0_trigger_actions])
36+
-r, --resources strings Resource types to generate Terraform config for. If not provided, config files for all available resources will be generated. (default [auth0_action,auth0_attack_protection,auth0_branding,auth0_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_email_provider,auth0_email_template,auth0_guardian,auth0_organization,auth0_pages,auth0_prompt,auth0_prompt_custom_text,auth0_resource_server,auth0_role,auth0_tenant,auth0_trigger_actions])
3737
```
3838

3939

internal/auth0/mock/email_template_mock.go

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/cli/terraform_fetcher.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ func (f *emailTemplateResourceFetcher) FetchData(ctx context.Context) (importDat
250250
templates := []string{`verify_email`, `reset_email`, `welcome_email`, `blocked_account`, `stolen_credentials`, `enrollment_email`, `mfa_oob_code`, `change_password`, `password_reset`}
251251

252252
for _, template := range templates {
253-
254253
emailTemplate, err := f.api.EmailTemplate.Read(ctx, template)
255254
if err != nil {
256255
if mErr, ok := err.(management.Error); ok && mErr.Status() == http.StatusNotFound {

internal/cli/terraform_fetcher_test.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,124 @@ func TestEmailProviderResourceFetcher_FetchData(t *testing.T) {
623623
assert.EqualError(t, err, "failed to read email provider")
624624
})
625625
}
626+
func TestEmailTemplateResourceFetcher_FetchData(t *testing.T) {
627+
t.Run("it successfully retrieves email templates data", func(t *testing.T) {
628+
ctrl := gomock.NewController(t)
629+
defer ctrl.Finish()
630+
631+
emailTemplateAPI := mock.NewMockEmailTemplateAPI(ctrl)
632+
templates := []string{
633+
"verify_email", "reset_email", "welcome_email",
634+
"blocked_account", "stolen_credentials",
635+
"enrollment_email", "mfa_oob_code",
636+
"change_password", "password_reset",
637+
}
638+
639+
for _, tmpl := range templates {
640+
emailTemplateAPI.EXPECT().
641+
Read(gomock.Any(), tmpl).
642+
Return(&management.EmailTemplate{Template: auth0.String(tmpl)}, nil)
643+
}
644+
645+
fetcher := emailTemplateResourceFetcher{
646+
api: &auth0.API{
647+
EmailTemplate: emailTemplateAPI,
648+
},
649+
}
650+
651+
expectedData := importDataList{
652+
{
653+
ResourceName: "auth0_email_template.verify_email",
654+
ImportID: "verify_email",
655+
},
656+
{
657+
ResourceName: "auth0_email_template.reset_email",
658+
ImportID: "reset_email",
659+
},
660+
{
661+
ResourceName: "auth0_email_template.welcome_email",
662+
ImportID: "welcome_email",
663+
},
664+
{
665+
ResourceName: "auth0_email_template.blocked_account",
666+
ImportID: "blocked_account",
667+
},
668+
{
669+
ResourceName: "auth0_email_template.stolen_credentials",
670+
ImportID: "stolen_credentials",
671+
},
672+
{
673+
ResourceName: "auth0_email_template.enrollment_email",
674+
ImportID: "enrollment_email",
675+
},
676+
{
677+
ResourceName: "auth0_email_template.mfa_oob_code",
678+
ImportID: "mfa_oob_code",
679+
},
680+
{
681+
ResourceName: "auth0_email_template.change_password",
682+
ImportID: "change_password",
683+
},
684+
{
685+
ResourceName: "auth0_email_template.password_reset",
686+
ImportID: "password_reset",
687+
},
688+
}
689+
690+
data, err := fetcher.FetchData(context.Background())
691+
assert.NoError(t, err)
692+
assert.Equal(t, expectedData, data)
693+
})
694+
695+
t.Run("it does not generate email template import data if email template does not exist", func(t *testing.T) {
696+
ctrl := gomock.NewController(t)
697+
defer ctrl.Finish()
698+
699+
mErr := mockManagamentError{status: http.StatusNotFound}
700+
emailTemplateAPI := mock.NewMockEmailTemplateAPI(ctrl)
701+
templates := []string{
702+
"verify_email", "reset_email", "welcome_email",
703+
"blocked_account", "stolen_credentials",
704+
"enrollment_email", "mfa_oob_code",
705+
"change_password", "password_reset",
706+
}
707+
708+
for _, tmpl := range templates {
709+
emailTemplateAPI.EXPECT().
710+
Read(gomock.Any(), tmpl).
711+
Return(nil, mErr)
712+
}
713+
714+
fetcher := emailTemplateResourceFetcher{
715+
api: &auth0.API{
716+
EmailTemplate: emailTemplateAPI,
717+
},
718+
}
719+
720+
data, err := fetcher.FetchData(context.Background())
721+
assert.NoError(t, err)
722+
assert.Len(t, data, 0)
723+
})
724+
725+
t.Run("it returns an error if api call fails", func(t *testing.T) {
726+
ctrl := gomock.NewController(t)
727+
defer ctrl.Finish()
728+
729+
emailTemplateAPI := mock.NewMockEmailTemplateAPI(ctrl)
730+
emailTemplateAPI.EXPECT().
731+
Read(gomock.Any(), gomock.Any()).
732+
Return(nil, fmt.Errorf("failed to read email template"))
733+
734+
fetcher := emailTemplateResourceFetcher{
735+
api: &auth0.API{
736+
EmailTemplate: emailTemplateAPI,
737+
},
738+
}
739+
740+
_, err := fetcher.FetchData(context.Background())
741+
assert.EqualError(t, err, "failed to read email template")
742+
})
743+
}
626744

627745
func TestLogStreamResourceFetcher_FetchData(t *testing.T) {
628746
t.Run("it successfully retrieves log streams data", func(t *testing.T) {

0 commit comments

Comments
 (0)