-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix email notification integration (#2292)
* Change allowed recipients to optional * Use my own email for email notification integration tests * Fix the docs * Add comment
- Loading branch information
1 parent
bbad5c6
commit 70edd3e
Showing
3 changed files
with
81 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package resources_test | |
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
|
@@ -11,22 +10,21 @@ import ( | |
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
// TODO: use email of our service user | ||
func TestAcc_EmailNotificationIntegration(t *testing.T) { | ||
env := os.Getenv("SKIP_EMAIL_INTEGRATION_TESTS") | ||
if env != "" { | ||
t.Skip("Skipping TestAcc_EmailNotificationIntegration") | ||
} | ||
|
||
emailIntegrationName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
verifiedEmail := "[email protected]" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
Providers: acc.TestAccProviders(), | ||
PreCheck: func() { acc.TestAccPreCheck(t) }, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: emailNotificationIntegrationConfig(emailIntegrationName), | ||
Config: emailNotificationIntegrationConfig(emailIntegrationName, verifiedEmail), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "name", emailIntegrationName), | ||
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "allowed_recipients.0", verifiedEmail), | ||
), | ||
}, | ||
{ | ||
|
@@ -38,12 +36,12 @@ func TestAcc_EmailNotificationIntegration(t *testing.T) { | |
}) | ||
} | ||
|
||
func emailNotificationIntegrationConfig(name string) string { | ||
func emailNotificationIntegrationConfig(name string, email string) string { | ||
s := ` | ||
resource "snowflake_email_notification_integration" "test" { | ||
name = "%s" | ||
enabled = true | ||
allowed_recipients = ["[email protected]"] # Verified Email Addresses is required | ||
allowed_recipients = ["%s"] # Verified Email Addresses is required | ||
comment = "test" | ||
/* | ||
Error: error creating notification integration: 394209 (22023): | ||
|
@@ -52,5 +50,50 @@ Either these email addresses are not yet validated or do not belong to any user | |
*/ | ||
} | ||
` | ||
return fmt.Sprintf(s, name, email) | ||
} | ||
|
||
// TestAcc_EmailNotificationIntegration_issue2223 proves https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues/2223 issue. | ||
// Snowflake allowed empty allowed recipients in https://docs.snowflake.com/en/release-notes/2023/7_40#email-notification-integrations-allowed-recipients-no-longer-required. | ||
func TestAcc_EmailNotificationIntegration_issue2223(t *testing.T) { | ||
emailIntegrationName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) | ||
verifiedEmail := "[email protected]" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
Providers: acc.TestAccProviders(), | ||
PreCheck: func() { acc.TestAccPreCheck(t) }, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: emailNotificationIntegrationWithoutRecipientsConfig(emailIntegrationName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "name", emailIntegrationName), | ||
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "allowed_recipients.#", "0"), | ||
), | ||
}, | ||
{ | ||
Config: emailNotificationIntegrationConfig(emailIntegrationName, verifiedEmail), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "name", emailIntegrationName), | ||
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "allowed_recipients.0", verifiedEmail), | ||
), | ||
}, | ||
{ | ||
Config: emailNotificationIntegrationWithoutRecipientsConfig(emailIntegrationName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "name", emailIntegrationName), | ||
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "allowed_recipients.#", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func emailNotificationIntegrationWithoutRecipientsConfig(name string) string { | ||
s := ` | ||
resource "snowflake_email_notification_integration" "test" { | ||
name = "%s" | ||
enabled = true | ||
}` | ||
return fmt.Sprintf(s, name) | ||
} |