Skip to content

Commit

Permalink
add test coverage for drop rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Nov 23, 2023
1 parent 8ca26a4 commit fe44307
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
}
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")
Expand Down Expand Up @@ -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", "[email protected]"),

resource.TestCheckResourceAttr(name, "action.0.type", "drop"),
),
},
},
})
}

0 comments on commit fe44307

Please sign in to comment.