Skip to content

Commit 2f899c1

Browse files
authored
Merge pull request #5927 from cloudflare/vaishak/one-more-bot-test
Chore: extra bot test and assertion fix
2 parents 68454d3 + 1e2d64d commit 2f899c1

File tree

3 files changed

+94
-30
lines changed

3 files changed

+94
-30
lines changed

internal/services/bot_management/resource_test.go

Lines changed: 84 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestAccCloudflareBotManagement_SBFM(t *testing.T) {
5858

5959
func TestAccCloudflareBotManagement_Unentitled(t *testing.T) {
6060
t.Skip("Test expects entitlement error but test zone entitlements allow the configuration")
61-
61+
6262
rnd := utils.GenerateRandomResourceName()
6363
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
6464

@@ -108,7 +108,7 @@ func TestAccCloudflareBotManagement_EnableJS(t *testing.T) {
108108
ImportStateVerify: true,
109109
ImportStateVerifyIgnore: []string{
110110
"ai_bots_protection",
111-
"crawler_protection",
111+
"crawler_protection",
112112
"stale_zone_configuration",
113113
},
114114
},
@@ -144,7 +144,7 @@ func TestAccCloudflareBotManagement_SuppressSessionScore(t *testing.T) {
144144
ImportStateVerify: true,
145145
ImportStateVerifyIgnore: []string{
146146
"ai_bots_protection",
147-
"crawler_protection",
147+
"crawler_protection",
148148
"stale_zone_configuration",
149149
},
150150
},
@@ -200,29 +200,6 @@ func TestAccCloudflareBotManagement_AIBotsProtection(t *testing.T) {
200200
})
201201
}
202202

203-
func testCloudflareBotManagementSBFM(resourceName, rnd string, bm cloudflare.BotManagement) string {
204-
return acctest.LoadTestCase("cloudflarebotmanagementsbfm.tf", resourceName, rnd,
205-
*bm.EnableJS, *bm.SBFMDefinitelyAutomated,
206-
*bm.SBFMLikelyAutomated, *bm.SBFMVerifiedBots,
207-
*bm.SBFMStaticResourceProtection, *bm.OptimizeWordpress)
208-
}
209-
210-
func testCloudflareBotManagementEntSubscription(resourceName, zoneID string, bm cloudflare.BotManagement) string {
211-
return acctest.LoadTestCase("cloudflarebotmanagemententsubscription.tf", resourceName, zoneID, *bm.EnableJS, *bm.SuppressSessionScore, false)
212-
}
213-
214-
func testCloudflareBotManagementEnableJS(resourceName, zoneID string, enableJS bool) string {
215-
return acctest.LoadTestCase("cloudflarebotmanagementenablejs.tf", resourceName, zoneID, enableJS)
216-
}
217-
218-
func testCloudflareBotManagementSuppressSessionScore(resourceName, zoneID string, suppressSessionScore bool) string {
219-
return acctest.LoadTestCase("cloudflarebotmanagementsuppresssessionscore.tf", resourceName, zoneID, suppressSessionScore)
220-
}
221-
222-
func testCloudflareBotManagementAutoUpdateModel(resourceName, zoneID string, autoUpdateModel bool) string {
223-
return acctest.LoadTestCase("cloudflarebotmanagementautoupdatemodel.tf", resourceName, zoneID, autoUpdateModel)
224-
}
225-
226203
func TestAccCloudflareBotManagement_StateConsistency(t *testing.T) {
227204
rnd := utils.GenerateRandomResourceName()
228205
resourceName := "cloudflare_bot_management." + rnd
@@ -260,7 +237,7 @@ func TestAccCloudflareBotManagement_StateConsistency(t *testing.T) {
260237
ImportStateVerify: true,
261238
ImportStateVerifyIgnore: []string{
262239
"ai_bots_protection",
263-
"crawler_protection",
240+
"crawler_protection",
264241
"stale_zone_configuration",
265242
},
266243
},
@@ -601,6 +578,59 @@ func TestAccCloudflareBotManagement_ComputedFields(t *testing.T) {
601578
})
602579
}
603580

581+
func TestAccCloudflareBotManagement_EnableJSAutoUpdateSuppression(t *testing.T) {
582+
rnd := utils.GenerateRandomResourceName()
583+
resourceName := "cloudflare_bot_management." + rnd
584+
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
585+
586+
resource.Test(t, resource.TestCase{
587+
PreCheck: func() { acctest.TestAccPreCheck(t) },
588+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
589+
Steps: []resource.TestStep{
590+
{
591+
Config: testCloudflareBotManagementEnableJSAutoUpdateSupression(rnd, zoneID),
592+
ConfigStateChecks: []statecheck.StateCheck{
593+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(consts.ZoneIDSchemaKey), knownvalue.StringExact(zoneID)),
594+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("enable_js"), knownvalue.Bool(false)),
595+
},
596+
ConfigPlanChecks: resource.ConfigPlanChecks{
597+
PreApply: []plancheck.PlanCheck{
598+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
599+
plancheck.ExpectKnownValue(
600+
resourceName,
601+
tfjsonpath.New("enable_js"),
602+
knownvalue.Bool(false),
603+
),
604+
plancheck.ExpectKnownValue(
605+
resourceName,
606+
tfjsonpath.New("auto_update_model"),
607+
knownvalue.Bool(true),
608+
),
609+
plancheck.ExpectKnownValue(
610+
resourceName,
611+
tfjsonpath.New("suppress_session_score"),
612+
knownvalue.Bool(false),
613+
),
614+
},
615+
PostApplyPostRefresh: []plancheck.PlanCheck{
616+
plancheck.ExpectEmptyPlan(),
617+
},
618+
},
619+
},
620+
{
621+
ResourceName: resourceName,
622+
ImportState: true,
623+
ImportStateVerify: true,
624+
ImportStateVerifyIgnore: []string{
625+
"ai_bots_protection",
626+
"crawler_protection",
627+
"stale_zone_configuration",
628+
},
629+
},
630+
},
631+
})
632+
}
633+
604634
func testCloudflareBotManagementAIBotsProtection(resourceName, zoneID string, aiBotsProtection string) string {
605635
return acctest.LoadTestCase("cloudflarebotmanagementaibotsprotection.tf", resourceName, zoneID, aiBotsProtection)
606636
}
@@ -664,3 +694,30 @@ func testCloudflareBotManagementIssue5519NullFields(resourceName, zoneID string)
664694
func testCloudflareBotManagementIssue5519Reproduce(resourceName, zoneID string) string {
665695
return acctest.LoadTestCase("cloudflarebotmanagementissue5519reproduce.tf", resourceName, zoneID)
666696
}
697+
698+
func testCloudflareBotManagementSBFM(resourceName, rnd string, bm cloudflare.BotManagement) string {
699+
return acctest.LoadTestCase("cloudflarebotmanagementsbfm.tf", resourceName, rnd,
700+
*bm.EnableJS, *bm.SBFMDefinitelyAutomated,
701+
*bm.SBFMLikelyAutomated, *bm.SBFMVerifiedBots,
702+
*bm.SBFMStaticResourceProtection, *bm.OptimizeWordpress)
703+
}
704+
705+
func testCloudflareBotManagementEntSubscription(resourceName, zoneID string, bm cloudflare.BotManagement) string {
706+
return acctest.LoadTestCase("cloudflarebotmanagemententsubscription.tf", resourceName, zoneID, *bm.EnableJS, *bm.SuppressSessionScore, false)
707+
}
708+
709+
func testCloudflareBotManagementEnableJS(resourceName, zoneID string, enableJS bool) string {
710+
return acctest.LoadTestCase("cloudflarebotmanagementenablejs.tf", resourceName, zoneID, enableJS)
711+
}
712+
713+
func testCloudflareBotManagementSuppressSessionScore(resourceName, zoneID string, suppressSessionScore bool) string {
714+
return acctest.LoadTestCase("cloudflarebotmanagementsuppresssessionscore.tf", resourceName, zoneID, suppressSessionScore)
715+
}
716+
717+
func testCloudflareBotManagementAutoUpdateModel(resourceName, zoneID string, autoUpdateModel bool) string {
718+
return acctest.LoadTestCase("cloudflarebotmanagementautoupdatemodel.tf", resourceName, zoneID, autoUpdateModel)
719+
}
720+
721+
func testCloudflareBotManagementEnableJSAutoUpdateSupression(resourceName, zoneID string) string {
722+
return acctest.LoadTestCase("cloudflarebotmanagementenablejsautoupdatesupression.tf", resourceName, zoneID)
723+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "cloudflare_bot_management" "%[1]s" {
2+
zone_id = "%[2]s"
3+
auto_update_model = true
4+
enable_js = false
5+
suppress_session_score = false
6+
}

internal/services/url_normalization_settings/resource_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package url_normalization_settings_test
33
import (
44
"context"
55
"fmt"
6-
"github.com/cloudflare/cloudflare-go/v5/url_normalization"
7-
"github.com/hashicorp/terraform-plugin-log/tflog"
86
"log"
97
"os"
108
"regexp"
119
"testing"
1210

11+
"github.com/cloudflare/cloudflare-go/v5/url_normalization"
12+
"github.com/hashicorp/terraform-plugin-log/tflog"
13+
1314
cloudflare "github.com/cloudflare/cloudflare-go/v5"
1415
"github.com/cloudflare/terraform-provider-cloudflare/internal/acctest"
1516
"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
@@ -191,7 +192,7 @@ func TestAccCloudflareURLNormalizationSettings_InvalidValues(t *testing.T) {
191192
},
192193
{
193194
Config: testAccCheckCloudflareURLNormalizationSettingsConfig(zoneID, "cloudflare", "invalid_scope", rnd),
194-
ExpectError: regexp.MustCompile(`value must be one of: \["none" "incoming" "both"\]`),
195+
ExpectError: regexp.MustCompile(`value must be one of: \["incoming"|"none"|"both"\]`),
195196
},
196197
},
197198
})

0 commit comments

Comments
 (0)