Skip to content

Commit

Permalink
test(waf): fix test case failed issue (#5523)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruwenqiang123 authored Sep 10, 2024
1 parent 35edbe7 commit b8cac8e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ data "huaweicloud_waf_rules_anti_crawler" "test" {
huaweicloud_waf_rule_anti_crawler.test
]
policy_id = huaweicloud_waf_policy.policy_1.id
policy_id = huaweicloud_waf_policy.test.id
}
locals {
rule_id = data.huaweicloud_waf_rules_anti_crawler.test.rules[0].id
}
data "huaweicloud_waf_rules_anti_crawler" "filter_by_rule_id" {
policy_id = huaweicloud_waf_policy.policy_1.id
policy_id = huaweicloud_waf_policy.test.id
rule_id = local.rule_id
}
Expand All @@ -108,7 +108,7 @@ locals {
}
data "huaweicloud_waf_rules_anti_crawler" "filter_by_name" {
policy_id = huaweicloud_waf_policy.policy_1.id
policy_id = huaweicloud_waf_policy.test.id
name = local.name
}
Expand All @@ -123,7 +123,7 @@ output "name_filter_is_useful" {
}
data "huaweicloud_waf_rules_anti_crawler" "not_found" {
policy_id = huaweicloud_waf_policy.policy_1.id
policy_id = huaweicloud_waf_policy.test.id
name = "not_found"
}
Expand All @@ -136,7 +136,7 @@ locals {
}
data "huaweicloud_waf_rules_anti_crawler" "filter_by_protection_mode" {
policy_id = huaweicloud_waf_policy.policy_1.id
policy_id = huaweicloud_waf_policy.test.id
protection_mode = local.protection_mode
}
Expand All @@ -156,7 +156,7 @@ locals {
}
data "huaweicloud_waf_rules_anti_crawler" "filter_by_status" {
policy_id = huaweicloud_waf_policy.policy_1.id
policy_id = huaweicloud_waf_policy.test.id
status = local.status
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/common"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

Expand Down Expand Up @@ -143,15 +144,15 @@ func TestAccRuleAntiCrawler_exceptProtectionMode(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(rName, "policy_id",
"huaweicloud_waf_policy.policy_1", "id"),
"huaweicloud_waf_policy.test", "id"),
resource.TestCheckResourceAttr(rName, "name", name),
resource.TestCheckResourceAttr(rName, "protection_mode", "anticrawler_except_url"),
resource.TestCheckResourceAttr(rName, "priority", "500"),
resource.TestCheckResourceAttr(rName, "description", "test description"),
resource.TestCheckResourceAttr(rName, "conditions.0.field", "url"),
resource.TestCheckResourceAttr(rName, "conditions.0.logic", "not_contain_all"),
resource.TestCheckResourceAttrPair(rName, "conditions.0.reference_table_id",
"huaweicloud_waf_reference_table.ref_table", "id"),
"huaweicloud_waf_reference_table.test", "id"),
resource.TestCheckResourceAttrSet(rName, "status"),
),
},
Expand Down Expand Up @@ -292,12 +293,34 @@ resource "huaweicloud_waf_rule_anti_crawler" "test" {
`, testAccWafPolicyV1_basic(name), name, name)
}

func testRuleAntiCrawler_excepProtectionMode(name string) string {
func testRuleAntiCrawler_base(name string) string {
return fmt.Sprintf(`
%s
%[1]s
resource "huaweicloud_waf_dedicated_instance" "test" {
name = "%[2]s"
available_zone = data.huaweicloud_availability_zones.test.names[1]
specification_code = "waf.instance.professional"
ecs_flavor = data.huaweicloud_compute_flavors.test.ids[0]
vpc_id = huaweicloud_vpc.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
security_group = [
huaweicloud_networking_secgroup.test.id
]
}
resource "huaweicloud_waf_reference_table" "ref_table" {
name = "%s"
resource "huaweicloud_waf_policy" "test" {
name = "%[2]s"
level = 1
depends_on = [
huaweicloud_waf_dedicated_instance.test
]
}
resource "huaweicloud_waf_reference_table" "test" {
name = "%[2]s"
type = "url"
description = "test url"
Expand All @@ -306,33 +329,39 @@ resource "huaweicloud_waf_reference_table" "ref_table" {
]
depends_on = [
huaweicloud_waf_dedicated_instance.instance_1
huaweicloud_waf_dedicated_instance.test
]
}
`, common.TestBaseComputeResources(name), name)
}

func testRuleAntiCrawler_excepProtectionMode(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_waf_rule_anti_crawler" "test" {
policy_id = huaweicloud_waf_policy.policy_1.id
name = "%s"
policy_id = huaweicloud_waf_policy.test.id
name = "%[2]s"
protection_mode = "anticrawler_except_url"
priority = 500
description = "test description"
conditions {
field = "url"
logic = "not_contain_all"
reference_table_id = huaweicloud_waf_reference_table.ref_table.id
reference_table_id = huaweicloud_waf_reference_table.test.id
}
}
`, testAccWafPolicyV1_basic(name), name, name)
`, testRuleAntiCrawler_base(name), name)
}

func testRuleAntiCrawler_excepProtectionMode_update(name string) string {
return fmt.Sprintf(`
%s
%[1]s
resource "huaweicloud_waf_rule_anti_crawler" "test" {
policy_id = huaweicloud_waf_policy.policy_1.id
name = "%s_update"
policy_id = huaweicloud_waf_policy.test.id
name = "%[2]s_update"
protection_mode = "anticrawler_except_url"
priority = 1000
description = "test description update"
Expand All @@ -343,7 +372,7 @@ resource "huaweicloud_waf_rule_anti_crawler" "test" {
content = "TR"
}
}
`, testAccWafPolicyV1_basic(name), name)
`, testRuleAntiCrawler_base(name), name)
}

func testRuleAntiCrawler_withEpsID(name string) string {
Expand Down

0 comments on commit b8cac8e

Please sign in to comment.