From fe44307c855d04c023ad5e4cfa74859cff0229d1 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Thu, 23 Nov 2023 13:31:05 +1100 Subject: [PATCH] add test coverage for drop rules --- ...urce_cloudflare_email_routing_rule_test.go | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/internal/sdkv2provider/resource_cloudflare_email_routing_rule_test.go b/internal/sdkv2provider/resource_cloudflare_email_routing_rule_test.go index 045f88df6b..d45f16f17e 100644 --- a/internal/sdkv2provider/resource_cloudflare_email_routing_rule_test.go +++ b/internal/sdkv2provider/resource_cloudflare_email_routing_rule_test.go @@ -30,7 +30,27 @@ func testEmailRoutingRuleConfig(resourceID, zoneID string, enabled bool, priorit `, resourceID, zoneID, enabled, priority) } -func TestAccTestEmailRoutingRule(t *testing.T) { +func testEmailRoutingRuleConfigDrop(resourceID, zoneID string, enabled bool, priority int) string { + return fmt.Sprintf(` + resource "cloudflare_email_routing_rule" "%[1]s" { + zone_id = "%[2]s" + enabled = "%[3]t" + priority = "%[4]d" + name = "%[1]s" + matcher { + field = "to" + type = "literal" + value = "test@example.com" + } + + action { + type = "drop" + } + } + `, resourceID, zoneID, enabled, priority) +} + +func TestAccCloudflareEmailRoutingRule_Basic(t *testing.T) { rnd := generateRandomResourceName() name := "cloudflare_email_routing_rule." + rnd zoneID := os.Getenv("CLOUDFLARE_ZONE_ID") @@ -59,3 +79,31 @@ func TestAccTestEmailRoutingRule(t *testing.T) { }, }) } + +func TestAccCloudflareEmailRoutingRule_Drop(t *testing.T) { + rnd := generateRandomResourceName() + name := "cloudflare_email_routing_rule." + rnd + zoneID := os.Getenv("CLOUDFLARE_ZONE_ID") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: providerFactories, + Steps: []resource.TestStep{ + { + Config: testEmailRoutingRuleConfigDrop(rnd, zoneID, true, 10), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(name, "enabled", "true"), + resource.TestCheckResourceAttr(name, consts.ZoneIDSchemaKey, zoneID), + resource.TestCheckResourceAttr(name, "priority", "10"), + resource.TestCheckResourceAttr(name, "name", rnd), + + resource.TestCheckResourceAttr(name, "matcher.0.type", "literal"), + resource.TestCheckResourceAttr(name, "matcher.0.field", "to"), + resource.TestCheckResourceAttr(name, "matcher.0.value", "test@example.com"), + + resource.TestCheckResourceAttr(name, "action.0.type", "drop"), + ), + }, + }, + }) +}