Skip to content

Commit

Permalink
fix test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Dec 5, 2024
1 parent 9519132 commit 25778f7
Showing 1 changed file with 35 additions and 61 deletions.
96 changes: 35 additions & 61 deletions internal/framework/service/snippet_rules/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,19 @@ func TestAccCloudflareSnippetRules(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "rules.0.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.expression", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.description", "some description 1"),
resource.TestCheckResourceAttr(resourceName, "rules.0.snippet_name", "test_snippet_1"),
resource.TestCheckResourceAttr(resourceName, "rules.0.snippet_name", "test_snippet_0"),

resource.TestCheckResourceAttr(resourceName, "rules.1.%", "4"),
resource.TestCheckResourceAttr(resourceName, "rules.1.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.1.expression", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.1.description", "some description 2"),
resource.TestCheckResourceAttr(resourceName, "rules.1.snippet_name", "test_snippet2"),
resource.TestCheckResourceAttr(resourceName, "rules.1.snippet_name", "test_snippet_1"),

resource.TestCheckResourceAttr(resourceName, "rules.2.%", "4"),
resource.TestCheckResourceAttr(resourceName, "rules.2.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.2.expression", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.2.description", "some description 3"),
resource.TestCheckResourceAttr(resourceName, "rules.2.snippet_name", "test_snippet_3"),
),
},
{
Config: testAccCheckCloudflareSnippetRulesRemovedRule(rnd, zoneID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, consts.ZoneIDSchemaKey, zoneID),
resource.TestCheckResourceAttr(resourceName, "rules.#", "2"),

resource.TestCheckResourceAttr(resourceName, "rules.0.%", "4"),
resource.TestCheckResourceAttr(resourceName, "rules.0.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.expression", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.0.description", "some description 2"),
resource.TestCheckResourceAttr(resourceName, "rules.0.snippet_name", "test_snippet_2"),

resource.TestCheckResourceAttr(resourceName, "rules.1.%", "4"),
resource.TestCheckResourceAttr(resourceName, "rules.1.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.1.expression", "true"),
resource.TestCheckResourceAttr(resourceName, "rules.1.description", "some description 3"),
resource.TestCheckResourceAttr(resourceName, "rules.1.snippet_name", "test_snippet_3"),
resource.TestCheckResourceAttr(resourceName, "rules.2.snippet_name", "test_snippet_2"),
),
},
},
Expand All @@ -105,47 +86,40 @@ func TestAccCloudflareSnippetRules(t *testing.T) {

func testAccCheckCloudflareSnippetRules(rnd, zoneID string) string {
return fmt.Sprintf(`
resource "cloudflare_snippet_rules" "%[1]s" {
zone_id = "%[2]s"
rules {
enabled = true
expression = "true"
description = "some description 1"
snippet_name = "test_snippet_1"
}
rules {
enabled = true
expression = "true"
description = "some description 2"
snippet_name = "test_snippet_2"
}
rules {
enabled = true
expression = "true"
description = "some description 3"
snippet_name = "test_snippet_3"
resource "cloudflare_snippet" "%[1]s" {
count = 3
zone_id = "%[2]s"
name = "test_snippet_${count.index}"
main_module = "file1.js"
files {
name = "file1.js"
content = "export default {async fetch(request) {return fetch(request)}};"
}
}
}`, rnd, zoneID)
}
func testAccCheckCloudflareSnippetRulesRemovedRule(rnd, zoneID string) string {
return fmt.Sprintf(`
resource "cloudflare_snippet_rules" "%[1]s" {
zone_id = "%[2]s"
rules {
enabled = true
expression = "true"
description = "some description 2"
snippet_name = "test_snippet_2"
}
rules {
enabled = true
expression = "true"
description = "some description 3"
snippet_name = "test_snippet_3"
}
zone_id = "%[2]s"
rules {
enabled = true
expression = "true"
description = "some description 1"
snippet_name = "test_snippet_0"
}
rules {
enabled = true
expression = "true"
description = "some description 2"
snippet_name = "test_snippet_1"
}
rules {
enabled = true
expression = "true"
description = "some description 3"
snippet_name = "test_snippet_2"
}
depends_on = ["cloudflare_snippet.%[1]s"]
}`, rnd, zoneID)
}

0 comments on commit 25778f7

Please sign in to comment.