-
Notifications
You must be signed in to change notification settings - Fork 422
/
email_notification_integration_acceptance_test.go
102 lines (93 loc) · 4.11 KB
/
email_notification_integration_acceptance_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package resources_test
import (
"fmt"
"testing"
acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/provider/resources"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)
// TODO [SNOW-1007539]: use email of our service user (verified email address is required)
func TestAcc_EmailNotificationIntegration(t *testing.T) {
id := acc.TestClient().Ids.RandomAccountObjectIdentifier()
verifiedEmail := "artur.sawicki@snowflake.com"
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: acc.CheckDestroy(t, resources.EmailNotificationIntegration),
Steps: []resource.TestStep{
{
Config: emailNotificationIntegrationConfig(id.Name(), verifiedEmail),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "name", id.Name()),
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "fully_qualified_name", id.FullyQualifiedName()),
resource.TestCheckResourceAttr("snowflake_email_notification_integration.test", "allowed_recipients.0", verifiedEmail),
),
},
{
ResourceName: "snowflake_email_notification_integration.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func emailNotificationIntegrationConfig(name string, email string) string {
s := `
resource "snowflake_email_notification_integration" "test" {
name = "%s"
enabled = true
allowed_recipients = ["%s"]
comment = "test"
}
`
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 := acc.TestClient().Ids.Alpha()
verifiedEmail := "artur.sawicki@snowflake.com"
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.RequireAbove(tfversion.Version1_5_0),
},
CheckDestroy: acc.CheckDestroy(t, resources.EmailNotificationIntegration),
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)
}